DocsRuntimemcpMCPSSEClient
Package: @hexos/runtime

MCP client implementation using SSE (Server-Sent Events) transport for HTTP-based communication.

Uses the official MCP SDK’s SSEClientTransport to communicate with MCP servers over HTTP. The transport connects to an SSE endpoint via GET for receiving server messages and sends client messages via POST to a separate messages endpoint.

Note: SSEClientTransport is deprecated in the MCP SDK in favor of StreamableHTTPClientTransport, but is retained here for compatibility with servers using SSEServerTransport.

Wraps all requests with configurable timeout handling to prevent indefinite hangs.

Implements IMCPClient interface and is managed by MCPManager. Configuration provided via MCPSSEServerConfig.

class MCPSSEClient extends EventEmitter implements IMCPClient {
    constructor(serverName: string, config: MCPSSEServerConfig)
    connect() => Promise<void>;
    listTools() => Promise<MCPToolInfo[]>;
    callTool(name: string, args: unknown) => Promise<unknown>;
    disconnect() => void;
    isConnected() => boolean;
}

constructor

(serverName: string, config: MCPSSEServerConfig) => MCPSSEClient

Create a new SSE MCP client instance.

connect

() => Promise

Connect to the MCP server via SSE transport.

Creates an SSEClientTransport instance pointing to the configured URL and wraps it with an MCP SDK Client. Sets up event handlers for connection lifecycle (close, error). The transport handles the MCP protocol handshake automatically.

Idempotent - returns immediately if already connected.

listTools

() => Promise<MCPToolInfo[]>

Retrieve all tools available from the MCP server.

Calls the MCP SDK’s listTools method and transforms the response into the common MCPToolInfo format. Wraps the request with timeout handling to prevent hangs.

Supports debug logging of raw tool data via config.debug flag.

callTool

(name: string, args: unknown) => Promise

Execute a tool on the MCP server with the provided arguments.

Calls the MCP SDK’s callTool method with the tool name and arguments. Extracts text content from the MCP response (which returns content arrays) and attempts JSON parsing if the result looks like JSON.

Wraps the request with timeout handling to prevent hangs.

disconnect

() => void

Disconnect from the MCP server and clean up all resources.

Closes the SSE transport and MCP client instances, then resets connection state. Transport closure will trigger the onclose handler.

isConnected

() => boolean

Check whether the client is currently connected to the MCP server.