{"record":{"id":"70ffa1f8ec1ffe57","repo":"BerriAI/litellm","slug":"mcp-server-server-id-not-found-70ffa1","errorCode":null,"errorMessage":"MCP server {server_id} not found","messagePattern":"MCP server (.+?) not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"litellm/proxy/management_endpoints/mcp_management_endpoints.py","lineNumber":1794,"sourceCode":"\n    async def _get_cached_temporary_mcp_server_or_404(\n        server_id: str,\n        user_api_key_dict: UserAPIKeyAuth,\n        request: Request | None = None,\n    ) -> MCPServer:\n        server = await get_cached_temporary_mcp_server(server_id)\n        resolved_from_temp_cache: Final = server is not None\n        if server is None:\n            # Fall back to real DB/config server (e.g. for the user-side OAuth flow\n            # which calls these endpoints with a real server_id, not a temp session id).\n            from litellm.proxy.auth.ip_address_utils import IPAddressUtils\n\n            client_ip: Final = IPAddressUtils.get_mcp_client_ip(request) if request else None\n            server = global_mcp_server_manager.get_mcp_server_by_id(\n                server_id\n            ) or global_mcp_server_manager.get_mcp_server_by_name(server_id, client_ip=client_ip)\n        if server is None:\n            raise HTTPException(\n                status_code=status.HTTP_404_NOT_FOUND,\n                detail={\"error\": f\"MCP server {server_id} not found\"},\n            )\n\n        # Per-server access policy mirrors `fetch_mcp_server`: admin-view\n        # callers are unrestricted; non-admins must have the server in their\n        # allowed-servers set. Temporary cached servers come from the\n        # admin-only `/server/oauth/session` setup flow and are not exposed\n        # to non-admins.\n        if not _user_has_admin_view(user_api_key_dict):\n            if resolved_from_temp_cache:\n                raise HTTPException(\n                    status_code=status.HTTP_403_FORBIDDEN,\n                    detail={\"error\": f\"Access denied to MCP server {server_id}\"},\n                )\n            allowed_server_ids: Final[set[str]] = set()\n            for auth_context in await build_effective_auth_contexts(user_api_key_dict):\n                allowed_server_ids.update(await global_mcp_server_manager.get_allowed_mcp_servers(auth_context))","sourceCodeStart":1776,"sourceCodeEnd":1812,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/management_endpoints/mcp_management_endpoints.py#L1776-L1812","documentation":"Returned (404) by the shared OAuth helper used by the /server/oauth/{server_id}/... browser endpoints (authorize, token, callback) when the id resolves nowhere: not in the temporary-server cache, not in the registry by id, and not in the registry by name. Temporary session servers live in Redis only for TEMPORARY_MCP_SERVER_TTL_SECONDS, so expiry is a first-class cause.","triggerScenarios":"Starting the OAuth authorize/token flow with a temp session server_id that already expired (TTL ~5 minutes elapsed between setup and authorize); using a server_id that was never created; typo'd id; server deleted between setup and use.","commonSituations":"Admin sets up an OAuth-connected MCP server, gets distracted, then completes the browser consent after the temp cache expired; browser tab left open on an authorize URL whose session id has since expired; mixing up the temp session id with the permanent server_id.","solutions":["If you were using a temporary session server, redo the OAuth session setup to mint a fresh temp id and complete the flow promptly.","For the user-side OAuth flow, pass the real (DB/config) server_id, which does not expire.","Double-check the id for typos and confirm the server still exists via the list endpoint."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"resp = requests.get(f\"{PROXY}/v1/mcp/server\", headers=AUTH)\nids = {s[\"server_id\"] for s in resp.json()[\"servers\"]}\n# temp session ids are admin-flow artifacts; verify freshness before use\nif server_id not in ids and not server_id.startswith(\"temp-\"):\n    raise ValueError(f\"unknown server id: {server_id}\")","typeGuard":null,"tryCatchPattern":"try:\n    authorize(server_id)\nexcept HTTPError as e:\n    if e.response.status_code == 404:\n        session = create_oauth_session()  # mint a fresh temp id (TTL ~5 min)\n        authorize(session[\"server_id\"])\n    else:\n        raise","preventionTips":["Complete OAuth setup promptly after creating a temp session (TTL is ~5 minutes).","Use the permanent server_id for user-side OAuth flows."],"tags":["litellm","mcp","oauth","not-found","session-expiry"],"backgroundTag":"resource-not-found","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}