StreamableHttpServerTransport
Server transport for Streamable HTTP: this implements the MCP Streamable HTTP transport specification. It supports both SSE streaming and direct HTTP responses.
In stateful mode:
Session ID is generated and included in response headers
Session ID is always included in initialization responses
Requests with invalid session IDs are rejected with 404 Not Found
Non-initialization requests without a session ID are rejected with 400 Bad Request
State is maintained in-memory (connections, message history)
In stateless mode:
No Session ID is included in any responses
No session validation is performed
Parameters
Transport configuration. See Configuration for available options.
Constructors
Secondary constructor for StreamableHttpServerTransport that simplifies initialization by directly taking the configurable parameters without requiring a Configuration instance.
Types
Configuration options for StreamableHttpServerTransport.
Properties
Functions
Closes the SSE stream associated with the given requestId, prompting the client to reconnect. Useful for implementing polling behavior for long-running operations.
Handles an HTTP DELETE request by closing the session and the transport.
Handles an HTTP GET request by establishing a standalone SSE stream for server-initiated notifications.
Handles POST requests containing JSON-RPC messages
Handles an incoming HTTP request, whether GET, POST or DELETE
A callback for session close events This is called when the server closes a session due to a DELETE request. Useful in cases when you need to clean up resources associated with the session. Note that this is different from the transport closing, if you are handling HTTP requests from multiple nodes you might want to close each StreamableHTTPServerTransport after a request is completed while still keeping the session open/running.
A callback for session initialization events This is called when the server initializes a new session. Useful in cases when you need to register multiple mcp sessions and need to keep track of them.
Function that generates a session ID for the transport. The session ID SHOULD be globally unique and cryptographically secure (e.g., a securely generated UUID, a JWT, or a cryptographic hash)