{"record":{"id":"64ecb6ac52bd4b2d","repo":"BerriAI/litellm","slug":"oauth2-token-response-for-mcp-server-server-serv","errorCode":null,"errorMessage":"OAuth2 token response for MCP server '{server.server_id}' returned non-object JSON (got {type(body).__name__})","messagePattern":"OAuth2 token response for MCP server '(.+?)' returned non-object JSON \\(got (.+?)\\)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/proxy/_experimental/mcp_server/oauth2_token_cache.py","lineNumber":160,"sourceCode":"\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\")\n        try:\n            expires_in = int(raw_expires_in) if raw_expires_in is not None else MCP_OAUTH2_TOKEN_CACHE_DEFAULT_TTL\n        except (TypeError, ValueError):\n            expires_in = MCP_OAUTH2_TOKEN_CACHE_DEFAULT_TTL\n\n        ttl: Final = max(\n            expires_in - MCP_OAUTH2_TOKEN_EXPIRY_BUFFER_SECONDS,\n            MCP_OAUTH2_TOKEN_CACHE_MIN_TTL,","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/_experimental/mcp_server/oauth2_token_cache.py#L142-L178","documentation":"The client-credentials token endpoint returned 2xx but response.json() parsed to a non-dict (list, string, number). It is a malformed-upstream-response type check; the cached-token path refuses to index into it and raises instead.","triggerScenarios":"Thrown at litellm/proxy/_experimental/mcp_server/oauth2_token_cache.py:160 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the upstream token endpoint; it must return a JSON object.","Log the raw response to diagnose."],"exampleFix":"Inspect token endpoint response body.","handlingStrategy":"type-guard","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"}