## User Story **As a** cluster admin, **I want to** configure per-user rate limits on MCPServer, **so that** no single user can monopolize a server's tools. ## 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.perUser` field with `maxTokens` and `refillPeriod` - [ ] Per-tool per-user limits supported via `rateLimiting.tools[].perUser` - [ ] CRD admission validation rejects `perUser` when auth is not enabled - [ ] CRD admission validation rejects `rateLimiting` when neither `global` nor `perUser` is set - [ ] Operator sets `RateLimitingConfigValid` status condition at reconciliation time - [ ] Unit: User exceeds `maxTokens` — next request is rejected with JSON-RPC error `-32029` and `retryAfterSeconds` - [ ] Unit: User A is rate-limited; User B's bucket is independent - [ ] Unit: Per-tool limit hit on `expensive_tool` doesn't affect `other_tool` - [ ] Unit: Request must pass both server-level per-user and per-tool per-user limits - [ ] Unit: Redis unavailable — request passes through (fail-open) - [ ] E2E: Deploy MCPServer with `perUser` rate limit, send traffic, verify rejection after limit exceeded - [ ] E2E: Streamable HTTP rejection returns HTTP 429 with `Retry-After` header - [ ] E2E: `kubectl apply` with `perUser` and no auth config is rejected at admission ## Out of Scope - Global rate limits (STORY-002) - VirtualMCPServer (STORY-003) - Observability beyond fail-open counter (STORY-004)
Activity
Add rate limiting types to MCPServerSpec
Add rate limiting types to MCPServerSpec
Add rate limiting CRD types and token-bucket package (#4577)
Add per-user rate limit CRD types and CEL validation
Add RateLimitConfigValid status condition to reconciler
Support per-user buckets in rate limiter
Add per-user rate limit CRD types and CEL validation
Add RateLimitConfigValid status condition to reconciler
Support per-user buckets in rate limiter
Add per-user rate limit types and limiter support (#4692)
Hoist mock OIDC server into testutil package
Wire authenticated identity into rate limit middleware
Add per-user rate limit E2E test with mock OIDC auth
Hoist mock OIDC server into testutil package
Wire authenticated identity into rate limit middleware
Add per-user rate limit E2E test with mock OIDC auth