@toolprint/hypertool-mcp
Version:
HyperTool MCP proxy server for routing requests between clients and multiple underlying MCP servers
194 lines • 4.9 kB
TypeScript
/**
* Error recovery and graceful degradation mechanisms
*/
import { EventEmitter } from "events";
/**
* Retry configuration
*/
export interface RetryConfig {
maxAttempts: number;
baseDelayMs: number;
maxDelayMs: number;
backoffMultiplier: number;
jitter: boolean;
}
/**
* Default retry configuration
*/
export declare const DEFAULT_RETRY_CONFIG: RetryConfig;
/**
* Circuit breaker states
*/
export declare enum CircuitBreakerState {
CLOSED = "closed",
OPEN = "open",
HALF_OPEN = "half_open"
}
/**
* Circuit breaker configuration
*/
export interface CircuitBreakerConfig {
failureThreshold: number;
recoveryTimeoutMs: number;
monitoringPeriodMs: number;
successThreshold: number;
}
/**
* Default circuit breaker configuration
*/
export declare const DEFAULT_CIRCUIT_BREAKER_CONFIG: CircuitBreakerConfig;
/**
* Fallback strategy interface
*/
export interface FallbackStrategy<T = any> {
execute(context: FallbackContext): Promise<T>;
canHandle(error: Error): boolean;
}
/**
* Fallback context
*/
export interface FallbackContext {
originalError: Error;
attemptNumber: number;
operation: string;
context?: Record<string, any>;
}
/**
* Retry utility with exponential backoff
*/
export declare class RetryManager {
private config;
private logger;
constructor(config?: Partial<RetryConfig>);
/**
* Execute operation with retry logic
*/
execute<T>(operation: () => Promise<T>, operationName: string, context?: Record<string, any>): Promise<T>;
/**
* Calculate retry delay with exponential backoff
*/
private calculateDelay;
/**
* Sleep for specified milliseconds
*/
private sleep;
}
/**
* Circuit breaker for preventing cascading failures
*/
export declare class CircuitBreaker extends EventEmitter {
private name;
private state;
private failureCount;
private successCount;
private lastFailureTime?;
private config;
private logger;
private monitoringTimer?;
constructor(name: string, config?: Partial<CircuitBreakerConfig>);
/**
* Execute operation through circuit breaker
*/
execute<T>(operation: () => Promise<T>): Promise<T>;
/**
* Get current circuit breaker state
*/
getState(): CircuitBreakerState;
/**
* Get circuit breaker metrics
*/
getMetrics(): {
state: CircuitBreakerState;
failureCount: number;
successCount: number;
lastFailureTime: Date | undefined;
};
/**
* Reset circuit breaker
*/
reset(): void;
/**
* Handle successful operation
*/
private onSuccess;
/**
* Handle failed operation
*/
private onFailure;
/**
* Set circuit breaker state
*/
private setState;
/**
* Start monitoring for automatic state transitions
*/
private startMonitoring;
/**
* Stop monitoring
*/
destroy(): void;
}
/**
* Fallback manager for graceful degradation
*/
export declare class FallbackManager {
private strategies;
private logger;
constructor();
/**
* Register a fallback strategy
*/
registerStrategy(strategy: FallbackStrategy): void;
/**
* Execute operation with fallback strategies
*/
executeWithFallback<T>(operation: () => Promise<T>, operationName: string, context?: Record<string, any>): Promise<T>;
/**
* Execute fallback strategies
*/
private executeFallback;
}
/**
* Default fallback strategy for server unavailable errors
*/
export declare class ServerUnavailableFallback implements FallbackStrategy {
private fallbackMessage;
constructor(fallbackMessage?: string);
canHandle(error: Error): boolean;
execute(context: FallbackContext): Promise<any>;
}
/**
* Recovery coordinator that manages retry, circuit breakers, and fallbacks
*/
export declare class RecoveryCoordinator {
private retryManager;
private circuitBreakers;
private fallbackManager;
private logger;
constructor(retryConfig?: Partial<RetryConfig>, circuitBreakerConfig?: Partial<CircuitBreakerConfig>);
/**
* Execute operation with full recovery mechanisms
*/
executeWithRecovery<T>(operation: () => Promise<T>, operationName: string, circuitBreakerName?: string, context?: Record<string, any>): Promise<T>;
/**
* Execute operation with circuit breaker
*/
private executeWithCircuitBreaker;
/**
* Get circuit breaker metrics
*/
getCircuitBreakerMetrics(): Record<string, any>;
/**
* Register custom fallback strategy
*/
registerFallbackStrategy(strategy: FallbackStrategy): void;
/**
* Reset all circuit breakers
*/
resetCircuitBreakers(): void;
/**
* Cleanup resources
*/
destroy(): void;
}
//# sourceMappingURL=recovery.d.ts.map