Remote MCP Rate Limit And Audit Export Design
Goal
Protect remote MCP/SSE deployments with session-scoped request rate limiting and append-only audit export.
Scope
This slice applies only to remote HTTP/SSE transport. Stdio remains unchanged. The limiter is in-memory and process-local. Distributed/shared rate limiting is outside this slice.
Architecture
Remote requests already flow through MCPTransportAuth.authorize() before /sse and /messages/ continue. The new design keeps that boundary:
- authenticate headers and resolve a remote session ID;
- apply a session-first fixed-window rate limiter;
- export a compact audit JSONL record for allowed, auth-denied, and rate-limited requests;
- return
401for auth/session failures and429for rate-limit failures.
The rate-limit key is the validated remote session ID. If a request cannot produce a session ID, the client host may be used only for audit context, not as the primary tenant boundary.
Configuration
MCP_RATE_LIMIT_ENABLED: defaulttrueMCP_RATE_LIMIT_REQUESTS: default120MCP_RATE_LIMIT_WINDOW_SECONDS: default60MCP_AUDIT_ENABLED: defaultfalseMCP_AUDIT_PATH: default.eventloom/remote_audit.jsonl
Data
Audit records are newline-delimited JSON with:
- timestamp
- session_id when known
- route
- method
- outcome:
allowed,denied_auth, ordenied_rate_limit - reason
- client_host when available
No bearer tokens, JWTs, raw payloads, or query text are exported.
Tests
Unit tests cover limiter allow/deny behavior, window reset, audit JSONL export, and disabled audit no-op behavior. MCP tests cover request authorization paths returning 429 after a configured limit and writing audit records for allowed and denied requests.