Repository navigation
fix(proxy): share temporary MCP OAuth sessions across instances via Redis - #26162
milan-berri wants to merge 6 commits into
Conversation
Share temporary MCP server session state across proxy instances via Redis with in-memory fallback, and extend MCP management endpoint tests to cover async cache lookup/write behavior. Made-with: Cursor
Greptile SummaryThis PR fixes MCP OAuth session lookup failures in multi-instance/load-balanced proxy deployments by persisting temporary session records to Redis (encrypted) in addition to the existing process-local in-memory cache. OAuth endpoints ( Confidence Score: 5/5Safe to merge; the single remaining finding is a minor P2 hardening gap in a best-effort helper. All identified issues are P2 (style/defensive hardening). The prior P1 concerns raised in earlier reviews — TTL re-inflation and assert_called_once_with vs assert_awaited_once_with — have been fully addressed. The core logic (encryption, Redis fallback, async conversion) is correct. The
|
| Filename | Overview |
|---|---|
| litellm/proxy/management_endpoints/mcp_management_endpoints.py | Adds Redis-backed L2 cache for temporary MCP OAuth sessions; encryption/decryption, TTL handling, and async conversion are correct, with one minor gap where model_dump/json.dumps in a best-effort helper are not wrapped. |
| tests/test_litellm/proxy/management_endpoints/test_mcp_management_endpoints.py | New tests cover Redis write/read, encryption/decryption, TTL, and fallback paths; all async mock assertions correctly use assert_awaited_once_with. |
Sequence Diagram
sequenceDiagram
participant Client
participant Instance1 as Proxy Instance 1
participant Instance2 as Proxy Instance 2
participant Redis
participant Memory as In-Memory Cache
Client->>Instance1: POST /v1/mcp/server/oauth/session
Instance1->>Memory: _cache_temporary_mcp_server(server, TTL=300s)
Instance1->>Redis: _cache_temporary_mcp_server_in_redis(encrypted, TTL=300s)
Instance1-->>Client: 200 OK (credentials redacted)
Client->>Instance2: GET /server/oauth/{server_id}/authorize
Instance2->>Memory: get_cached_temporary_mcp_server(server_id) → miss
Instance2->>Redis: _get_temporary_mcp_server_from_redis(server_id) → hit
Note over Instance2,Redis: Decrypts payload, returns MCPServer (no L1 repopulation)
Instance2-->>Client: Redirect to authorization URL
Reviews (6): Last reviewed commit: "fix(mcp): require encrypted string for t..." | Re-trigger Greptile
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Avoid extending temporary MCP session lifetime on Redis cache hits by skipping local repopulation, and tighten async test assertion semantics with assert_awaited_once_with. Made-with: Cursor
There was a problem hiding this comment.
Medium: Plaintext secrets written to Redis
This PR shares temporary MCP OAuth sessions across proxy instances by writing the full MCPServer object to Redis. The MCPServer model includes sensitive fields (client_secret, authentication_token, aws_secret_access_key, aws_session_token) that are stored as plaintext JSON in Redis after decryption.
Use existing proxy encrypt/decrypt helpers for temporary MCP session payloads in Redis, keep best-effort cache behavior on crypto failures, and add tests for encrypted write/decrypt read paths. Made-with: Cursor
Apply Black-required line wrapping to satisfy formatting checks. Made-with: Cursor
Made-with: Cursor
Made-with: Cursor
|
re-opened it here #26318 with conflicts resolved and CI run |
…is (#26162) (#26318) Temporary MCP OAuth sessions were kept in process-local memory, so on multi-instance/LB proxy deployments a session created on instance A could not be found when the follow-up /server/oauth/{server_id}/... request landed on instance B. Persist temporary session records to Redis (encrypted with the existing proxy encryption helpers) as a best-effort L2 cache alongside the current in-memory L1. Convert get_cached_temporary_mcp_server to async and await it from the authorize/token/register OAuth endpoints. Made-with: Cursor
Relevant issues
Fixes temporary MCP OAuth session lookup failures in multi-instance/LB proxy deployments where
/v1/mcp/server/oauth/sessionis created on one instance and subsequent/server/oauth/{server_id}/...requests may land on another.Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/test_litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewCI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Screenshots / Proof of Fix
Targeted local test runs:
poetry run python -m pytest tests/test_litellm/proxy/management_endpoints/test_mcp_management_endpoints.py -v56 passedFocused path validation also covered temporary MCP OAuth handlers, Redis fallback logic, and encrypted Redis payload read/write paths in:
TestTemporaryMCPSessionEndpointsType
🐛 Bug Fix
✅ Test
Changes
authorize,token,register) to await them.