MCP TypeScript SDK
    Preparing search index...

    Server transport for Streamable HTTP: this implements the MCP Streamable HTTP transport specification. It supports both SSE streaming and direct HTTP responses.

    This is a wrapper around WebStandardStreamableHTTPServerTransport that provides Node.js HTTP compatibility. It uses the @hono/node-server library to convert between Node.js HTTP and Web Standard APIs.

    Usage example:

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

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

    // Using with pre-parsed request body
    app.post('/mcp', (req, res) => {
    transport.handleRequest(req, res, req.body);
    });

    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

    Accessors

    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

    • Handles an incoming HTTP request, whether GET or POST.

      This method converts Node.js HTTP objects to Web Standard Request/Response and delegates to the underlying WebStandardStreamableHTTPServerTransport.

      Parameters

      • req: IncomingMessage & { auth?: AuthInfo }

        Node.js IncomingMessage, optionally with auth property from middleware

      • res: ServerResponse

        Node.js ServerResponse

      • OptionalparsedBody: unknown

        Optional pre-parsed body from body-parser middleware

      Returns Promise<void>