cherry-pick: OpenAPI MCP extra_headers (#27383) onto litellm_1.84.0rc2#27768
Conversation
OpenAPI-generated tools only applied static closure headers and BYOK Authorization via ContextVar. Copy MCPServer.extra_headers from the incoming MCP request into _request_extra_headers (set in server.py before local tool dispatch), merge in openapi_to_mcp_generator via a small helper. OAuth2 M2M: do not forward caller Authorization from raw_headers (same rule as _prepare_mcp_server_headers for managed MCP). Adds TestRequestExtraHeaders and clarifies mcp_server_manager registration comment. Fixes BerriAI#26794 Co-authored-by: Cursor <cursoragent@cursor.com>
Greptile: getattr default was redundant; property exists on MCPServer and mcp_server is non-None inside the extra_headers forwarding block. Co-authored-by: Cursor <cursoragent@cursor.com>
Match the existing MCP invariant in merge_mcp_headers and the managed MCP path: operator-configured static headers always override caller-forwarded headers on name conflict, with case-insensitive comparison so different casing cannot bypass the precedence. _request_auth_header (BYOK) still overrides Authorization last. Addresses Veria review on PR BerriAI#27383. Co-authored-by: Mateo Wang <mateo-berri@users.noreply.github.com>
|
|
Greptile SummaryCherry-picks the OpenAPI MCP
Confidence Score: 5/5Safe to merge; all changes are scoped to the experimental OpenAPI MCP path with no impact on existing managed MCP or core request flows. The forwarding logic is well-guarded: ContextVars are always reset in No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/proxy/_experimental/mcp_server/openapi_to_mcp_generator.py | Adds _request_extra_headers ContextVar and _merge_openapi_tool_request_headers helper; replaces inline auth override with the new merge function inside create_tool_function. Precedence logic (BYOK auth > static > forwarded) is correct, case-insensitive conflict detection is properly implemented. |
| litellm/proxy/_experimental/mcp_server/server.py | Populates _request_extra_headers from MCPServer.extra_headers allowlist against raw_headers before dispatching to local OpenAPI tools; resets both ContextVars in a finally block. The OAuth2 M2M guard (skip_caller_authorization) matches the managed MCP path. No header leakage between requests. |
| litellm/proxy/_experimental/mcp_server/mcp_server_manager.py | Comment-only update clarifying that extra_headers values are applied at call-time via ContextVar, not baked in at tool registration. No logic changes. |
| tests/test_litellm/proxy/_experimental/mcp_server/test_openapi_to_mcp_generator.py | Adds 7 new mock-only tests in TestRequestExtraHeaders covering: header forwarding, no default injection, merge with statics, conflict resolution (static wins, case-insensitively), BYOK auth precedence, and no ContextVar leakage between calls. No existing tests are modified. |
Reviews (1): Last reviewed commit: "fix(mcp): static headers win over forwar..." | Re-trigger Greptile
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
4046cb1
into
BerriAI:litellm_1.84.0rc2
Relevant issues
Cherry-picks #27383 onto
litellm_1.84.0rc2.Fixes #26794 (same as #27383).
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/test_litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
CI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Screenshots / Proof of Fix
No UI change. Locally,
python3 -m pytest tests/test_litellm/proxy/_experimental/mcp_server/test_openapi_to_mcp_generator.pypassed (49 tests) after the cherry-pick and test alignment commit.Type
🐛 Bug Fix
Changes
Summary
Bring #27383 onto
litellm_1.84.0rc2so the RC matches staging for OpenAPI MCP header behavior.Included commits (cherry-picked)
MCPServer.extra_headersinto_request_extra_headersbefore local tool dispatch; merge inopenapi_to_mcp_generator. OAuth2 M2M: do not forward callerAuthorizationfromraw_headers(same idea as managed MCP)._request_auth_headerstill overridesAuthorizationlast.Not cherry-picked
Two merge commits from
litellm_internal_stagingon the original PR branch were skipped (unrelated history).Follow-up on this branch