Skip to main content
Glama
QianJue-CN

Random.org MCP Server

by QianJue-CN
rateLimiter.ts1.2 kB
export class RateLimiter { private tokens: number; private lastRefill: number; private readonly maxTokens: number; private readonly refillRate: number; // tokens per second constructor(requestsPerSecond: number, burstSize: number) { this.maxTokens = burstSize; this.tokens = burstSize; this.refillRate = requestsPerSecond; this.lastRefill = Date.now(); } async waitForToken(): Promise<void> { this.refillTokens(); if (this.tokens >= 1) { this.tokens -= 1; return; } // Calculate how long to wait for the next token const timeToWait = (1 / this.refillRate) * 1000; // Convert to milliseconds await new Promise(resolve => setTimeout(resolve, timeToWait)); // Try again after waiting return this.waitForToken(); } private refillTokens(): void { const now = Date.now(); const timePassed = (now - this.lastRefill) / 1000; // Convert to seconds const tokensToAdd = timePassed * this.refillRate; this.tokens = Math.min(this.maxTokens, this.tokens + tokensToAdd); this.lastRefill = now; } getAvailableTokens(): number { this.refillTokens(); return Math.floor(this.tokens); } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/QianJue-CN/TRUERandomMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server