Class HttpServerTransportOptions
- Namespace
- ModelContextProtocol.AspNetCore
- Assembly
- ModelContextProtocol.AspNetCore.dll
Represents configuration options for McpEndpointRouteBuilderExtensions.MapMcp, which implements the Streaming HTTP transport for the Model Context Protocol. See the protocol specification for details on the Streamable HTTP transport. https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#streamable-http
public class HttpServerTransportOptions
- Inheritance
-
HttpServerTransportOptions
- Inherited Members
Remarks
For details on the Streamable HTTP transport, see the protocol specification.
Properties
ConfigureSessionOptions
Gets or sets an optional asynchronous callback to configure per-session McpServerOptions with access to the HttpContext of the request that initiated the session.
public Func<HttpContext, McpServerOptions, CancellationToken, Task>? ConfigureSessionOptions { get; set; }
Property Value
IdleTimeout
Gets or sets the duration of time the server will wait between any active requests before timing out an MCP session.
public TimeSpan IdleTimeout { get; set; }
Property Value
- TimeSpan
The amount of time the server waits between any active requests before timing out an MCP session. The default is 2 hours.
Remarks
This value is checked in the background every 5 seconds. A client trying to resume a session will receive a 404 status code and should restart their session. A client can keep their session open by keeping a GET request open.
MaxIdleSessionCount
Gets or sets maximum number of idle sessions to track in memory. This value is used to limit the number of sessions that can be idle at once.
public int MaxIdleSessionCount { get; set; }
Property Value
- int
The maximum number of idle sessions to track in memory. The default is 10,000 sessions.
Remarks
Past this limit, the server logs a critical error and terminates the oldest idle sessions, even if they have not reached their IdleTimeout, until the idle session count is below this limit. Clients that keep their session open by keeping a GET request open don't count towards this limit.
PerSessionExecutionContext
Gets or sets a value that indicates whether the server uses a single execution context for the entire session.
public bool PerSessionExecutionContext { get; set; }
Property Value
- bool
true if the server uses a single execution context for the entire session; otherwise, false. The default is false.
Remarks
If false, handlers like tools get called with the ExecutionContext belonging to the corresponding HTTP request, which can change throughout the MCP session. If true, handlers will get called with the same ExecutionContext used to call ConfigureSessionOptions and RunSessionHandler. Enabling a per-session ExecutionContext can be useful for setting AsyncLocal<T> variables that persist for the entire session, but it prevents you from using IHttpContextAccessor in handlers.
RunSessionHandler
Gets or sets an optional asynchronous callback for running new MCP sessions manually.
public Func<HttpContext, McpServer, CancellationToken, Task>? RunSessionHandler { get; set; }
Property Value
Remarks
This callback is useful for running logic before a sessions starts and after it completes.
Stateless
Gets or sets a value that indicates whether the server runs in a stateless mode that doesn't track state between requests, allowing for load balancing without session affinity.
public bool Stateless { get; set; }
Property Value
- bool
true if the server runs in a stateless mode; false if the server tracks state between requests. The default is false.
Remarks
If true, SessionId will be null, and the "MCP-Session-Id" header will not be used, the RunSessionHandler will be called once for for each request, and the "/sse" endpoint will be disabled. Unsolicited server-to-client messages and all server-to-client requests are also unsupported, because any responses might arrive at another ASP.NET Core application process. Client sampling, elicitation, and roots capabilities are also disabled in stateless mode, because the server cannot make requests.
TimeProvider
Gets or sets the time provider that's used for testing the IdleTimeout.
public TimeProvider TimeProvider { get; set; }