interface RateLimitResult { allowed: boolean; reason?: string; retryAfterMs?: number; creditsUsed?: number; creditWarning?: string; } interface SessionStats { inFlight: number; creditsUsed: number; rpmCurrent: number; } type CostCheckResult = { allowed: true; warning?: string; } | { allowed: false; warning: string; }; export declare class McpRateLimiter { private sessions; private keyWindows; private sessionRpm; private keyRpm; private maxConcurrent; constructor(opts?: { sessionRpm?: number; keyRpm?: number; maxConcurrent?: number; }); /** * Check all 4 dimensions before allowing a tool call. * Called at the /mcp endpoint level (SSE mode) or before tool execution (stdio mode). */ check(sessionId: string, apiKey: string): RateLimitResult; /** * Called BEFORE a tool handler executes. Increments in-flight counter. */ acquire(sessionId: string): void; /** * Called AFTER a tool handler completes (success or failure). * Decrements in-flight counter and records credits consumed. */ release(sessionId: string, creditsConsumed: number): void; /** * Dimension 4: Cost-aware check. Called inside tool handlers after * fetching usage info from the backend. Returns a warning string * to append to tool responses, or null if credits are healthy. */ checkCostThreshold(creditsRemaining: number, creditsTotal: number): CostCheckResult; /** Get session stats for health/debug endpoints */ getSessionStats(sessionId: string): SessionStats | null; /** Cleanup when a session is destroyed */ cleanup(sessionId: string): void; /** Cleanup when an API key has no more sessions */ cleanupKey(apiKey: string): void; } export {};