UNPKG

@gohcltech/bitbucket-mcp

Version:

Bitbucket integration for Claude via Model Context Protocol

145 lines 4.7 kB
/** * Configuration interface for rate limiting parameters. * Uses token bucket algorithm to control API request rates. */ export interface RateLimitConfig { /** Maximum number of concurrent requests */ maxConcurrent: number; /** Minimum time between requests in milliseconds */ minTime: number; /** Initial number of tokens in the bucket for burst requests */ reservoir: number; /** Number of tokens to add to the bucket during each refresh */ reservoirRefreshAmount: number; /** Interval in milliseconds for token replenishment */ reservoirRefreshInterval: number; } /** * Statistics about rate limiter operation and queue status. */ export interface RateLimitStats { /** Number of requests waiting in queue */ queued: number; /** Number of requests currently being processed */ running: number; /** Total number of successfully completed requests */ done: number; /** Total number of failed requests */ failed: number; /** Suggested retry delay in milliseconds when rate limited */ retryAfter?: number; } /** * Rate limiter implementation using Bottleneck library. * * Provides intelligent rate limiting for Bitbucket API requests using a combination * of concurrent request limiting and token bucket algorithm. Prevents API quota * exhaustion while maintaining optimal throughput. * * Features: * - Concurrent request limiting * - Token bucket algorithm for burst capacity * - Automatic queue management * - Detailed statistics and monitoring * - Error handling and retry logic * - Event-based logging integration * * @example * ```typescript * const rateLimiter = new RateLimiter({ * maxConcurrent: 10, * minTime: 100, * reservoir: 100, * reservoirRefreshAmount: 50, * reservoirRefreshInterval: 60000 * }); * * await rateLimiter.execute( * () => apiClient.get('/repositories'), * { operationName: 'list_repositories', toolName: 'repository_tools' } * ); * ``` */ export declare class RateLimiter { private logger; private limiter; private config; private stats; constructor(config: RateLimitConfig); /** * Execute a function with rate limiting applied. * * Queues the operation according to rate limiting constraints and executes it * when resources are available. Provides detailed logging and error handling. * * @template T - Return type of the operation * @param operation - Async function to execute with rate limiting * @param context - Execution context for logging and prioritization * @param context.operationName - Human-readable operation name for logging * @param context.toolName - Optional tool name for categorized logging * @param context.priority - Optional priority (1-10, higher = more important) * @returns Promise resolving to the operation result * @throws {RateLimitError} When rate limits are exceeded * * @example * ```typescript * const result = await rateLimiter.execute( * () => fetch('/api/repositories'), * { * operationName: 'fetch_repositories', * toolName: 'repository_tools', * priority: 7 * } * ); * ``` */ execute<T>(operation: () => Promise<T>, context: { operationName: string; toolName?: string; priority?: number; }): Promise<T>; /** * Get current queue and processing statistics */ getStats(): RateLimitStats; /** * Get detailed queue information */ getQueueStats(): Record<string, number>; /** * Check if the rate limiter is currently limiting requests */ isLimited(): boolean; /** * Get the current reservoir level (available tokens) */ getReservoirLevel(): Promise<number>; /** * Manually add tokens to the reservoir */ addTokens(amount: number): Promise<void>; /** * Reset the rate limiter state */ reset(): Promise<void>; /** * Gracefully stop the rate limiter */ stop(): Promise<void>; /** * Update rate limiter configuration */ updateConfig(newConfig: Partial<RateLimitConfig>): void; private setupEventHandlers; private logConfig; private isBottleneckRateLimitError; private extractRetryAfter; } export declare function createRateLimiter(config: RateLimitConfig): RateLimiter; export declare function getRateLimiter(): RateLimiter; export declare function rateLimited<T extends (...args: any[]) => Promise<any>>(target: T, context: { operationName: string; toolName?: string; priority?: number; }): T; //# sourceMappingURL=rate-limiter.d.ts.map