McpServerResourceBuilderExtensions Methods

ClassMethods1 member
Provides extension methods for configuring MCP (Model Context Protocol) server endpoints on resources.
WithMcpServer(IResourceBuilder<T>, string?, string?)Section titled WithMcpServer(IResourceBuilder<T>, string?, string?)extensionIResourceBuilder<T>
Marks the resource as hosting a Model Context Protocol (MCP) server on the specified endpoint.
public static class McpServerResourceBuilderExtensions
{
public static IResourceBuilder<T> WithMcpServer<T>(
this IResourceBuilder<T> builder,
string? path = "/mcp",
string? endpointName = null)
{
// ...
}
}
builderIResourceBuilder<T>The resource builder.
pathstring?optionalAn optional path to append to the endpoint URL when forming the MCP server address. Defaults to "/mcp". A leading slash is added if missing. A null or empty value uses the endpoint URL without an additional path.
endpointNamestring?optionalAn optional name of the endpoint that hosts the MCP server. If not specified, selects the endpoint named https, falling back to the endpoint named http. Names are matched case-insensitively; endpoints with other names must be selected explicitly, regardless of their URI scheme.
IResourceBuilder<T>A reference to the ApplicationModel.IResourceBuilder`1 for chaining additional configuration.
This method adds an McpServerEndpointAnnotation to the resource, enabling the Aspire tooling to discover and proxy the MCP server exposed by the resource. It does not create an endpoint, start an MCP server, or configure its transport or authentication. The resource must already expose an MCP server at the selected endpoint and path. Endpoint selection and URL resolution occur when tooling consumes the annotation, not when this method is called. A missing selected endpoint causes resolution to throw a DistributedApplicationException.

Mark a resource as hosting an MCP server using the default endpoint: Mark a resource as hosting an MCP server with a custom path and endpoint: var api = builder.AddDotnetProject("api", "../MyApi/MyApi.csproj") .WithMcpServer("/sse", endpointName: "https");

var api = builder.AddDotnetProject("api", "../MyApi/MyApi.csproj")
.WithMcpServer();