@modelcontextprotocol/sdk
    Preparing search index...

    Class SSEServerTransport

    Server transport for SSE: this will send messages over an SSE connection and receive messages from HTTP POST requests.

    This transport is only available in Node.js environments.

    Implements

    Index

    Constructors

    • Creates a new SSE server transport, which will direct the client to POST messages to the relative or absolute URL identified by _endpoint.

      Parameters

      • _endpoint: string
      • res: ServerResponse

      Returns SSEServerTransport

    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?: { authInfo?: AuthInfo }) => void

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

    Includes the authInfo if the transport is authenticated.

    Accessors

    • get sessionId(): string

      Returns the session ID for this transport.

      This can be used to route incoming POST requests.

      Returns string

    Methods

    • Handle a client message, regardless of how it arrived. This can be used to inform the server of messages that arrive via a means different than HTTP POST.

      Parameters

      • message: unknown
      • Optionalextra: { authInfo?: AuthInfo }

      Returns Promise<void>

    • Handles incoming POST messages.

      This should be called when a POST request is made to send a message to the server.

      Parameters

      • req: IncomingMessage & { auth?: AuthInfo }
      • res: ServerResponse
      • OptionalparsedBody: unknown

      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

      Returns Promise<void>

    • Handles the initial SSE connection request.

      This should be called when a GET request is made to establish the SSE stream.

      Returns Promise<void>