MCP TypeScript SDK (V2)
    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.

    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
    const server = new McpServer({ name: 'my-server', version: '1.0.0' });

    const transport = new WebStandardStreamableHTTPServerTransport({
    sessionIdGenerator: () => crypto.randomUUID()
    });

    await server.connect(transport);
    const transport = new WebStandardStreamableHTTPServerTransport({
    sessionIdGenerator: undefined
    });
    app.all('/mcp', async c => {
    return transport.handleRequest(c.req.raw);
    });
    const worker = {
    async fetch(request: Request): Promise<Response> {
    return transport.handleRequest(request);
    }
    };

    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

    • Close an SSE stream for a specific request, triggering client reconnection. Use this to implement polling behavior during long-running operations - client will reconnect after the retry interval specified in the priming event.

      Parameters

      Returns void

    • Close the standalone GET SSE stream, triggering client reconnection. Use this to implement polling behavior for server-initiated notifications.

      Returns void