Skip to main content
Glama
haasonsaas
by haasonsaas

rate_limit_check

Check if an operation should be rate-limited by evaluating request counts against defined thresholds for specific resources.

Instructions

Check if an operation should be rate-limited

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
resourceYesResource identifier (e.g., 'api.github.com')
max_requestsNoMaximum requests allowed
window_secondsNoTime window in seconds
incrementNoIncrement the counter if allowed

Implementation Reference

  • The main handler function for the 'rate_limit_check' tool. It checks if a request for a given resource is within rate limits, optionally increments the counter, and returns status including remaining requests and reset time.
    case "rate_limit_check": { const { resource, max_requests = 60, window_seconds = 60, increment = true } = args as any; const now = Date.now(); const windowMs = window_seconds * 1000; let limit = rateLimits.get(resource); // Initialize or reset if window expired if (!limit || limit.resetAt <= now) { limit = { count: 0, resetAt: now + windowMs }; rateLimits.set(resource, limit); } const allowed = limit.count < max_requests; const remaining = Math.max(0, max_requests - limit.count); const resetIn = Math.ceil((limit.resetAt - now) / 1000); if (allowed && increment) { limit.count++; } return { content: [{ type: "text", text: JSON.stringify({ allowed, resource, current_count: limit.count, max_requests, remaining, reset_in_seconds: resetIn, reset_at: new Date(limit.resetAt).toISOString() }) }] }; }
  • The tool specification including name, description, and input schema for 'rate_limit_check', which defines the expected input parameters and validation.
    { name: "rate_limit_check", description: "Check if an operation should be rate-limited", inputSchema: { type: "object", properties: { resource: { type: "string", description: "Resource identifier (e.g., 'api.github.com')" }, max_requests: { type: "number", description: "Maximum requests allowed", default: 60 }, window_seconds: { type: "number", description: "Time window in seconds", default: 60 }, increment: { type: "boolean", description: "Increment the counter if allowed", default: true } }, required: ["resource"] } }
  • Global storage Map for rate limit counters per resource, essential for tracking usage across tool calls.
    // Rate limiting storage const rateLimits = new Map<string, { count: number; resetAt: number }>();

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/haasonsaas/mcp-utility-tools'

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