BerriAI/litellm · error · ValueError

OAuth2 token request for MCP server '{server.server_id}' fai

Error message

OAuth2 token request for MCP server '{server.server_id}' failed with status {exc.response.status_code}

What it means

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.

Source

Thrown at litellm/proxy/_experimental/mcp_server/oauth2_token_cache.py:152

            client_secret=server.client_secret,
        )
        data: Final[dict[str, str]] = {
            "grant_type": "client_credentials",
            **token_request.body,
        }
        if server.scopes:
            data["scope"] = " ".join(server.scopes)

        verbose_logger.debug(
            "Fetching OAuth2 client_credentials token for MCP server %s",
            server.server_id,
        )

        try:
            response: Final = await client.post(server.token_url, data=data, headers=token_request.headers or None)
            response.raise_for_status()
        except httpx.HTTPStatusError as exc:
            raise ValueError(
                f"OAuth2 token request for MCP server '{server.server_id}' "
                f"failed with status {exc.response.status_code}"
            ) from exc

        body: Final = response.json()

        if not isinstance(body, dict):
            raise ValueError(
                f"OAuth2 token response for MCP server '{server.server_id}' "
                f"returned non-object JSON (got {type(body).__name__})"
            )

        access_token: Final = body.get("access_token")
        if not access_token:
            raise ValueError(f"OAuth2 token response for MCP server '{server.server_id}' missing 'access_token'")

        # Safely parse expires_in — providers may return null or non-numeric values
        raw_expires_in: Final = body.get("expires_in")

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Verify client credentials and token_url; check the upstream error body for the status code.

Example fix

Test the token request manually with curl.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at litellm/proxy/_experimental/mcp_server/oauth2_token_cache.py:152 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/c38b354e7b0142d1. Report an issue: GitHub.