/** * MCP Rate Limiter * * Fixed-window rate limiter scoped by tenant + tier. * Supports pluggable storage backends via RateLimitStore: * - InMemoryRateLimitStore (default, Map-backed) * - PGliteRateLimitStore (SQL-backed, persistent) * * @example * ```typescript * // In-memory (default) * const limiter = new McpRateLimiter(); * * // PGlite-backed * import { PGlite } from '@electric-sql/pglite'; * import { PGliteRateLimitStore } from './rate-limit-store.js'; * const db = new PGlite(); * const limiter = new McpRateLimiter({ * store: new PGliteRateLimitStore({ db }), * }); * * const result = await limiter.check('tenant-123', 'pro'); * if (!result.allowed) { * throw new Error(`Rate limited. Retry after ${result.resetMs}ms`); * } * ``` */ import { type RateLimitStore } from './rate-limit-store.js'; export interface RateLimitConfig { /** Max requests per window */ maxRequests: number; /** Window size in milliseconds */ windowMs: number; } export interface RateLimitResult { allowed: boolean; remaining: number; limit: number; resetMs: number; } export interface McpRateLimiterOptions { /** Tier-based rate limit configuration. */ limits?: Record; /** Storage backend (default: InMemoryRateLimitStore). */ store?: RateLimitStore; } /** Default rate limits per tier. */ export declare const DEFAULT_TIER_LIMITS: Record; /** * Fixed-window rate limiter scoped by tenant + tier. * Accepts a pluggable RateLimitStore for different storage backends. */ export declare class McpRateLimiter { private store; private limits; private cleanupInterval; constructor(options?: McpRateLimiterOptions); /** * Check if a request is allowed and consume one token if so. * Returns quota information including remaining requests and reset time. */ check(tenantId: string, tier: string): Promise; /** Override limits for a specific tier. */ setTierLimit(tier: string, config: RateLimitConfig): void; /** Clean up expired window entries. */ private cleanup; /** Dispose the rate limiter, clearing the cleanup timer and all windows. */ dispose(): Promise; } //# sourceMappingURL=rate-limiter.d.ts.map