Class McpEndpointRouteBuilderExtensions
- Namespace
- Microsoft.AspNetCore.Builder
- Assembly
- ModelContextProtocol.AspNetCore.dll
Provides extension methods for IEndpointRouteBuilder to add MCP endpoints.
public static class McpEndpointRouteBuilderExtensions
- Inheritance
-
McpEndpointRouteBuilderExtensions
- Inherited Members
Methods
MapMcp(IEndpointRouteBuilder, string)
Sets up endpoints for handling MCP Streamable HTTP transport.
public static IEndpointConventionBuilder MapMcp(this IEndpointRouteBuilder endpoints, string pattern = "")
Parameters
endpointsIEndpointRouteBuilderThe web application to attach MCP HTTP endpoints.
patternstringThe route pattern prefix to map to.
Returns
- IEndpointConventionBuilder
Returns a builder for configuring additional endpoint conventions like authorization policies.
Remarks
For details about the Streamable HTTP transport, see the 2025-11-25 protocol specification. This method also maps legacy SSE endpoints for backward compatibility at the path "/sse" and "/message". For details about the HTTP with SSE transport, see the 2024-11-05 protocol specification.
Exceptions
- InvalidOperationException
The required MCP services have not been registered. Ensure WithHttpTransport(IMcpServerBuilder, Action<HttpServerTransportOptions>?) has been called during application startup.