/** * MCP Client - Manages connections to MCP servers using the official SDK * * Supports: * - stdio transport (local process spawning) * - SSE transport (legacy HTTP/SSE) * - StreamableHTTP transport (modern HTTP) * - WebSocket transport (real-time bidirectional) * * Lifecycle: connect → initialize → discover → ready ↔ disconnected → close */ export type TransportType = "stdio" | "sse" | "streamable-http" | "websocket"; export interface StdioServerConfig { type: "stdio"; command: string; args?: string[]; env?: Record; cwd?: string; } export interface SseServerConfig { type: "sse"; url: string; headers?: Record; } export interface StreamableHttpServerConfig { type: "streamable-http"; url: string; headers?: Record; sessionId?: string; } export interface WebSocketServerConfig { type: "websocket"; url: string; } export type ServerTransportConfig = StdioServerConfig | SseServerConfig | StreamableHttpServerConfig | WebSocketServerConfig; /** Full config for a single MCP server entry */ export interface MCPServerConfig { /** Unique name for this server */ name: string; /** Transport configuration */ transport: ServerTransportConfig; /** Whether to auto-connect on startup */ enabled: boolean; /** Auto-reconnect on disconnect */ autoReconnect?: boolean; /** Maximum reconnection attempts */ maxReconnectAttempts?: number; /** Reconnection delay in ms */ reconnectDelayMs?: number; /** Connection timeout in ms (default: 30000) */ connectTimeoutMs?: number; /** Only register tools matching these names (allowlist). Mutually exclusive with deniedTools. */ allowedTools?: string[]; /** Register all tools except those matching these names (denylist). Mutually exclusive with allowedTools. */ deniedTools?: string[]; } export type ConnectionStatus = "disconnected" | "connecting" | "initializing" | "ready" | "error"; export interface DiscoveredTool { name: string; description?: string; inputSchema: Record; outputSchema?: Record; annotations?: Record; } export interface DiscoveredResource { uri: string; name: string; description?: string; mimeType?: string; } export interface DiscoveredPrompt { name: string; description?: string; arguments?: Array<{ name: string; description?: string; required?: boolean; }>; } export interface ConnectionInfo { name: string; status: ConnectionStatus; error?: string; tools: DiscoveredTool[]; resources: DiscoveredResource[]; prompts: DiscoveredPrompt[]; serverVersion?: string; protocolVersion?: string; /** Tool allowlist — only these tools will be registered */ allowedTools?: string[]; /** Tool denylist — these tools will be skipped */ deniedTools?: string[]; /** Timestamp when connection was established (epoch ms) */ connectedAt?: number; /** Number of successful tool calls */ toolCallCount?: number; /** Number of failed tool calls */ toolCallErrorCount?: number; /** Last error message (even if currently connected) */ lastError?: string; } export declare class ResourceCache { private readonly entries; private readonly maxSize; private readonly defaultTtlMs; constructor(maxSize?: number, defaultTtlMs?: number); get(key: string): unknown | undefined; set(key: string, value: unknown, ttlMs?: number): void; invalidate(key: string): boolean; clear(): void; get size(): number; } export declare class MCPConnectionManager { private readonly connections; private readonly onChangeCallbacks; private readonly workspaceRoots; readonly resourceCache: ResourceCache; constructor(workspaceRoots?: string[], cacheMaxSize?: number, cacheTtlMs?: number); /** Connect to a single MCP server */ connect(config: MCPServerConfig): Promise; private connectWithReconnectAttempts; /** Disconnect from a server */ disconnect(name: string): Promise; /** Disconnect all servers */ disconnectAll(): Promise; /** Call a tool on a connected server */ callTool(serverName: string, toolName: string, args: Record, timeoutMs?: number): Promise; /** Read a resource from a connected server */ readResource(serverName: string, uri: string, timeoutMs?: number): Promise; /** Get a prompt from a connected server */ getPrompt(serverName: string, promptName: string, args?: Record, timeoutMs?: number): Promise; /** Re-discover tools/resources/prompts for a server */ refresh(name: string): Promise; /** Get connection info for a server */ getConnectionInfo(name: string): ConnectionInfo | undefined; /** Get all connection infos */ getAllConnectionInfo(): ConnectionInfo[]; /** Subscribe to connection changes */ onChange(callback: (name: string, info: ConnectionInfo) => void): () => void; private createTransport; private discover; private setupReconnect; private scheduleReconnect; private getConnectionOrThrow; private assertStatus; private emitChange; } /** * Interpolate `${ENV_VAR}` patterns in string values of a record. * Returns a new record with values resolved from process.env. * Missing env vars are replaced with an empty string. */ export declare function interpolateEnv(record: Record | undefined): Record; //# sourceMappingURL=index.d.ts.map