Skip to main content
Glama

Google Ads MCP Server

by martechery
rate-limiter.ts1.07 kB
export class TokenBucket { private tokens: number; private lastRefill: number; private readonly capacity: number; private readonly refillRate: number; // tokens per second constructor(capacity: number, refillRate: number) { this.capacity = Math.max(0, capacity | 0); this.refillRate = Math.max(0, refillRate); this.tokens = this.capacity; this.lastRefill = Date.now(); } consume(count = 1): boolean { this.refill(); if (this.tokens >= count) { this.tokens -= count; return true; } return false; } private refill(): void { const now = Date.now(); const elapsedSec = (now - this.lastRefill) / 1000; if (elapsedSec <= 0) return; const tokensToAdd = elapsedSec * this.refillRate; this.tokens = Math.min(this.capacity, this.tokens + tokensToAdd); this.lastRefill = now; } getRetryAfter(): number { this.refill(); const tokensNeeded = 1 - this.tokens; if (tokensNeeded <= 0 || this.refillRate <= 0) return 0; return Math.ceil(tokensNeeded / this.refillRate); } }

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/martechery/mcp-google-ads-ts'

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