ailoy-web
    Preparing search index...

    Class MCPStreamableHTTPClientTransport

    Client transport for Streamable HTTP: this implements the MCP Streamable HTTP transport specification. It will connect to a server using HTTP POST for sending messages and HTTP GET with Server-Sent Events for receiving messages.

    Implements

    • Transport
    Index

    Constructors

    • Parameters

      • url: URL
      • Optionalopts: StreamableHTTPClientTransportOptions

      Returns MCPStreamableHTTPClientTransport

    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) => 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.)

    Accessors

    • get protocolVersion(): undefined | string

      Returns undefined | string

    • get sessionId(): undefined | string

      The session ID generated for this connection.

      Returns undefined | string

    Methods

    • Closes the connection.

      Returns Promise<void>

    • Call this method after the user has finished authorizing via their user agent and is redirected back to the MCP client application. This will exchange the authorization code for an access token, enabling the next connection attempt to successfully auth.

      Parameters

      • authorizationCode: string

      Returns Promise<void>

    • Sends a JSON-RPC message (request or response).

      If present, relatedRequestId is used to indicate to the transport which incoming request to associate this outgoing message with.

      Parameters

      • message: JSONRPCMessage | JSONRPCMessage[]
      • Optionaloptions: { onresumptiontoken?: (token: string) => void; resumptionToken?: string }

      Returns Promise<void>

    • Sets the protocol version used for the connection (called when the initialize response is received).

      Parameters

      • version: string

      Returns void

    • Starts processing messages on the transport, including any connection steps that might need to be taken.

      This method should only be called after callbacks are installed, or else messages may be lost.

      NOTE: This method should not be called explicitly when using Client, Server, or Protocol classes, as they will implicitly call start().

      Returns Promise<void>

    • Terminates the current session by sending a DELETE request to the server.

      Clients that no longer need a particular session (e.g., because the user is leaving the client application) SHOULD send an HTTP DELETE to the MCP endpoint with the Mcp-Session-Id header to explicitly terminate the session.

      The server MAY respond with HTTP 405 Method Not Allowed, indicating that the server does not allow clients to terminate sessions.

      Returns Promise<void>