{"record":{"id":"dfe531cbf01bed67","repo":"PrefectHQ/fastmcp","slug":"global-rate-limit-exceeded","errorCode":null,"errorMessage":"Global rate limit exceeded","messagePattern":"Global rate limit exceeded","errorType":"exception","errorClass":"RateLimitError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/server/middleware/rate_limiting.py","lineNumber":164,"sourceCode":"                self.burst_capacity, self.max_requests_per_second\n            )\n\n    async def _get_client_identifier(self, context: MiddlewareContext) -> str:\n        \"\"\"Get client identifier for rate limiting.\"\"\"\n        if self.get_client_id:\n            client_id = self.get_client_id(context)\n            if inspect.isawaitable(client_id):\n                return cast(str, await client_id)\n            return client_id\n        return \"global\"\n\n    async def on_request(self, context: MiddlewareContext, call_next: CallNext) -> Any:\n        \"\"\"Apply rate limiting to requests.\"\"\"\n        if self.global_limit:\n            # Global rate limiting\n            allowed = await self.global_limiter.consume()\n            if not allowed:\n                raise RateLimitError(\"Global rate limit exceeded\")\n        else:\n            # Per-client rate limiting\n            client_id = await self._get_client_identifier(context)\n            limiter = self.limiters[client_id]\n            allowed = await limiter.consume()\n            if not allowed:\n                raise RateLimitError(f\"Rate limit exceeded for client: {client_id}\")\n\n        return await call_next(context)\n\n\nclass SlidingWindowRateLimitingMiddleware(Middleware):\n    \"\"\"Middleware that implements sliding window rate limiting.\n\n    Uses a sliding window approach which provides more precise rate limiting\n    but uses more memory to track individual request timestamps.\n\n    Example:","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/server/middleware/rate_limiting.py#L146-L182","documentation":"Raised as RateLimitError by RateLimitingMiddleware.on_request when the global token-bucket limiter's consume() returns False, meaning the server-wide request budget for the current window is exhausted. This applies to all clients collectively, not one caller.","triggerScenarios":"RateLimitingMiddleware(max_requests=N, window_seconds=W) configured without per-client limits, and more than N requests arrive within any W-second window regardless of source.","commonSituations":"Load tests or bursts of traffic exceeding a conservative global cap; multiple services sharing one FastMCP server; window_seconds set far below actual traffic volume.","solutions":["Raise max_requests or window_seconds to match legitimate traffic volume.","Switch to per-client limiting (omit global_limit) so one noisy client cannot starve everyone.","Add client-side retry with backoff honoring the rate-limit response before resuming."],"exampleFix":"// before\nmw = RateLimitingMiddleware(max_requests=100, window_seconds=60)\n\n// after: scale the cap to observed traffic, or go per-client\nmw = RateLimitingMiddleware(max_requests=5000, window_seconds=60)\n# or per-client mode:\nmw = RateLimitingMiddleware(max_requests=100, window_seconds=60, global_limit=False)","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"import anyio\nfor attempt in range(5):\n    try:\n        result = await client.call_tool(name, args)\n        break\n    except Exception as e:\n        if \"Global rate limit exceeded\" in str(e) and attempt < 4:\n            await anyio.sleep(2 ** attempt)\n            continue\n        raise","preventionTips":["Size max_requests/window_seconds from measured peak throughput, not guesses.","Load-test against the configured global cap before production.","Prefer per-client limiting so one consumer cannot exhaust the shared budget.","Spread scheduled bulk jobs across time instead of bursting."],"tags":["rate-limiting","middleware","traffic"],"backgroundTag":"rate-limit-exceeded","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}