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 10309a4d3..6b2ac4cd9 100644 --- a/src/CommunityToolkit.Aspire.Hosting.McpInspector/McpInspectorResource.cs +++ b/src/CommunityToolkit.Aspire.Hosting.McpInspector/McpInspectorResource.cs @@ -65,9 +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) || !endpoints.Any()) + { + 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.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..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") @@ -448,8 +447,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")