UNPKG

@ai-capabilities-suite/mcp-debugger-core

Version:

Core debugging engine for Node.js and TypeScript applications. Provides Inspector Protocol integration, breakpoint management, variable inspection, execution control, profiling, hang detection, and source map support.

127 lines (126 loc) 4.11 kB
/** * Rate limit configuration for an operation type */ export interface RateLimitConfig { maxRequests: number; windowMs: number; } /** * Rate limit metrics */ export interface RateLimitMetrics { operationType: string; requestCount: number; limitExceeded: number; currentWindow: { count: number; resetAt: Date; }; } /** * Rate limit error */ export declare class RateLimitError extends Error { operationType: string; retryAfter: number; constructor(message: string, operationType: string, retryAfter: number); } /** * Manages rate limiting for debugging operations * Tracks requests per operation type and enforces limits */ export declare class RateLimiter { private limits; private entries; private metrics; private defaultConfig?; private defaultEntries; /** * Create a new RateLimiter * @param defaultConfig Optional default rate limit configuration */ constructor(defaultConfig?: RateLimitConfig); /** * Configure rate limit for an operation type * @param operationType The operation type (e.g., 'debugger_start', 'debugger_set_breakpoint') * @param config Rate limit configuration */ setLimit(operationType: string, config: RateLimitConfig): void; /** * Check if a request is allowed under rate limits * @param operationTypeOrIdentifier The operation type, or identifier if using default config * @param identifier Optional unique identifier for the requester (e.g., session ID, user ID) * @returns Object with allowed status and retryAfter time */ checkLimit(operationTypeOrIdentifier: string, identifier?: string): { allowed: boolean; retryAfter?: number; }; /** * Check limit using default configuration * @param identifier Unique identifier for the requester * @returns Object with allowed status and retryAfter time */ private checkDefaultLimit; /** * Check if a request is allowed and throw error if not (legacy method) * @param operationType The operation type * @param identifier Unique identifier for the requester * @throws RateLimitError if the rate limit is exceeded */ checkLimitOrThrow(operationType: string, identifier?: string): void; /** * Get the current rate limit status for an operation and identifier * @param operationType The operation type * @param identifier Unique identifier for the requester * @returns Current count and reset time, or null if no limit configured */ getStatus(operationType: string, identifier?: string): { count: number; limit: number; resetAt: Date; } | null; /** * Get metrics for an operation type * @param operationType The operation type * @returns Metrics for the operation type */ getMetrics(operationType: string): RateLimitMetrics | null; /** * Get metrics for all operation types * @returns Array of metrics for all operation types */ getAllMetrics(): RateLimitMetrics[]; /** * Reset rate limit for a specific identifier * @param operationType The operation type * @param identifier Unique identifier for the requester * @returns True if the entry was found and reset */ reset(operationType: string, identifier?: string): boolean; /** * Reset all rate limits for an operation type * @param operationType The operation type * @returns True if the operation type was found */ resetAll(operationType: string): boolean; /** * Clean up expired entries */ cleanup(): void; /** * Clear all rate limits and metrics */ clear(): void; /** * Get all configured operation types * @returns Array of operation types */ getOperationTypes(): string[]; /** * Check if an operation type has a rate limit configured * @param operationType The operation type * @returns True if a rate limit is configured */ hasLimit(operationType: string): boolean; }