From a1c2bc9511e64a62b2805172d5169e2136df26bb Mon Sep 17 00:00:00 2001 From: Aaron Powell Date: Mon, 1 Dec 2025 01:34:46 +0000 Subject: [PATCH 1/3] Fixing endpoint checking and allocation Fixes #1010 --- .../McpInspectorResource.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/CommunityToolkit.Aspire.Hosting.McpInspector/McpInspectorResource.cs b/src/CommunityToolkit.Aspire.Hosting.McpInspector/McpInspectorResource.cs index 10309a4d3..97b505b9d 100644 --- a/src/CommunityToolkit.Aspire.Hosting.McpInspector/McpInspectorResource.cs +++ b/src/CommunityToolkit.Aspire.Hosting.McpInspector/McpInspectorResource.cs @@ -65,9 +65,14 @@ internal void AddMcpServer(IResourceWithEndpoints mcpServer, bool isDefault, Mcp throw new InvalidOperationException($"The MCP server {mcpServer.Name} is already added to the MCP Inspector resource."); } + if (!mcpServer.TryGetEndpoints(out var endpoints)) + { + throw new InvalidOperationException($"The MCP server {mcpServer.Name} must have at least one endpoint defined."); + } + McpServerMetadata item = new( mcpServer.Name, - mcpServer.GetEndpoint("https") ?? mcpServer.GetEndpoint("http") ?? throw new InvalidOperationException($"The MCP server {mcpServer.Name} must have an 'https' or 'http' endpoint defined."), + mcpServer.GetEndpoint(endpoints.First().Name), transportType, path); From f861f67720710aa8dfc5c3cd912c402d12f84c33 Mon Sep 17 00:00:00 2001 From: Aaron Powell Date: Tue, 2 Dec 2025 04:42:34 +0000 Subject: [PATCH 2/3] better handling of endpoint names --- .../Properties/launchSettings.json | 9 +++++---- .../McpInspectorResource.cs | 7 +++++-- .../McpInspectorResourceBuilderExtensionsTests.cs | 3 +-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/examples/mcp-inspector/CommunityToolkit.Aspire.Hosting.McpInspector.McpServer/Properties/launchSettings.json b/examples/mcp-inspector/CommunityToolkit.Aspire.Hosting.McpInspector.McpServer/Properties/launchSettings.json index db8bb522b..5aa8af34c 100644 --- a/examples/mcp-inspector/CommunityToolkit.Aspire.Hosting.McpInspector.McpServer/Properties/launchSettings.json +++ b/examples/mcp-inspector/CommunityToolkit.Aspire.Hosting.McpInspector.McpServer/Properties/launchSettings.json @@ -1,23 +1,24 @@ { "$schema": "https://json.schemastore.org/launchsettings.json", "profiles": { - "http": { + "https": { "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, - "applicationUrl": "http://localhost:5230", + "applicationUrl": "https://localhost:7295;http://localhost:5230", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, - "https": { + "http": { "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, - "applicationUrl": "https://localhost:7295;http://localhost:5230", + "applicationUrl": "http://localhost:5230", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } } } } + diff --git a/src/CommunityToolkit.Aspire.Hosting.McpInspector/McpInspectorResource.cs b/src/CommunityToolkit.Aspire.Hosting.McpInspector/McpInspectorResource.cs index 97b505b9d..6b2ac4cd9 100644 --- a/src/CommunityToolkit.Aspire.Hosting.McpInspector/McpInspectorResource.cs +++ b/src/CommunityToolkit.Aspire.Hosting.McpInspector/McpInspectorResource.cs @@ -65,14 +65,17 @@ internal void AddMcpServer(IResourceWithEndpoints mcpServer, bool isDefault, Mcp throw new InvalidOperationException($"The MCP server {mcpServer.Name} is already added to the MCP Inspector resource."); } - if (!mcpServer.TryGetEndpoints(out var endpoints)) + if (!mcpServer.TryGetEndpoints(out var endpoints) || !endpoints.Any()) { throw new InvalidOperationException($"The MCP server {mcpServer.Name} must have at least one endpoint defined."); } McpServerMetadata item = new( mcpServer.Name, - mcpServer.GetEndpoint(endpoints.First().Name), + mcpServer.GetEndpoint( + endpoints.FirstOrDefault(e => e.Name == "https")?.Name + ?? endpoints.FirstOrDefault(e => e.Name == "http")?.Name + ?? endpoints.First().Name), transportType, path); diff --git a/tests/CommunityToolkit.Aspire.Hosting.McpInspector.Tests/McpInspectorResourceBuilderExtensionsTests.cs b/tests/CommunityToolkit.Aspire.Hosting.McpInspector.Tests/McpInspectorResourceBuilderExtensionsTests.cs index bc9f3599e..0b44d915a 100644 --- a/tests/CommunityToolkit.Aspire.Hosting.McpInspector.Tests/McpInspectorResourceBuilderExtensionsTests.cs +++ b/tests/CommunityToolkit.Aspire.Hosting.McpInspector.Tests/McpInspectorResourceBuilderExtensionsTests.cs @@ -448,8 +448,7 @@ public void WithMcpServerPrefersHttpsOverHttp() // Create a mock MCP server resource with both https and http endpoints // AddProject creates "http" by default, we add "https" with explicit name - var mockServer = appBuilder.AddProject("mcpServer") - .WithHttpsEndpoint(name: "https"); + var mockServer = appBuilder.AddProject("mcpServer"); // Act var inspector = appBuilder.AddMcpInspector("inspector") From f45a5a90f3cbdcd567284d6f82027810cb92733e Mon Sep 17 00:00:00 2001 From: Aaron Powell Date: Tue, 2 Dec 2025 23:39:40 +0000 Subject: [PATCH 3/3] Fixing last test --- .../McpInspectorResourceBuilderExtensionsTests.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/CommunityToolkit.Aspire.Hosting.McpInspector.Tests/McpInspectorResourceBuilderExtensionsTests.cs b/tests/CommunityToolkit.Aspire.Hosting.McpInspector.Tests/McpInspectorResourceBuilderExtensionsTests.cs index 0b44d915a..9af24df7e 100644 --- a/tests/CommunityToolkit.Aspire.Hosting.McpInspector.Tests/McpInspectorResourceBuilderExtensionsTests.cs +++ b/tests/CommunityToolkit.Aspire.Hosting.McpInspector.Tests/McpInspectorResourceBuilderExtensionsTests.cs @@ -415,8 +415,7 @@ public void WithMcpServerSupportsHttpsEndpoint() var appBuilder = DistributedApplication.CreateBuilder(); // Create a mock MCP server resource with https endpoint (uses name "https") - var mockServer = appBuilder.AddProject("mcpServer") - .WithHttpsEndpoint(name: "https"); + var mockServer = appBuilder.AddProject("mcpServer"); // Act var inspector = appBuilder.AddMcpInspector("inspector")