microsoft/aspire · error · DistributedApplicationException

Could not create MCP server for resource

Error message

Could not create MCP server for resource '{resource.Name}' as no endpoint was found matching one of the specified names: {string.Join(", ", s_httpSchemes)}

What it means

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.

Solutions

  1. Add a default-scheme endpoint: .WithHttpEndpoint() (creates the 'http' endpoint) or .WithHttpsEndpoint() for 'https'.
  2. Pass an explicit endpointName matching an existing custom endpoint: .WithMcpServer(endpointName: "internal").
  3. Rename the existing custom endpoint to 'http' or 'https' if it should serve MCP traffic.

Example fix

// before
var svc = builder.AddContainer("svc", "img").WithEndpoint(name: "internal").WithMcpServer();

// after
var svc = builder.AddContainer("svc", "img")
    .WithEndpoint(name: "internal")
    .WithHttpEndpoint(name: "http")
    .WithMcpServer(endpointName: "http");
Defensive patterns

Strategy: validation

Validate before calling

// Verify the resource declares an endpoint named 'https' or 'http' before relying on the default WithMcpServer endpoint selection.
bool hasDefaultSchemeEndpoint = /* declared endpoints */ new[] { "http", "https" }.Any(scheme => declaredEndpointNames.Contains(scheme, StringComparer.OrdinalIgnoreCase));
if (!hasDefaultSchemeEndpoint)
{
    throw new InvalidOperationException("Resource must declare an http/https endpoint or pass an explicit endpointName to WithMcpServer.");
}

Try / catch

try
{
    builder.WithMcpServer();
}
catch (DistributedApplicationException ex) when (ex.Message.Contains("matching one of the specified names"))
{
    logger.LogError(ex, "Add .WithHttpEndpoint() or specify endpointName for WithMcpServer.");
    throw;
}

Prevention

When it happens

Trigger: 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'.

Common situations: 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.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/569fe1140dcc6cff. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting/McpServerResourceBuilderExtensions.cs:79

                {
                    throw new DistributedApplicationException(
                        $"Could not create MCP server for resource '{resource.Name}' as no endpoint was found with name '{endpointName}'.");
                }
            }
            else
            {
                foreach (var scheme in s_httpSchemes)
                {
                    endpoint = endpoints.FirstOrDefault(e => string.Equals(e.EndpointName, scheme, StringComparisons.EndpointAnnotationName));
                    if (endpoint is not null)
                    {
                        break;
                    }
                }

                if (endpoint is null)
                {
                    throw new DistributedApplicationException(
                        $"Could not create MCP server for resource '{resource.Name}' as no endpoint was found matching one of the specified names: {string.Join(", ", s_httpSchemes)}");
                }
            }

            if (!endpoint.Exists)
            {
                return null;
            }

            var baseUrl = await endpoint.GetValueAsync(cancellationToken).ConfigureAwait(false);
            if (string.IsNullOrEmpty(baseUrl))
            {
                return null;
            }

            if (string.IsNullOrEmpty(path))
            {
                return new Uri(baseUrl, UriKind.Absolute);

View on GitHub (pinned to 25830f84bd)