import type { JSONRPCMessage } from './types.js'; import { BaseTransport, type BaseTransportConfig } from './base-transport.js'; /** * Configuration for SSE Transport. */ export interface SSETransportConfig extends BaseTransportConfig { /** Base URL of the MCP server (e.g., https://api.example.com/mcp) */ baseUrl: string; /** Optional session ID for authenticated connections */ sessionId?: string; /** Custom headers to include in requests */ headers?: Record; /** Reconnect delay in milliseconds (default: 1000) */ reconnectDelay?: number; /** Maximum reconnect attempts (default: 5) */ maxReconnectAttempts?: number; /** Request timeout in milliseconds (default: 30000) */ timeout?: number; } /** * SSETransport connects to MCP servers over HTTP using Server-Sent Events. * * This transport is used for remote MCP servers that expose an SSE endpoint. * Messages from the server are received via SSE, while requests are sent * via HTTP POST. * * Expected server endpoints: * - GET {baseUrl}/sse - SSE endpoint for receiving messages * - POST {baseUrl}/message - Endpoint for sending messages */ export declare class SSETransport extends BaseTransport { private streamAbortController; private connected; private reconnectAttempts; private readonly baseUrl; private readonly sessionId?; private readonly headers; private readonly reconnectDelay; private readonly maxReconnectAttempts; private readonly timeout; private messageEndpoint; /** Timer ID for reconnection delay - allows cancellation */ private reconnectTimer; /** Flag to prevent reconnection after close() is called */ private isClosing; /** Maximum backoff delay in milliseconds */ private readonly maxBackoffDelay; constructor(config: SSETransportConfig); /** * Connect to the SSE endpoint. */ connect(): Promise; /** * Handle an incoming SSE message. */ private handleSSEMessage; /** * Stream and parse SSE events from a fetch response. */ private readSSEStream; /** * Handle reconnection after a connection error. * * RELIABILITY IMPROVEMENTS: * - Prevents unbounded recursion with max attempts check * - Uses capped exponential backoff * - Clears reconnect timer on close * - Checks isClosing flag to prevent reconnection after close() * - Explicitly aborts SSE stream on max attempts */ private handleReconnect; /** * Send a JSON-RPC message to the server via HTTP POST. */ send(message: JSONRPCMessage, _signal?: AbortSignal): void; /** * Close the SSE connection. * * RELIABILITY: Properly cleans up all resources including: * - SSE stream connection * - Pending HTTP requests (via abort controller) * - Reconnection timer * - Sets isClosing flag to prevent reconnection attempts */ close(): void; /** * Check if the transport is connected. */ isConnected(): boolean; } //# sourceMappingURL=sse-transport.d.ts.map