{"record":{"id":"c3f42aa244fe7ede","repo":"BerriAI/litellm","slug":"error-caching-temporary-mcp-server-e","errorCode":null,"errorMessage":"Error caching temporary mcp server: {e}","messagePattern":"Error caching temporary mcp server: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"litellm/proxy/management_endpoints/mcp_management_endpoints.py","lineNumber":1670,"sourceCode":"                temp_record,\n                credentials_are_encrypted=False,\n            )\n            _cache_temporary_mcp_server(\n                temporary_server,\n                ttl_seconds=TEMPORARY_MCP_SERVER_TTL_SECONDS,\n            )\n            await _persist_draft_mcp_server(\n                payload_with_credentials,\n                temp_record.server_id,\n                created_by,\n            )\n            await _cache_temporary_mcp_server_in_redis(\n                temporary_server,\n                ttl_seconds=TEMPORARY_MCP_SERVER_TTL_SECONDS,\n            )\n        except Exception as e:\n            verbose_proxy_logger.exception(\"Error caching temporary mcp server: %s\", e)\n            raise HTTPException(\n                status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,\n                detail={\"error\": f\"Error caching temporary mcp server: {e}\"},\n            )\n\n        return _redact_mcp_credentials(temp_record)\n\n    async def _mcp_oauth_user_api_key_auth(request: Request) -> UserAPIKeyAuth:\n        \"\"\"\n        Auth dependency for MCP OAuth browser-navigation endpoints (/authorize, /token).\n\n        Tries the Authorization header first. Falls back to decoding the UI\n        'token' session cookie (set by SSO login) to extract the API key, which\n        allows browser-based OAuth redirects to work without an explicit\n        Authorization header.\n        \"\"\"\n        import jwt as _jwt\n\n        from litellm.proxy.proxy_server import master_key","sourceCodeStart":1652,"sourceCodeEnd":1688,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/management_endpoints/mcp_management_endpoints.py#L1652-L1688","documentation":"Returned (500) when the temporary-server setup block fails: either _persist_draft_mcp_server (DB write of the draft row) or _cache_temporary_mcp_server_in_redis (Redis write with TEMPORARY_MCP_SERVER_TTL_SECONDS). The original exception is logged via verbose_proxy_logger.exception, then surfaced as this generic 500; nothing usable is returned to the caller.","triggerScenarios":"Running the admin MCP OAuth session flow while Redis is down or redis_url is not configured on the proxy; the draft DB write failing (DB down, schema drift); values in the payload failing serialization on the way into the cache.","commonSituations":"Proxy deployed without the Redis instance that temporary MCP server caching requires; Redis restarted or evicting mid-flow; DB outage during OAuth setup.","solutions":["Check the proxy logs for the wrapped exception's traceback to see which leg failed (draft persist vs Redis cache).","Verify the proxy's Redis connection (redis_url) and that Redis is reachable.","Verify DB connectivity/migrations if the draft persist is the failing call.","Retry the session flow once infrastructure is healthy; temp entries are TTL-scoped so partial state ages out."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"try:\n    import redis\n    redis.Redis.from_url(REDIS_URL).ping()\nexcept Exception as e:\n    raise RuntimeError(f\"Redis unavailable; temp MCP server flow will 500: {e}\")","typeGuard":null,"tryCatchPattern":"for attempt in range(2):\n    try:\n        return create_temp_session(payload)\n    except HTTPError as e:\n        if e.response.status_code == 500 and attempt == 0:\n            sleep(2)\n            continue  # transient Redis/DB hiccup; temp entries are TTL-scoped so retry is safe\n        raise","preventionTips":["Deploy Redis and set redis_url before using OAuth session flows.","Check proxy logs to distinguish draft-persist failure from Redis-cache failure.","Retry only after confirming infra health; persistent 500s mean config, not flake."],"tags":["litellm","mcp","redis","cache","oauth","internal-error"],"backgroundTag":"cache-write-failed","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}