import { JSONRPCMessage } from '@modelcontextprotocol/sdk/types.js'; import { Transport } from '@modelcontextprotocol/sdk/shared/transport.js'; /** * SSE (Server-Sent Events) transport implementation for MCP protocol communication. * * This transport provides a unidirectional communication channel from server to client * using the Server-Sent Events (SSE) protocol. It is designed for MCP servers that * support SSE for streaming notifications and responses to the client. * * **Key Features:** * - Automatic reconnection with exponential backoff strategy * - JSON-RPC message parsing and validation * - Configurable connection parameters (headers, reconnect interval, max attempts) * - Built-in error handling and logging * - Graceful shutdown and cleanup * * **Limitations:** * - SSE is unidirectional (server-to-client only) * - Client-to-server messages are not supported via this transport * - For bidirectional communication, use stdio or HTTP transports instead * * **Usage Scenario:** * Ideal for remote MCP servers that expose SSE endpoints for real-time updates, * notifications, or streaming responses where the client primarily receives data * from the server rather than sending requests. * * @implements {Transport} */ export declare class SseTransport implements Transport { private url; private headers; private reconnectInterval; private maxReconnectAttempts; private proxy?; private eventSource; private reconnectAttempts; private isClosing; private _serverName?; private _compositeKey?; onmessage?: (message: JSONRPCMessage) => void; onerror?: (error: Error) => void; onclose?: () => void; /** * Creates a new SSE transport instance. * * @param url - The SSE endpoint URL to connect to * @param headers - Optional HTTP headers to include in the SSE connection request * @param reconnectInterval - Time interval (in milliseconds) between reconnection attempts (default: 3000ms) * @param maxReconnectAttempts - Maximum number of reconnection attempts before giving up (default: 5) * @param proxy - Optional proxy configuration * @param serverName - Optional server name for logging * @param compositeKey - Optional composite key (serverName-serverIndex) for logging */ constructor(url: string, headers?: Record, reconnectInterval?: number, maxReconnectAttempts?: number, proxy?: { url: string; } | undefined, serverName?: string, compositeKey?: string); /** * Helper method to format log messages with server context. * * @param message - The base message * @returns Formatted message with server context if available */ private formatLogMessage; /** * Initializes and starts the SSE connection to the specified URL. * * This method establishes a connection to the SSE endpoint, sets up event handlers * for message processing, error handling, and connection lifecycle events. * It also configures automatic reconnection logic for handling transient network issues. * * @throws {Error} If the transport is already started or if connection creation fails * @returns {Promise} Resolves when the connection is successfully established */ start(): Promise; /** * Restarts the SSE connection by closing the current connection and starting a new one. * * This method is used internally for automatic reconnection after connection failures. * It ensures proper cleanup of the existing connection before attempting to establish * a new one, preventing resource leaks or duplicate connections. * * @returns {Promise} Resolves when the restart process is complete */ private restart; /** * Gracefully closes the SSE connection and prevents further reconnection attempts. * * This method sets the closing flag to prevent automatic reconnection and then * delegates to the internal close implementation for actual cleanup. * * @returns {Promise} Resolves when the connection is fully closed */ close(): Promise; /** * Performs the actual cleanup of the SSE connection resources. * * This internal method handles the low-level closing of the EventSource connection, * nullifies the reference, and triggers the onclose callback if defined. * It is used by both the public close method and the restart method. * * @returns {Promise} Resolves when internal cleanup is complete */ private closeInternal; /** * Attempts to send a JSON-RPC message through the SSE transport. * * **Note**: This method always throws an error because SSE is a unidirectional * protocol (server-to-client only). Client-to-server communication is not supported * by the SSE protocol specification. * * For bidirectional MCP communication, use stdio or HTTP transports instead. * * @param message - The JSON-RPC message to send (will not be actually sent) * @throws {Error} Always throws an error indicating that SSE transport does not support sending messages * @returns {Promise} Never resolves successfully due to the inherent limitation of SSE */ send(message: JSONRPCMessage): Promise; } //# sourceMappingURL=sse-transport.d.ts.map