MCP TypeScript SDK
    Preparing search index...

    Server transport for Web Standards Streamable HTTP: this implements the MCP Streamable HTTP transport specification using Web Standard APIs (Request, Response, ReadableStream).

    This transport works on any runtime that supports Web Standards: Node.js 18+, Cloudflare Workers, Deno, Bun, etc.

    Usage example:

    // Stateful mode - server sets the session ID
    const statefulTransport = new WebStandardStreamableHTTPServerTransport({
    sessionIdGenerator: () => crypto.randomUUID(),
    });

    // Stateless mode - explicitly set session ID to undefined
    const statelessTransport = new WebStandardStreamableHTTPServerTransport({
    sessionIdGenerator: undefined,
    });

    // Hono.js usage
    app.all('/mcp', async (c) => {
    return transport.handleRequest(c.req.raw);
    });

    // Cloudflare Workers usage
    export default {
    async fetch(request: Request): Promise<Response> {
    return transport.handleRequest(request);
    }
    };

    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

    Implements

    Index

    Constructors

    Properties

    onclose?: () => void

    Callback for when the connection is closed for any reason.

    This should be invoked when close() is called as well.

    onerror?: (error: Error) => void

    Callback for when an error occurs.

    Note that errors are not necessarily fatal; they are used for reporting any kind of exceptional condition out of band.

    onmessage?: (message: JSONRPCMessage, extra?: MessageExtraInfo) => void

    Callback for when a message (request or response) is received over the connection.

    Includes the requestInfo and authInfo if the transport is authenticated.

    The requestInfo can be used to get the original request information (headers, etc.)

    sessionId?: string

    The session ID generated for this connection.

    Methods