## User Story **As a** cluster admin, **I want to** configure global rate limits on MCPServer, **so that** total throughput stays within safe bounds for downstream services. ## Context See [THV-0057: Rate Limiting for MCP Servers](https://github.com/stacklok/toolhive-rfcs/blob/main/rfcs/THV-0057-rate-limiting.md) for full design details. ## Acceptance Criteria - [ ] `MCPServerSpec` includes a `rateLimiting.global` field with `maxTokens` and `refillPeriod` - [ ] Per-tool global limits supported via `rateLimiting.tools[].global` - [ ] Unit: Total requests across all users exceed `maxTokens` — next request is rejected with JSON-RPC error `-32029` - [ ] Unit: `Retry-After` is computed from the global bucket's refill rate - [ ] Unit: Per-tool global limit hit on one tool doesn't affect other tools - [ ] Unit: Request must pass both server-level global and per-tool global limits - [ ] E2E: Deploy MCPServer with `global` rate limit, send traffic from multiple users, verify rejection after global limit exceeded - [ ] E2E: Deploy MCPServer with both `global` and `perUser` — request must pass both ## Out of Scope - Per-user rate limits (STORY-001) - VirtualMCPServer (STORY-003) - Observability (STORY-004)
Activity
Add rate limiting types to MCPServerSpec
Add token-bucket rate limiter package with tests
Add token-bucket rate limiter package with tests
Add rate limiting types to MCPServerSpec
Add token-bucket rate limiter package with tests
Add rate limiting types to MCPServerSpec
Add token-bucket rate limiter package with tests
Add rate limiting types to MCPServerSpec
Add token-bucket rate limiter package with tests
Add rate limiting types to MCPServerSpec
24 remaining items
Add E2E acceptance tests for rate limiting
Add rate limit HTTP middleware with error helpers
Wire rate limit middleware into proxy runner chain
Add E2E acceptance tests for rate limiting
Add rate limit HTTP middleware with error helpers
Wire rate limit middleware into proxy runner chain
Add E2E acceptance tests for rate limiting
Add rate limit HTTP middleware with error helpers
Wire rate limit middleware into proxy runner chain
Add E2E acceptance tests for rate limiting
Add rate limit HTTP middleware with error helpers
Wire rate limit middleware into proxy runner chain
Add E2E acceptance tests for rate limiting
Wire rate limit middleware into proxy runner chain (#4652)