6 views
-/https://github.com/berriai/litellm/issues/29261
GitHub · issue

#29261 [Bug]: Interactive OAuth2 MCP server returns 500 instead of 401+WWW-Authenticate when x-litellm-api-key is present but no Google OAuth token exists yet

  • State: open
  • Author: @joelstucki-taulia
  • Labels: claude code

## Description

When an MCP server is configured with `auth_type: oauth2`, `authorization_url`, and `token_url` (interactive PKCE flow — NOT `delegate_auth_to_upstream`), sending a request with **only** `x-litellm-api-key` (valid LiteLLM key, no `Authorization` header) returns **HTTP 500** instead of a clean **HTTP 401 + `WWW-Authenticate`** header.

This prevents MCP clients (OpenCode, Claude Code) from initiating the OAuth browser flow, because they need a clean 401 with the `authorization_uri` to discover the authorize endpoint. Instead they receive a 500 and fail with `"Error POSTing to endpoint: {"error":"MCP request failed","details":""}"`.

## LiteLLM Version

`1.85.0` (Docker image `docker.io/litellm/litellm:1.85.0`)

## Configuration

```yaml mcp_servers: Gmail: url: "https://gmailmcp.googleapis.com/mcp/v1" transport: "http" auth_type: "oauth2" client_id: "<google-oauth-client-id>" client_secret: "<google-oauth-client-secret>" authorization_url: "https://accounts.google.com/o/oauth2/v2/auth" token_url: "https://oauth2.googleapis.com/token" scopes: - "https://www.googleapis.com/auth/gmail.modify" - "https://www.googleapis.com/au…

GitHub resolver

Import GitHub neighbors on demand. Results are saved as system ingests.

Refresh page
vote history (4 events)
#0 of 0 · 31d18h34m41s ago — entered · #import:https:::github.com:berriai:litellm post #2304
The right issue spans shared persistence, batching, retries, and multiple spend dimensions, requiring broader regression coverage and greater data-integrity risk. The left is narrower, primarily involving authentication error mapping and response headers.
OAuth/MCP authentication behavior spans middleware, protocol-specific challenge headers, and interactive-flow compatibility, creating greater integration and regression risk; the logging change is comparatively localized to logger filtering/configuration.
The right issue is harder because it requires tracing and correcting authentication middleware behavior across MCP request handling, OAuth challenge generation, error mapping, and client compatibility, with integration and regression testing. The left issue is a bounded metadata update affecting static pricing/context records with straightforward validation.
#0 of 0 · 31d17h44m6s ago — current · #import:https:::github.com:berriai:litellm post #3154
Model omitted braces; inferred difficulty from issue scope and surface area.
discussed in #import:https:::github.com:berriai:litellm

ranked child groups

no voted pairs yet in this scope

cli
src
spread
search