/**
 * HTTP Rate Limiter for MCP HTTP Transport
 * Implements token bucket algorithm for rate limiting
 * Provides fault tolerance and prevents server overload
 */
import type { TokenBucketRateLimitConfig, RateLimiterStats } from "../types/index.js";
/**
 * Default rate limit configuration
 * Provides sensible defaults for most MCP HTTP transport use cases
 */
export declare const DEFAULT_RATE_LIMIT_CONFIG: TokenBucketRateLimitConfig;
/**
 * HTTPRateLimiter
 * Implements token bucket algorithm for rate limiting HTTP requests
 *
 * The token bucket algorithm works as follows:
 * - Tokens are added to the bucket at a fixed rate (refillRate per second)
 * - Each request consumes one token
 * - If no tokens are available, the request must wait
 * - Maximum tokens are capped at maxBurst to allow controlled bursting
 */
export declare class HTTPRateLimiter {
    private tokens;
    private lastRefill;
    private config;
    private waitQueue;
    private processingQueue;
    constructor(config?: Partial<TokenBucketRateLimitConfig>);
    /**
     * Refill tokens based on elapsed time since last refill
     * Tokens are added at the configured refillRate (tokens per second)
     */
    private refillTokens;
    /**
     * Acquire a token, waiting if necessary
     * This is the primary method for rate-limited operations
     *
     * @returns Promise that resolves when a token is acquired
     * @throws Error if the wait queue is too long
     */
    acquire(): Promise<void>;
    /**
     * Process the wait queue, granting tokens as they become available
     */
    private processQueue;
    /**
     * Sleep helper function
     */
    private sleep;
    /**
     * Try to acquire a token without waiting
     *
     * @returns true if a token was acquired, false otherwise
     */
    tryAcquire(): boolean;
    /**
     * Handle rate limit response headers from server
     * Parses Retry-After header and returns wait time in milliseconds
     *
     * @param headers - Response headers from the server
     * @returns Wait time in milliseconds, or 0 if no rate limit headers found
     */
    handleRateLimitResponse(headers: Headers): number;
    /**
     * Get the number of remaining tokens
     *
     * @returns Current number of available tokens
     */
    getRemainingTokens(): number;
    /**
     * Reset the rate limiter to initial state
     * Useful for testing or when server indicates rate limits have been reset
     */
    reset(): void;
    /**
     * Get current rate limiter statistics
     */
    getStats(): RateLimiterStats;
    /**
     * Update configuration dynamically
     * Useful when server provides rate limit information
     */
    updateConfig(config: Partial<TokenBucketRateLimitConfig>): void;
    /**
     * Get current configuration
     */
    getConfig(): Readonly<TokenBucketRateLimitConfig>;
}
/**
 * RateLimiterManager
 * Manages multiple rate limiters for different servers
 * Each server can have its own rate limiting configuration
 */
export declare class RateLimiterManager {
    private limiters;
    /**
     * Get or create a rate limiter for a server
     *
     * @param serverId - Unique identifier for the server
     * @param config - Optional configuration for the rate limiter
     * @returns HTTPRateLimiter instance for the server
     */
    getLimiter(serverId: string, config?: Partial<TokenBucketRateLimitConfig>): HTTPRateLimiter;
    /**
     * Check if a rate limiter exists for a server
     *
     * @param serverId - Unique identifier for the server
     * @returns true if a rate limiter exists for the server
     */
    hasLimiter(serverId: string): boolean;
    /**
     * Remove a rate limiter for a server
     *
     * @param serverId - Unique identifier for the server
     */
    removeLimiter(serverId: string): void;
    /**
     * Get all server IDs with active rate limiters
     *
     * @returns Array of server IDs
     */
    getServerIds(): string[];
    /**
     * Get statistics for all rate limiters
     *
     * @returns Record of server IDs to their rate limiter statistics
     */
    getAllStats(): Record<string, RateLimiterStats>;
    /**
     * Reset all rate limiters
     */
    resetAll(): void;
    /**
     * Destroy all rate limiters and clean up resources
     * This should be called during application shutdown
     */
    destroyAll(): void;
    /**
     * Get health summary for all rate limiters
     */
    getHealthSummary(): {
        totalLimiters: number;
        serversWithQueuedRequests: string[];
        totalQueuedRequests: number;
        averageTokensAvailable: number;
    };
}
/**
 * Global rate limiter manager instance
 * Use this for application-wide rate limiting management
 */
export declare const globalRateLimiterManager: RateLimiterManager;
