{"record":{"id":"c38b354e7b0142d1","repo":"BerriAI/litellm","slug":"oauth2-token-request-for-mcp-server-server-serve","errorCode":null,"errorMessage":"OAuth2 token request for MCP server '{server.server_id}' failed with status {exc.response.status_code}","messagePattern":"OAuth2 token request for MCP server '(.+?)' failed with status (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/proxy/_experimental/mcp_server/oauth2_token_cache.py","lineNumber":152,"sourceCode":"            client_secret=server.client_secret,\n        )\n        data: Final[dict[str, str]] = {\n            \"grant_type\": \"client_credentials\",\n            **token_request.body,\n        }\n        if server.scopes:\n            data[\"scope\"] = \" \".join(server.scopes)\n\n        verbose_logger.debug(\n            \"Fetching OAuth2 client_credentials token for MCP server %s\",\n            server.server_id,\n        )\n\n        try:\n            response: Final = await client.post(server.token_url, data=data, headers=token_request.headers or None)\n            response.raise_for_status()\n        except httpx.HTTPStatusError as exc:\n            raise ValueError(\n                f\"OAuth2 token request for MCP server '{server.server_id}' \"\n                f\"failed with status {exc.response.status_code}\"\n            ) from exc\n\n        body: Final = response.json()\n\n        if not isinstance(body, dict):\n            raise ValueError(\n                f\"OAuth2 token response for MCP server '{server.server_id}' \"\n                f\"returned non-object JSON (got {type(body).__name__})\"\n            )\n\n        access_token: Final = body.get(\"access_token\")\n        if not access_token:\n            raise ValueError(f\"OAuth2 token response for MCP server '{server.server_id}' missing 'access_token'\")\n\n        # Safely parse expires_in — providers may return null or non-numeric values\n        raw_expires_in: Final = body.get(\"expires_in\")","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/_experimental/mcp_server/oauth2_token_cache.py#L134-L170","documentation":"Raised when the OAuth2 client_credentials token POST to an MCP server's token_url returns an HTTP error status; the server_id and upstream status are embedded. Fires on bad client_id/secret or an unreachable identity provider.","triggerScenarios":"Thrown at litellm/proxy/_experimental/mcp_server/oauth2_token_cache.py:152 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify client credentials and token_url; check the upstream error body for the status code."],"exampleFix":"Test the token request manually with curl.","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}