TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/modelcontextprotocol/csharp-sdk/llms.txt
Use this file to discover all available pages before exploring further.
MapMcp() extension method sets up HTTP endpoints for handling MCP Streamable HTTP transport in ASP.NET Core applications.
MapMcp
Maps MCP protocol endpoints to the application’s request pipeline.Parameters
The endpoint route builder (typically your
WebApplication instance).The route pattern prefix to map MCP endpoints to. Supports ASP.NET Core route templates.Examples:
""- Maps to root path"/mcp"- Maps to/mcp"/{category}"- Maps with route parameter"/api/v1/mcp"- Maps to nested path
Returns
IEndpointConventionBuilder
A builder for configuring endpoint conventions like authorization policies, CORS, rate limiting, and other middleware.
Endpoints Created
The method creates the following endpoints:Streamable HTTP Transport (2025-11-25 spec)
Handles MCP client requests. Accepts JSON-RPC messages and may respond with:
200 OKwithtext/event-streamfor streaming responses202 Acceptedfor requests with no immediate response404 Not Foundif session ID is invalid
MCP-Protocol-Version(required) - Protocol version (e.g., “2025-11-25”)Mcp-Session-Id(optional) - Session identifier for stateful modeLast-Event-ID(optional) - For resuming interrupted streams
application/jsonAccept: Must include both application/json and text/event-streamOpens a persistent SSE stream for receiving server-to-client messages and requests.Not available in stateless mode.Headers:
Mcp-Session-Id(required) - Session identifierLast-Event-ID(optional) - For resuming from a specific event
200 OK with text/event-streamExplicitly terminates an MCP session and cleans up resources.Not available in stateless mode.Headers:
Mcp-Session-Id(required) - Session identifier to delete
Legacy HTTP with SSE Transport (2024-11-05 spec)
Legacy SSE endpoint for backward compatibility.Not available in stateless mode.Response:
200 OK with text/event-streamLegacy message endpoint for backward compatibility.Not available in stateless mode.Content-Type:
application/jsonResponse: 202 AcceptedBasic Usage
Authorization
Apply authorization policies to MCP endpoints using the returnedIEndpointConventionBuilder.
Tool-Level Authorization
For granular authorization on individual tools, prompts, or resources:CORS Configuration
Enable CORS for cross-origin MCP clients:Rate Limiting
Protect MCP endpoints with rate limiting:Per-Session Configuration
Combine route parameters with session configuration:Multiple MCP Endpoints
Host multiple MCP servers with different configurations:Metadata and OpenAPI
Enrich endpoints with metadata for OpenAPI documentation:Error Handling
The endpoints automatically handle errors and return JSON-RPC error responses:- 400 Bad Request - Invalid protocol version or malformed JSON-RPC
- 404 Not Found - Session not found or expired
- 406 Not Acceptable - Missing required Accept headers
Prerequisites
MapMcp() requires that WithHttpTransport() has been called during service registration. Calling MapMcp() without proper service configuration will throw an InvalidOperationException.Protocol Specifications
The endpoints implement:- Streamable HTTP Transport (2025-11-25)
- HTTP with SSE Transport (2024-11-05 - legacy)
- 2024-11-05
- 2025-03-26
- 2025-06-18
- 2025-11-25