/** * @file mcp-client.service.ts * @description Service for managing connections to remote MCP servers */ import { type AuthInfo, type CallToolResult, type GetPromptResult, type Prompt, type ReadResourceResult, type Resource, type ResourceTemplate, type Tool } from '@frontmcp/protocol'; import { type FrontMcpLogger } from '../common'; import type { McpCapabilityChangeCallback, McpClientConnection, McpClientServiceOptions, McpConnectionChangeCallback, McpConnectionInfo, McpConnectRequest, McpRemoteAuthConfig, McpRemoteAuthContext, McpRemoteCapabilities, McpUnsubscribeFn } from './mcp-client.types'; import { type CircuitBreaker, type HealthChecker } from './resilience'; /** * Service for managing connections to remote MCP servers. * * This service handles: * - Connection lifecycle (connect, disconnect, reconnect) * - Capability discovery (tools, resources, prompts) * - Proxy execution (callTool, readResource, getPrompt) * - Authentication context forwarding * - Event subscriptions for capability and connection changes */ export declare class McpClientService { private readonly connections; private readonly capabilities; private readonly configs; private readonly options; private readonly logger; private readonly capabilityChangeCallbacks; private readonly connectionChangeCallbacks; private readonly refreshTimers; private readonly refreshInProgress; private readonly circuitBreakerManager; private readonly healthCheckManager; private readonly reconnectAttempts; private readonly reconnectTimers; constructor(logger: FrontMcpLogger, options?: McpClientServiceOptions); /** * Connect to a remote MCP server */ connect(request: McpConnectRequest): Promise; /** * Disconnect from a remote MCP server */ disconnect(appId: string): Promise; /** * Reconnect to a remote MCP server */ reconnect(appId: string): Promise; /** * Get connection status for an app */ getConnectionStatus(appId: string): McpConnectionInfo | undefined; /** * Check if connected to an app */ isConnected(appId: string): boolean; /** * Discover capabilities from a remote server */ discoverCapabilities(appId: string): Promise; /** * Get cached capabilities for an app */ getCapabilities(appId: string): McpRemoteCapabilities | undefined; /** * List tools from a remote server */ listTools(appId: string): Promise; /** * List resources from a remote server */ listResources(appId: string): Promise; /** * List resource templates from a remote server */ listResourceTemplates(appId: string): Promise; /** * List prompts from a remote server */ listPrompts(appId: string): Promise; /** * Call a tool on a remote server with self-healing */ callTool(appId: string, toolName: string, args: Record, authContext?: McpRemoteAuthContext): Promise; /** * Read a resource from a remote server */ readResource(appId: string, uri: string, authContext?: McpRemoteAuthContext): Promise; /** * Get a prompt from a remote server */ getPrompt(appId: string, promptName: string, args: Record, authContext?: McpRemoteAuthContext): Promise; /** * Subscribe to capability change events */ onCapabilityChange(callback: McpCapabilityChangeCallback): McpUnsubscribeFn; /** * Subscribe to connection status change events */ onConnectionChange(callback: McpConnectionChangeCallback): McpUnsubscribeFn; /** * Resolve authentication headers for a remote request */ resolveAuthHeaders(appId: string, authConfig: McpRemoteAuthConfig | undefined, gatewayAuthInfo?: AuthInfo): Promise>; /** * Disconnect from all remote servers and clean up */ dispose(): Promise; private getConnection; /** * Create transport for a remote connection. * * Note: For HTTP transport with fallback, the initial transport is Streamable HTTP. * If connection fails with Streamable HTTP, use createFallbackTransport() to get SSE. */ private createTransport; /** * Create fallback SSE transport when Streamable HTTP fails */ private createFallbackSSETransport; /** * Check if fallback to SSE is enabled for a request */ private shouldFallbackToSSE; private listToolsInternal; private listResourcesInternal; private listResourceTemplatesInternal; private listPromptsInternal; private updateConnectionStatus; private emitCapabilityChangeIfNeeded; private startCapabilityRefresh; private stopCapabilityRefresh; private buildAuthHeaders; /** * Schedule an auto-reconnect attempt for an app */ private scheduleAutoReconnect; /** * Cancel scheduled auto-reconnect for an app */ private cancelAutoReconnect; /** * Handle health status changes for proactive healing */ private handleHealthStatusChange; /** * Start health checking for an app */ private startHealthCheck; /** * Stop health checking for an app */ private stopHealthCheck; /** * Get circuit breaker status for an app */ getCircuitBreakerStatus(appId: string): ReturnType | undefined; /** * Get health check status for an app */ getHealthStatus(appId: string): ReturnType | undefined; /** * Manually reset circuit breaker for an app */ resetCircuitBreaker(appId: string): void; /** * Force a health check for an app */ forceHealthCheck(appId: string): Promise; } //# sourceMappingURL=mcp-client.service.d.ts.map