litellm/tests/test_litellm/proxy
Ishaan Jaff f5e5d17e4a
fix(mcp): fix OpenAPI OAuth flow — transport mapping, error messages, and discovery bypass (#23315)
* fix(mcp): fix OpenAPI OAuth flow — transport mapping, error messages, and discovery bypass

Three bugs fixed to make the end-to-end OAuth flow work for OpenAPI MCP servers:

1. **Transport mapping in getTemporaryPayload**: `TRANSPORT.OPENAPI` is a UI-only concept;
   the backend only accepts `"http"`, `"sse"`, or `"stdio"`. The pre-OAuth temp-session
   call was sending `transport: "openapi"` and getting a 422. Fixed by mapping to `"http"`.

2. **deriveErrorMessage handles FastAPI 422 arrays**: FastAPI validation errors return
   `detail` as an array of `{loc, msg, type}` objects. The shared error extractor was
   returning the array directly, causing `Error: [object Object]`. Fixed to map each
   item to its `.msg` field.

3. **Skip OAuth discovery when authorization_url already provided**: `build_mcp_server_from_table`
   was unconditionally calling `_descovery_metadata(server_url)` for OAuth servers. For
   OpenAPI servers the url is the spec JSON file, not the API base — this caused a timeout
   fetching e.g. the GitHub spec (2 MB). Fixed by skipping discovery when `authorization_url`
   is already set.

Also: collapsible auth section in MCP server form, "Create OAuth App →" link next to
Client ID when a docs URL is available (e.g. GitHub OAuth App creation page), and
`extractErrorMessage` helper in `useMcpOAuthFlow` for cleaner error display.

* refactor(mcp): extract needs_discovery flag and reduceStaticHeaders helper

* feat(mcp): user OAuth connect flow — OAuthConnectModal, MCPCredentialsTab, useUserMcpOAuthFlow

Adds the user-facing MCP OAuth2 PKCE connect flow:

- OAuthConnectModal: modal that launches the PKCE flow for a user to connect to an MCP server
- MCPCredentialsTab: credentials management tab in the MCP apps panel
- useUserMcpOAuthFlow: hook that handles the full PKCE auth code exchange for user-level connections
- MCPAppsPanel: wires up the new credentials tab and connect modal
- ChatPage: further cleanup after responses-API revert
- db.py / mcp_management_endpoints.py / _types.py: backend support for storing user MCP credentials

* fix(mcp): make client_id optional in /authorize — use server's stored client_id when not provided

* address greptile review feedback

* fix(mcp): narrow bare except to RecordNotFoundError in BYOK credential delete

* refactor(mcp): move inline imports to module level in db.py

* docs(claude): add MCP OAuth, transport mapping, and browser storage patterns

* fix(security): remove accessToken from sessionStorage in OAuth flow state

The LiteLLM API key was being serialised into sessionStorage as part of
StoredFlowState. After the OAuth redirect the component re-mounts with the
same accessToken prop, so it never needed to be stored. Read it from props
in resumeOAuthFlow instead.

* fix(ui): remove duplicate extractErrorMessage, sessionStorage-only in admin OAuth hook, call delete API on disconnect

* fix(ui): guard resumeOAuthFlow against wrong hook instance consuming OAuth result

* fix(ui): separate OAuth result keys per flow, sessionStorage-only, surface revoke errors

* fix(ui): remove dead OAuthConnectModal, revert tsconfig jsx mode to preserve

* fix(mcp): guard BYOK overwrite in oauth credential store, raise clear error when client_id absent

* fix: forward OAuth error params in callback, fix BYOK guard exception handling in db.py
2026-03-11 16:16:08 -07:00
..
_experimental/mcp_server feat(mcp): add AWS SigV4 auth support in UI and fix credential merge on edit (#23282) 2026-03-11 09:43:28 -07:00
agent_endpoints fix(tests): restore litellm_params=None on mock agent in a2a invoke test (#23125) 2026-03-09 07:16:02 -07:00
anthropic_endpoints
auth Revert "feat: add model_cost aliases expansion support" 2026-03-10 22:39:19 -03:00
client
common_utils Merge pull request #20688 from BerriAI/litellm_budget_tier_enforcement_for_keys 2026-03-06 20:44:58 -08:00
db Revert "feat(proxy): add Prisma DB pool and engine health metrics to Promethe…" 2026-03-09 14:55:11 -07:00
discovery_endpoints Support auto_redirect_ui_login_to_sso in config.yaml general_settings 2026-03-11 11:34:17 -07:00
experimental/mcp_server
google_endpoints
guardrails Merge branch 'main' into litellm_oss_staging_03_10_2026 2026-03-11 18:32:17 +05:30
health_endpoints Prisma DB Failure Detection and Self-Healing (#21059) 2026-03-05 13:44:49 -08:00
hooks Agents - add max budget + tpm/rpm limiting per agent AND per agent session (#22849) 2026-03-07 19:12:42 -08:00
image_endpoints
management_endpoints fix(mcp): fix OpenAPI OAuth flow — transport mapping, error messages, and discovery bypass (#23315) 2026-03-11 16:16:08 -07:00
management_helpers Fix mcp_tool_permissions JSON string deserialization in _resolve_team_allowed_mcp_servers 2026-03-11 00:23:40 -07:00
middleware feat: add in_flight_requests metric to /health/backlog + prometheus (#22319) 2026-02-27 18:00:50 -08:00
openai_files_endpoint CircleCI test stability (#23055) 2026-03-07 15:19:39 -08:00
pass_through_endpoints fix(proxy): preserve multipart/form-data boundary in passthrough endpoints 2026-03-11 16:52:02 +05:30
policy_engine
prompts
public_endpoints [Feature] Add /public/endpoints endpoint for provider endpoint support 2026-02-26 18:17:37 -08:00
rag_endpoints
response_api_endpoints
spend_tracking Fix TypeError in _is_master_key when api_key is None 2026-03-11 11:01:29 -07:00
test_configs
ui_crud_endpoints [Fix] PATCH /update/ui_settings now merges with existing record instead of overwriting 2026-03-05 15:49:40 -08:00
vector_store_endpoints
__init__.py
conftest.py
test_aiohttp_cleanup_closed.py
test_api_key_masking_in_errors.py
test_audio_speech_prometheus_hooks.py fix req changes 2026-02-28 21:32:57 +05:30
test_batch_expiry.py fix(proxy): improve team expiry enforcement validation 2026-03-03 17:29:39 -08:00
test_batch_metadata_none_fix.py
test_caching_routes.py
test_chat_completion_metadata.py
test_common_request_processing.py Bug Fix: auto-inject prompt caching support for Gemini models (#21881) 2026-03-03 20:25:35 -08:00
test_custom_proxy.py
test_empty_model_list.py [Release Fix] (#22411) 2026-02-28 09:46:35 -08:00
test_enforce_user_param.py
test_fallback_management_endpoints.py
test_fastapi_offline_routes.py
test_health_check_functions.py
test_health_check_max_tokens.py add docs and formatting 2026-02-28 14:08:09 +05:30
test_litellm_pre_call_utils.py Bug Fix: auto-inject prompt caching support for Gemini models (#21881) 2026-03-03 20:25:35 -08:00
test_model_dump_with_preserved_fields.py
test_model_id_header_propagation.py
test_prometheus_cleanup.py Add Prometheus child_exit cleanup for gunicorn workers 2026-02-27 16:11:15 -08:00
test_proxy_cli.py test: assert setup_database called with correct args 2026-03-10 18:31:04 +05:30
test_proxy_server.py Fix inflight mypy 2026-03-02 19:41:32 +05:30
test_proxy_types.py fix: Add PROXY_ADMIN role to system user for key rotation (#21896) 2026-02-27 19:11:29 -08:00
test_proxy_utils.py [Feat[ extends OAuth2 M2M authentication support to info routes (/key/info, /team/info, /user/info, /model/info) (#22713) 2026-03-06 17:29:25 -08:00
test_pyroscope.py
test_response_model_sanitization.py
test_route_a2a_models.py
test_route_llm_request.py
test_shared_health_check.py
test_spend_log_cleanup.py Fix spend log cleanup: lock tracking, integer retention, skip log level 2026-03-03 10:12:08 -08:00
test_swagger_chat_completions.py [Release Fix] (#22411) 2026-02-28 09:46:35 -08:00
test_team_member_update.py
test_tools_allowlist_enforcement.py Bug Fix: auto-inject prompt caching support for Gemini models (#21881) 2026-03-03 20:25:35 -08:00
test_update_llm_router_resilience.py