{"record":{"id":"569fe1140dcc6cff","repo":"microsoft/aspire","slug":"could-not-create-mcp-server-for-resource-resource-name-as-no-569fe1","errorCode":null,"errorMessage":"Could not create MCP server for resource '{resource.Name}' as no endpoint was found matching one of the specified names: {string.Join(\", \", s_httpSchemes)}","messagePattern":"Could not create MCP server for resource '(.+?)' as no endpoint was found matching one of the specified names: (.+?)","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/McpServerResourceBuilderExtensions.cs","lineNumber":79,"sourceCode":"                {\n                    throw new DistributedApplicationException(\n                        $\"Could not create MCP server for resource '{resource.Name}' as no endpoint was found with name '{endpointName}'.\");\n                }\n            }\n            else\n            {\n                foreach (var scheme in s_httpSchemes)\n                {\n                    endpoint = endpoints.FirstOrDefault(e => string.Equals(e.EndpointName, scheme, StringComparisons.EndpointAnnotationName));\n                    if (endpoint is not null)\n                    {\n                        break;\n                    }\n                }\n\n                if (endpoint is null)\n                {\n                    throw new DistributedApplicationException(\n                        $\"Could not create MCP server for resource '{resource.Name}' as no endpoint was found matching one of the specified names: {string.Join(\", \", s_httpSchemes)}\");\n                }\n            }\n\n            if (!endpoint.Exists)\n            {\n                return null;\n            }\n\n            var baseUrl = await endpoint.GetValueAsync(cancellationToken).ConfigureAwait(false);\n            if (string.IsNullOrEmpty(baseUrl))\n            {\n                return null;\n            }\n\n            if (string.IsNullOrEmpty(path))\n            {\n                return new Uri(baseUrl, UriKind.Absolute);","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/McpServerResourceBuilderExtensions.cs#L61-L97","documentation":"When WithMcpServer is called without an endpointName, it searches the resource's endpoints for one named 'https' or 'http' (the default schemes). If neither exists it throws DistributedApplicationException, because it cannot guess which endpoint should host the MCP server.","triggerScenarios":"Calling .WithMcpServer() (no endpointName) on a resource whose endpoints are all declared with custom names (e.g. name: \"internal\", name: \"metrics\") or that has no endpoints at all — the callback finds no endpoint named 'https' or 'http'.","commonSituations":"Projects exposing endpoints via Dockerfile/launchSettings only with custom names; containers configured with WithEndpoint(name: \"grpc\") style custom names; forgetting WithHttpEndpoint entirely on a worker-style resource.","solutions":["Add a default-scheme endpoint: .WithHttpEndpoint() (creates the 'http' endpoint) or .WithHttpsEndpoint() for 'https'.","Pass an explicit endpointName matching an existing custom endpoint: .WithMcpServer(endpointName: \"internal\").","Rename the existing custom endpoint to 'http' or 'https' if it should serve MCP traffic."],"exampleFix":"// before\nvar svc = builder.AddContainer(\"svc\", \"img\").WithEndpoint(name: \"internal\").WithMcpServer();\n\n// after\nvar svc = builder.AddContainer(\"svc\", \"img\")\n    .WithEndpoint(name: \"internal\")\n    .WithHttpEndpoint(name: \"http\")\n    .WithMcpServer(endpointName: \"http\");","handlingStrategy":"validation","validationCode":"// Verify the resource declares an endpoint named 'https' or 'http' before relying on the default WithMcpServer endpoint selection.\nbool hasDefaultSchemeEndpoint = /* declared endpoints */ new[] { \"http\", \"https\" }.Any(scheme => declaredEndpointNames.Contains(scheme, StringComparer.OrdinalIgnoreCase));\nif (!hasDefaultSchemeEndpoint)\n{\n    throw new InvalidOperationException(\"Resource must declare an http/https endpoint or pass an explicit endpointName to WithMcpServer.\");\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    builder.WithMcpServer();\n}\ncatch (DistributedApplicationException ex) when (ex.Message.Contains(\"matching one of the specified names\"))\n{\n    logger.LogError(ex, \"Add .WithHttpEndpoint() or specify endpointName for WithMcpServer.\");\n    throw;\n}","preventionTips":["Give every MCP-hosting resource a standard WithHttpEndpoint() (or WithHttpsEndpoint) so the default scheme lookup succeeds.","If using custom endpoint names, always pass endpointName explicitly.","Review resources whose endpoints come only from launchSettings or custom WithEndpoint calls."],"tags":["aspire","mcp","endpoint","configuration"],"backgroundTag":"resource-not-found","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}