Skip to content
DocsTry Aspire
DocsTry

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".
endpointNamestring?optionalAn optional name of the endpoint that hosts the MCP server. If not specified, defaults to the first HTTPS or HTTP endpoint.
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.

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.AddProject<Projects.MyApi>("api") .WithMcpServer("/sse", endpointName: "https");

var api = builder.AddProject<Projects.MyApi>("api")
.WithMcpServer();