{"record":{"id":"a5aa8ba4f63098a9","repo":"microsoft/aspire","slug":"mcp-endpoint-for-resource-resourcename-is-not-available","errorCode":null,"errorMessage":"MCP endpoint for resource '{resourceName}' is not available.","messagePattern":"MCP endpoint for resource '(.+?)' is not available\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/Backchannel/AuxiliaryBackchannelRpcTarget.cs","lineNumber":1803,"sourceCode":"\n        var resource = appModel.Resources\n            .OfType<IResourceWithEndpoints>()\n            .FirstOrDefault(r => string.Equals(r.Name, resourceName, StringComparisons.ResourceName));\n\n        if (resource is null)\n        {\n            throw new InvalidOperationException($\"Resource '{resourceName}' not found.\");\n        }\n\n        if (!resource.TryGetLastAnnotation<McpServerEndpointAnnotation>(out var annotation))\n        {\n            throw new InvalidOperationException($\"Resource '{resourceName}' does not have an MCP endpoint annotation.\");\n        }\n\n        var endpointUri = await annotation.EndpointUrlResolver(resource, cancellationToken).ConfigureAwait(false);\n        if (endpointUri is null)\n        {\n            throw new InvalidOperationException($\"MCP endpoint for resource '{resourceName}' is not available.\");\n        }\n\n        var transport = CreateHttpClientTransport(endpointUri);\n\n        McpClient? mcpClient = null;\n        try\n        {\n            mcpClient = await McpClient.CreateAsync(transport, cancellationToken: cancellationToken).ConfigureAwait(false)\n                ?? throw new InvalidOperationException(\"Failed to create MCP client.\");\n\n            if (logger.IsEnabled(LogLevel.Debug))\n            {\n                logger.LogDebug(\"Invoking tool {Name} with arguments {Arguments}\", toolName, JsonSerializer.Serialize(arguments));\n            }\n\n            var result = await mcpClient.CallToolAsync(toolName, arguments, cancellationToken: cancellationToken).ConfigureAwait(false);\n\n            if (logger.IsEnabled(LogLevel.Debug))","sourceCodeStart":1785,"sourceCodeEnd":1821,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/Backchannel/AuxiliaryBackchannelRpcTarget.cs#L1785-L1821","documentation":"This error is thrown by the auxiliary backchannel RPC target when resolving an MCP endpoint annotation for a resource succeeded, but the annotation's EndpointUrlResolver returned null. It means the resource declares an MCP endpoint, but no concrete URL could be resolved at the time of the call (e.g. the endpoint is not running or not yet allocated).","triggerScenarios":"Calling the backchannel RPC method that invokes an MCP tool when the resource's MCP endpoint annotation exists but EndpointUrlResolver returns null — typically because the resource is not running, the endpoint has no allocated URL yet, or the resolver is misconfigured.","commonSituations":"Invoking an MCP tool against a resource that is stopped or still starting; calling before the endpoint URL has been assigned; a custom EndpointUrlResolver that fails to produce a value.","solutions":["Verify the resource is running and has reached a state where its MCP endpoint URL is allocated before invoking tools.","Check that the EndpointUrlResolver on the McpEndpointAnnotation returns the correct URL and does not silently return null.","Wait for the resource's endpoint/event indicating it is listening, then retry the tool invocation.","Inspect the resource in the dashboard to confirm the MCP endpoint is present and healthy."],"exampleFix":"// before: call immediately after adding resource\nawait rpcTarget.InvokeMcpToolAsync(\"myresource\", \"mytool\", args);\n// after: wait for the resource to be running and endpoint resolved\nawait app.ResourceNotifications.WaitForResourceHealthyAsync(\"myresource\");\nawait rpcTarget.InvokeMcpToolAsync(\"myresource\", \"mytool\", args);","handlingStrategy":"validation","validationCode":"// Before invoking, ensure the resource is running and its MCP endpoint resolves\nvar annotation = resource.Annotations.OfType<McpEndpointAnnotation>().SingleOrDefault();\nif (annotation is null) throw new InvalidOperationException(\"Resource has no MCP endpoint annotation.\");\nvar url = await annotation.EndpointUrlResolver(resource, ct);\nif (url is null) throw new InvalidOperationException(\"MCP endpoint URL not yet available; wait for the resource to start.\");","typeGuard":"bool CanInvokeMcpTool(IResource resource) =>\n    resource.Annotations.OfType<McpEndpointAnnotation>().Any();","tryCatchPattern":null,"preventionTips":["Wait for the resource to be healthy/running before invoking MCP tools.","Verify the endpoint URL is allocated in the dashboard before tool calls.","Review any custom EndpointUrlResolver for paths that return null."],"tags":["mcp","endpoint","backchannel","aspire"],"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"}