UNPKG

firewalla-mcp-server

Version:

Model Context Protocol (MCP) server for Firewalla MSP API - Provides real-time network monitoring, security analysis, and firewall management through 28 specialized tools compatible with any MCP client

140 lines 4.15 kB
/** * Timeout Management Utilities for Firewalla MCP Server * Provides consistent timeout handling across all tools and operations */ /** * Timeout configuration options */ export interface TimeoutConfig { /** Timeout duration in milliseconds */ timeoutMs?: number; /** Warning threshold in milliseconds */ warningMs?: number; /** Error threshold in milliseconds */ errorMs?: number; /** Whether to log performance metrics */ enableMetrics?: boolean; /** Tool name for context */ toolName?: string; } /** * Performance metrics for monitoring */ export interface PerformanceMetrics { startTime: number; endTime?: number; duration?: number; toolName: string; success: boolean; timedOut: boolean; warning: boolean; error: boolean; } /** * Timeout error class for actual timeout situations */ export declare class TimeoutError extends Error { readonly isTimeout = true; readonly duration: number; readonly toolName: string; constructor(toolName: string, duration: number, timeoutMs: number); } /** * Validation error class for immediate parameter/validation failures */ export declare class ValidationError extends Error { readonly isValidation = true; readonly duration: number; readonly toolName: string; constructor(toolName: string, duration: number, originalError: string); } /** * Performance warning class for monitoring */ export declare class PerformanceWarning extends Error { readonly isWarning = true; readonly duration: number; readonly toolName: string; constructor(toolName: string, duration: number, threshold: number); } /** * Timeout manager class for handling operation timeouts */ export declare class TimeoutManager { private activeTimeouts; private metrics; private readonly maxMetrics; /** * Execute an async operation with timeout protection */ withTimeout<T>(operation: () => Promise<T>, config?: Partial<TimeoutConfig>): Promise<T>; /** * Create a timeout-wrapped version of an async function */ wrapWithTimeout<T extends any[], R>(fn: (...args: T) => Promise<R>, config?: Partial<TimeoutConfig>): (...args: T) => Promise<R>; /** * Record performance metrics */ private recordMetrics; /** * Get performance metrics for a specific tool */ getMetrics(toolName?: string): PerformanceMetrics[]; /** * Get performance statistics */ getPerformanceStats(toolName?: string): { totalOperations: number; successRate: number; timeoutRate: number; warningRate: number; averageDuration: number; maxDuration: number; minDuration: number; }; /** * Clear all metrics (useful for testing) */ clearMetrics(): void; /** * Cancel all active timeouts (useful for cleanup) */ cancelAllTimeouts(): void; /** * Get the number of active operations */ getActiveOperationsCount(): number; } /** * Global timeout manager instance */ export declare const globalTimeoutManager: TimeoutManager; /** * Convenience function for wrapping tool operations with timeout */ export declare function withToolTimeout<T>(operation: () => Promise<T>, toolName: string, customTimeoutMs?: number): Promise<T>; /** * Create a standardized validation error response for MCP tools */ export declare function createValidationErrorResponse(toolName: string, duration: number, originalError: string): { content: Array<{ type: string; text: string; }>; isError: true; }; /** * Create a standardized timeout error response for MCP tools with enhanced guidance */ export declare function createTimeoutErrorResponse(toolName: string, duration: number, timeoutMs: number): { content: Array<{ type: string; text: string; }>; isError: true; }; /** * Create a performance warning response for MCP tools */ export declare function createPerformanceWarningResponse(toolName: string, duration: number, threshold: number): string; //# sourceMappingURL=timeout-manager.d.ts.map