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.
HttpServerTransportOptions class configures the Streamable HTTP transport implementation for Model Context Protocol servers in ASP.NET Core.
HttpServerTransportOptions
Configure HTTP transport behavior when callingWithHttpTransport().
Properties
Optional callback to configure per-session
McpServerOptions with access to the HttpContext of the request that initiated the session.Use this to customize server options based on the incoming request, such as filtering tools by route parameters or user claims.Optional callback for running new MCP sessions manually.Useful for running logic before a session starts and after it completes.
This is an experimental API. The
HttpContext parameter comes from the request that initiated the session and may not be usable after McpServer.RunAsync() starts. Consider using ConfigureSessionOptions instead.Indicates whether the server runs in stateless mode without tracking state between requests, allowing for load balancing without session affinity.When
true:McpSession.SessionIdwill be null- “MCP-Session-Id” header is not used
RunSessionHandleris called once per request- “/sse” endpoint is disabled
- Unsolicited server-to-client messages are unsupported
- Server-to-client requests are unsupported
- Client sampling, elicitation, and roots capabilities are disabled
Event store for resumability support. When set, events are stored and can be replayed when clients reconnect with a Last-Event-ID header.The server will:
- Generate unique event IDs for each SSE message
- Store events for later replay
- Replay missed events when a client reconnects with a Last-Event-ID header
- Send priming events to establish resumability before actual messages
Session migration handler for cross-instance session migration.When configured, the server supports session migration between instances. If a request arrives with a session ID not found locally, the handler is consulted to determine if the session can be migrated from another instance.Can be set directly or resolved from DI.
Indicates whether the server uses a single execution context for the entire session.When
false, handlers get called with the ExecutionContext belonging to the corresponding HTTP request.When true, handlers get called with the same ExecutionContext used for ConfigureSessionOptions and RunSessionHandler. Useful for setting AsyncLocal<T> variables that persist for the entire session, but prevents using IHttpContextAccessor in handlers.Duration the server waits between any active requests before timing out an MCP session.Checked in the background every 5 seconds. Clients trying to resume a timed-out session receive a 404 status code and should restart. Clients can keep sessions open by maintaining a GET request.
Maximum number of idle sessions to track in memory.When exceeded, the server logs a critical error and terminates the oldest idle sessions until the count is below this limit. Active sessions with open GET requests don’t count towards this limit.
Time provider used for testing the
IdleTimeout. Primarily for testing scenarios.WithHttpTransport
Extension method to add HTTP transport services to an MCP server.Parameters
The MCP server builder instance.
Optional callback to configure HTTP transport options.
Returns
IMcpServerBuilder
The builder instance for method chaining.
Example
WithDistributedCacheEventStreamStore
Registers aDistributedCacheEventStreamStore as the ISseEventStreamStore for SSE resumability.
An
IDistributedCache implementation must be registered in the service collection before calling this method.Parameters
The MCP server builder instance.
Optional callback to configure event stream store options.
DistributedCacheEventStreamStoreOptions
The distributed cache instance to use for event storage. Automatically populated from DI if not set.
Sliding expiration for individual events. Events are refreshed on each access.
Absolute expiration for individual events. Events are evicted after this period regardless of access.
Sliding expiration for stream metadata (mode and completion status).
Absolute expiration for stream metadata.
Interval between polling attempts when a stream reader is waiting for new events. Shorter intervals provide lower latency but increase cache access frequency.