{"record":{"id":"f630279a7344d5bc","repo":"microsoft/aspire","slug":"could-not-create-mcp-server-for-resource-resource-name-as-no","errorCode":null,"errorMessage":"Could not create MCP server for resource '{resource.Name}' as no endpoint was found with name '{endpointName}'.","messagePattern":"Could not create MCP server for resource '(.+?)' as no endpoint was found with name '(.+?)'\\.","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/McpServerResourceBuilderExtensions.cs","lineNumber":62,"sourceCode":"        this IResourceBuilder<T> builder,\n        string? path = \"/mcp\",\n        [EndpointName] string? endpointName = null)\n        where T : IResourceWithEndpoints\n    {\n        ArgumentNullException.ThrowIfNull(builder);\n\n        return builder.WithAnnotation(new McpServerEndpointAnnotation(async (resource, cancellationToken) =>\n        {\n            var endpoints = resource.GetEndpoints();\n            EndpointReference? endpoint = null;\n\n            if (endpointName is not null)\n            {\n                endpoint = endpoints.FirstOrDefault(e => string.Equals(e.EndpointName, endpointName, StringComparisons.EndpointAnnotationName));\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 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)}\");","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/McpServerResourceBuilderExtensions.cs#L44-L80","documentation":"WithMcpServer resolves the endpoint that will host the MCP server at annotation-evaluation time. When an explicit endpointName was supplied and no endpoint on the resource matches that name (case-insensitive per EndpointAnnotationName comparison), it throws DistributedApplicationException. This fails fast because the MCP server cannot be exposed without a valid endpoint reference.","triggerScenarios":"Calling builder.AddProject(...).WithMcpServer(endpointName: \"someEndpoint\") where the project/container resource has no WithEndpoint/WithHttpEndpoint/WithHttpsEndpoint declaring an endpoint literally named 'someEndpoint' (note: the name compared is the endpoint name, not the URL scheme unless they coincide).","commonSituations":"Typo in the endpoint name; assuming the callback receives a scheme like 'https' when the endpoint was created with a custom name; endpoint declared on a different resource; renaming an endpoint without updating WithMcpServer callers.","solutions":["Declare a matching endpoint on the resource, e.g. .WithHttpEndpoint(name: \"<endpointName>\") or pass the name of an existing endpoint.","Omit endpointName to let WithMcpServer pick the first 'https' or 'http' endpoint automatically.","List the resource's endpoints (WithEndpoint/WithHttpEndpoint calls) and align the endpointName spelling exactly."],"exampleFix":"// before\nvar api = builder.AddProject<Projects.MyApi>(\"api\")\n    .WithMcpServer(endpointName: \"apiv2\"); // no such endpoint\n\n// after\nvar api = builder.AddProject<Projects.MyApi>(\"api\")\n    .WithHttpEndpoint(name: \"apiv2\")\n    .WithMcpServer(endpointName: \"apiv2\");","handlingStrategy":"validation","validationCode":"// Ensure the named endpoint exists before WithMcpServer resolves its annotation callback.\n// Endpoint names come from WithEndpoint/WithHttpEndpoint(name: ...) declarations.\nvar endpointNames = new[] { \"https\", \"http\", \"apiv2\" }; // names you declared\nif (!endpointNames.Contains(endpointName, StringComparer.OrdinalIgnoreCase))\n{\n    throw new ArgumentException($\"Endpoint '{endpointName}' is not declared on the resource.\");\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    builder.WithMcpServer(endpointName: \"apiv2\");\n}\ncatch (DistributedApplicationException ex) when (ex.Message.Contains(\"no endpoint was found with name\"))\n{\n    logger.LogError(ex, \"Declare the endpoint via WithHttpEndpoint(name:) before referencing it.\");\n    throw;\n}","preventionTips":["Keep endpoint names in constants shared between WithEndpoint and WithMcpServer calls.","Omit endpointName when an https/http endpoint already exists.","Check endpoint declarations on the resource whenever renaming endpoints.","Remember the match is on the endpoint NAME, not the URL scheme, unless they coincide."],"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"}