UNPKG

okta-mcp-server

Version:

Model Context Protocol (MCP) server for Okta API operations with support for bulk operations and caching

45 lines 1.29 kB
/** * Simple rate limiter for bulk operations */ export class RateLimiter { tokens; lastRefill; maxTokens; refillRate; constructor(options) { this.maxTokens = options.max; this.tokens = options.max; this.lastRefill = Date.now(); this.refillRate = options.max / options.window; // tokens per ms } /** * Attempt to consume tokens */ async consume(_key, count = 1) { this.refill(); if (this.tokens >= count) { this.tokens -= count; return { allowed: true, remaining: Math.floor(this.tokens), reset: Date.now() + (this.maxTokens - this.tokens) / this.refillRate, }; } return { allowed: false, remaining: Math.floor(this.tokens), reset: Date.now() + (count - this.tokens) / this.refillRate, }; } /** * Refill tokens based on time elapsed */ refill() { const now = Date.now(); const elapsed = now - this.lastRefill; const tokensToAdd = elapsed * this.refillRate; this.tokens = Math.min(this.maxTokens, this.tokens + tokensToAdd); this.lastRefill = now; } } //# sourceMappingURL=rate-limiter.js.map