/** * Health Check Implementation for MCP Server * * Provides comprehensive health monitoring capabilities including * server status, dependency checks, and performance metrics. * * @packageDocumentation */ import type { Logger } from '../types'; /** * Health status values */ export type HealthStatus = 'healthy' | 'degraded' | 'unhealthy'; /** * Individual health check result */ export interface HealthCheckResult { /** Name of the check */ readonly name: string; /** Status of the check */ readonly status: HealthStatus; /** Human-readable description */ readonly message?: string; /** Time taken to perform the check (ms) */ readonly duration: number; /** Timestamp of the check */ readonly timestamp: Date; /** Additional details */ readonly details?: Record; } /** * Aggregate health report */ export interface HealthReport { /** Overall health status */ readonly status: HealthStatus; /** Server uptime in milliseconds */ readonly uptime: number; /** Timestamp of the report */ readonly timestamp: Date; /** Individual check results */ readonly checks: readonly HealthCheckResult[]; /** Server version */ readonly version: string; /** Server name */ readonly serverName: string; } /** * Health check function type */ export type HealthCheckFunction = () => Promise; /** * Health check registration */ export interface HealthCheckRegistration { /** Check name */ readonly name: string; /** Check function */ readonly check: HealthCheckFunction; /** Whether the check is critical (affects overall status) */ readonly critical?: boolean; /** Timeout for the check in milliseconds */ readonly timeout?: number; /** Check interval for periodic monitoring */ readonly interval?: number; } /** * Health check manager configuration */ export interface HealthCheckConfig { /** Server name for reporting */ readonly serverName: string; /** Server version for reporting */ readonly version: string; /** Default timeout for checks (ms) */ readonly defaultTimeout?: number; /** Whether to run checks periodically */ readonly enablePeriodicChecks?: boolean; /** Default interval for periodic checks (ms) */ readonly defaultInterval?: number; /** Logger instance */ readonly logger?: Logger; } /** * Create a memory usage health check * * @param thresholds - Memory thresholds for degraded/unhealthy status * @returns Health check function */ export declare function createMemoryHealthCheck(thresholds?: { degradedPercent?: number; unhealthyPercent?: number; }): HealthCheckFunction; /** * Create an event loop lag health check * * @param thresholds - Event loop lag thresholds * @returns Health check function */ export declare function createEventLoopHealthCheck(thresholds?: { degradedMs?: number; unhealthyMs?: number; }): HealthCheckFunction; /** * Create a process health check * * @returns Health check function */ export declare function createProcessHealthCheck(): HealthCheckFunction; /** * Health Check Manager * * Manages health checks for the MCP server, providing both * on-demand and periodic health monitoring. * * @example * ```typescript * const healthManager = new HealthCheckManager({ * serverName: 'wundr-mcp-server', * version: '1.0.0', * }); * * healthManager.registerCheck({ * name: 'database', * check: async () => { * // Check database connection * return { * name: 'database', * status: 'healthy', * duration: 10, * timestamp: new Date(), * }; * }, * critical: true, * }); * * const report = await healthManager.getHealthReport(); * ``` */ export declare class HealthCheckManager { private readonly config; private readonly checks; private readonly periodicChecks; private readonly lastResults; private readonly startTime; private readonly logger?; /** * Create a new Health Check Manager * * @param config - Manager configuration */ constructor(config: HealthCheckConfig); /** * Register a health check * * @param registration - Health check registration */ registerCheck(registration: HealthCheckRegistration): void; /** * Unregister a health check * * @param name - Check name to unregister * @returns Whether the check was unregistered */ unregisterCheck(name: string): boolean; /** * Run a single health check * * @param name - Check name to run * @returns Check result */ runCheck(name: string): Promise; /** * Get a complete health report * * @param useCache - Whether to use cached results for periodic checks * @returns Comprehensive health report */ getHealthReport(useCache?: boolean): Promise; /** * Get a quick liveness check * * @returns Simple liveness response */ getLiveness(): { alive: boolean; uptime: number; }; /** * Get a readiness check * * @returns Whether the server is ready to accept requests */ getReadiness(): Promise<{ ready: boolean; checks: string[]; }>; /** * Start all periodic checks */ startPeriodicChecks(): void; /** * Stop all periodic checks */ stopPeriodicChecks(): void; /** * Get the last result for a check * * @param name - Check name * @returns Last check result or undefined */ getLastResult(name: string): HealthCheckResult | undefined; /** * Get all registered check names */ getRegisteredChecks(): string[]; /** * Register built-in health checks */ private registerBuiltInChecks; /** * Execute a health check with timeout */ private executeCheck; /** * Start periodic execution of a health check */ private startPeriodicCheck; /** * Calculate overall health status from check results */ private calculateOverallStatus; } /** * Create a health check manager with default configuration * * @param serverName - Server name * @param version - Server version * @returns Configured health check manager */ export declare function createHealthCheckManager(serverName: string, version: string): HealthCheckManager; //# sourceMappingURL=health-check.d.ts.map