/** * Connection Management System for MCP * * Handles provider connections, health monitoring, failover, and load balancing */ import { EventEmitter } from 'events'; import { MCPConnection, MCPProvider, MCPError, LLMRequest, LLMResponse, MCPClientConfig, RateLimitInfo } from './types'; /** * Provider health monitor */ declare class ProviderHealthMonitor extends EventEmitter { private config; private healthChecks; private healthHistory; private maxHealthHistory; constructor(config: { interval: number; timeout: number; }); /** * Start monitoring provider health */ startMonitoring(providerId: string, connection: MCPConnection): void; /** * Stop monitoring provider health */ stopMonitoring(providerId: string): void; /** * Get provider health score (0-1) */ getHealthScore(providerId: string): number; /** * Record health check result */ private recordHealthCheck; /** * Create timeout promise */ private createTimeout; /** * Stop all monitoring */ stopAll(): void; } /** * Load balancer for distributing requests across providers */ declare class LoadBalancer { private requestCounts; private lastUsed; /** * Select best provider using round-robin with health weighting */ selectProvider(providers: string[], healthMonitor: ProviderHealthMonitor, strategy?: 'round-robin' | 'least-connections' | 'health-weighted'): string | undefined; /** * Record request for load balancing metrics */ recordRequest(providerId: string): void; /** * Round-robin selection */ private roundRobinSelection; /** * Least connections selection */ private leastConnectionsSelection; /** * Health-weighted selection */ private healthWeightedSelection; /** * Calculate provider score for selection */ private calculateProviderScore; } /** * Rate limiter for provider requests */ declare class RateLimiter { private requestCounts; private tokenCounts; /** * Check if request is allowed under rate limits */ isAllowed(providerId: string, rateLimits: RateLimitInfo, tokens?: number): boolean; /** * Record request for rate limiting */ recordRequest(providerId: string, tokens?: number): void; /** * Clean old entries */ private cleanOldEntries; /** * Get current usage stats */ getUsageStats(providerId: string, rateLimits: RateLimitInfo): { requestsPerMinute: { used: number; limit: number; }; tokensPerMinute: { used: number; limit: number; }; requestsPerDay: { used: number; limit: number; }; tokensPerDay: { used: number; limit: number; }; }; } /** * Failover manager for handling provider failures */ declare class FailoverManager extends EventEmitter { private failoverHistory; private maxFailoverAttempts; private failoverWindow; /** * Handle provider failure and attempt failover */ handleFailure(failedProvider: string, availableProviders: string[], request: LLMRequest, error: MCPError): Promise<{ provider: string; shouldRetry: boolean; }>; /** * Record provider failure */ private recordFailure; /** * Check if failover should be attempted */ private shouldAttemptFailover; /** * Select best provider for failover */ private selectFailoverProvider; /** * Reset failure history for provider */ resetFailureHistory(providerId: string): void; /** * Get failure stats */ getFailureStats(providerId: string): { recentFailures: number; lastFailure?: Date; failoverAvailable: boolean; }; } /** * Main connection manager */ export declare class MCPConnectionManager extends EventEmitter { private config; private connections; private providers; private healthMonitor; private loadBalancer; private rateLimiter; private failoverManager; constructor(config: MCPClientConfig); /** * Add provider and establish connection */ addProvider(provider: MCPProvider, connection: MCPConnection): Promise; /** * Remove provider and close connection */ removeProvider(providerId: string): Promise; /** * Send request with load balancing and failover */ sendRequest(request: LLMRequest, preferredProvider?: string): Promise; /** * Send request to specific provider with rate limiting and failover */ private sendRequestToProvider; /** * Get list of available (connected and healthy) providers */ getAvailableProviders(): string[]; /** * Get connection for provider */ getConnection(providerId: string): MCPConnection | undefined; /** * Get provider information */ getProvider(providerId: string): MCPProvider | undefined; /** * Get comprehensive health status */ getHealthStatus(): Promise>; /** * Handle connection disconnection */ private handleDisconnection; /** * Handle connection errors */ private handleConnectionError; /** * Setup event handlers */ private setupEventHandlers; /** * Shutdown connection manager */ shutdown(): Promise; } export { ProviderHealthMonitor, LoadBalancer, RateLimiter, FailoverManager }; //# sourceMappingURL=connection-manager.d.ts.map