Repository navigation
feat(mcp): caller sign-in seam for connect-time RFC 9728 challenges and shared Agent 365 OBO exchange - #41163
devin-ai-integration[bot] wants to merge 114 commits into
Conversation
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
bugbot run |
4f23e86 to
d0cb350
Compare
…r catalog identity Track the tools each MCP server listed per caller identity so pre_mcp_call and during_mcp_call hooks receive the tool description and input schema the client saw. Servers with no caller-dependent inputs share one slot; user identity, forwarded headers, stdio env, relayed bearers, and server-specific auth get their own. Local registry and OpenAPI paths pass the registered metadata and admin description overrides. The Agent 365 guardrail reads the new fields into its evaluate payload. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…docstrings Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
token_exchange servers list upstream with the caller's own Entra bearer, so two callers on one LiteLLM key with different subjects were sharing a catalog slot Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…slot Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…nges Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
d0cb350 to
e3bee03
Compare
e3bee03 to
17daa55
Compare
The pre-listing resolver ran the tool-call byok_auth_required check even when the caller already supplied x-mcp-auth, and it ran outside the per-server error boundary, so a single deprecated-header caller dropped the server from the aggregate list. Listing now returns a supplied header unchanged and falls back to the stored credential without raising Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…; true_passthrough moved-shape regression tests Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
bugbot run |
…bearer Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
bugbot run |
# Conflicts: # litellm/proxy/_experimental/mcp_server/mcp_server_manager.py # litellm/proxy/_experimental/mcp_server/operations.py # litellm/proxy/_experimental/mcp_server/rest_endpoints.py # litellm/proxy/guardrails/guardrail_hooks/agent_365/agent_365.py # litellm/proxy/utils.py # tests/integration/mcp/test_mcp_access_matrix.py # tests/integration/mcp/test_mcp_credentials.py # tests/integration/mcp/test_mcp_listed_tool_metadata.py # tests/integration/mcp/test_mcp_oauth_flows.py # tests/unit/proxy/_experimental/mcp_server/test_mcp_server.py # tests/unit/proxy/_experimental/mcp_server/test_mcp_server_manager.py # tests/unit/proxy/_experimental/mcp_server/test_mcp_server_tool_calls_and_headers.py # tests/unit/proxy/_experimental/mcp_server/test_operations.py # tests/unit/proxy/guardrails/guardrail_hooks/test_agent_365.py # tests/unit/responses/mcp/test_litellm_proxy_mcp_handler.py
|
@greptileai review latest head |
|
bugbot run |
…rule gates only sign-in providers The r12 regression: a scheme-less Authorization value or a tab-separated Bearer used to be exchanged with the IdP (the legacy lenient parse) and the sign-in contract's single-space Bearer rule challenged them at connect. The gate now decomposes the requirement: guardrail providers keep the strict subject rule, the OBO server's own requirement challenges only when there is no Authorization at all or the bearer is a withheld LiteLLM key, and any other bearer the legacy parser accepts flows to the exchange untouched.
|
@greptileai review latest head |
|
bugbot run |
…sted slot only The merge resolution let request_obj.tool_description feed the synthetic message the rate limiter counts, so a listed tool's gateway metadata inflated the caller's projected input reservation. Restore main's exact source: kwargs['mcp_tool_description'] only; request_obj.tool_description still reaches guardrails via mcp_tool_description.
|
@greptileai review latest head |
|
bugbot run |
…, not parsability Gauntlet round: an empty-valued Authorization header opened the session on the merge base (the old gate tested oauth2_headers presence) and the restored gate challenged it (the parse yields None). Presence now decides the no-header leg, and the withheld-LiteLLM-key leg fires only when a parseable bearer exists.
# Conflicts: # litellm/proxy/_experimental/mcp_server/operations.py # litellm/proxy/guardrails/guardrail_hooks/agent_365/agent_365.py
|
@greptileai review latest head |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 9d74643. Configure here.
TLDR
Problem
tools/call, where JSON-RPC dropsWWW-Authenticate, and discovery named the gateway as issuer — the client never got a sign-in promptFix
caller_sign_incontract shared by OBO servers and sign-in guardrails: a connect with no usable subject answers401with the RFC 9728 challenge, and the protected-resource metadata advertises the real issuerBearerthat is not a LiteLLM key; anything else is challenged at connect and never sent to EntraOboTokenExchanger; Entrainvalid_clientwith an AADSTS 50027xx code is a caller fault (401, never503orfail_open)scopeswhen set,api://<client_id>/access_as_userotherwiseIntentional behavior change: a server gated by a
default_onAgent 365 guardrail answersinitializewith401+ RFC 9728 metadata instead of200and failing tool calls; its discovery lists the Entra issuer instead of the gateway. A tag-onlyModewith nodefaultkeeps the old bytes.Built on #41162 (merged); main merged back at 6608e49 — reviewers diffing against an older merge base will also see main's own changes in that window, e.g. #44066's stdio MCP servers now default-disabled (
LITELLM_ENABLE_MCP_STDIO=trueto enable).User Flow
Before:
claude mcp add --transport http catalog https://litellm-domain/mcp/catalog --header "x-litellm-api-key: Bearer <key>"—initializereturns200, the server shows as connected, then everytools/callreturnsisErrorAgent 365 guardrail rejected the tool callwith no sign-in prompt.After: the same connect gets
401withWWW-Authenticate: Bearer resource_metadata="…/.well-known/oauth-protected-resource/mcp/catalog"; that document lists the Entra tenant issuer and scopes. Claude Code opens the Microsoft sign-in page, retriesinitializewith the Entra bearer, gets200, and tool calls run as the user. Ungranted keys still get403; opted-out keys and/mcpstill get200; a token Entra rejects gets the same401, not503.Linear ticket
Resolves LIT-8934
Pre-Submission checklist
Screenshots / Proof of Fix
Independently re-verified at merge commit
6608e4924bon a live rig (real proxy on real Postgres, 2 workers; scripted MCP upstream; a wire-faithful Entra/Defender double behind owned TLS — no real tenant creds available on that box, so the Microsoft side is a disclosed emulator):initialize→ RFC 9728 doc naming the Entra issuer → sign-in → retryinitialize200→tools/callruns as the user (upstream saw the call, Entra saw the OBO exchange, Defender scored it)isError; tampered JWS →401challenge; non-JWS credential →401with zero Entra calls; ungranted key →403; opted-out key →200with zero Entra calls; AADSTS 50027xxinvalid_client→ caller-fault401— 13/13 cells8ffd7c107ashows the old dead end:initialize200, tool callisErrorrejected, discovery naming the gateway as issuer — 3/3 cellsEarlier legs (including a real-tenant Entra rig) are in the Devin session history linked below.
Type
🆕 New Feature
Caveats (if any)
Medium
invalid_clientwithout an AADSTS 50027xx code stays a gateway-owned503/fail_openon Agent 365 and a500 misconfiguredon an OBO server, as onmainoauth2_token_exchangeserver's exchange now follow the unavailable path (previously401); Agent 365 keeps its throttled503default_onAgent 365 guardrail whose own OBO subject issuer differs from the guardrail's Entra tenant cannot complete the sign-in: RFC 9728 listsauthorization_serversas alternatives, a client signs in with one, and the connect preflight requires the single bearer to satisfy every gating provider. Align the issuers (same tenant) or opt the key/server out of the guardrailavailable_on_public_internet: false) are denied — the403at connect and theisErrordenial attools/call— where the merge base's tools path ignoredclient_ipand could run them; connect and tools/call now agreeinitialize(503, the preflight's design) where the merge base opened the session (200,tools/list200) and onlytools/callfailedx-mcp-serverson/mcp(a scoped single-server connect) now answersinitializewith the401sign-in challenge, where the merge base opened the session; a true multi-server aggregate on/mcpstill connects200and rejects attools/call, as onmain/mcp-rest/tools/callkeeps the structured401withoutWWW-Authenticate, as onmainLow
--forwarded-allow-ipstrusts loopback peers, so a local reverse proxy'sX-Forwarded-Protoapplies even when LiteLLM'smcp_trusted_proxy_ranges+use_x_forwarded_forgate would reject that peer), then LiteLLM's gate400whose body haserror: nullnow readsrejected (invalid_grant)wheremainprintedrejected (None)Final Attestation
REVIEWER MUST KNOW BEFORE APPROVING
default_onAgent 365-gated server (/mcp/<name>,/mcp/<server_id>, case variants,/<name>/mcp) answersinitializewith the401challenge for a missing bearer, a LiteLLM key as bearer, a non-Bearerscheme, an opaque bearer, or a JWS Entra rejects — even underfail_open. Discovery lists the Entra issuer (serverscopesorapi://<client_id>/access_as_user).server_name→name→server_id→ case-folded). Router-resolved shapes of OBO,oauth_delegate, gateway-oauth2,passthruandtrue_passthroughservers that previously answered200now answer the401challenge (ungranted keys get401instead of403there), and some case-variant discovery documents/relays move from404to the exact name's answer. RootGET /authorizeandPOST /tokenalso resolveclient_idwith the router's lookup: a case variant of a plain server's alias (e.g.client_id=DOCS) answers400 server_not_oauth2where the merge base fell through to a lone gateway OAuth server; exactclient_ids are unchanged. Routing and server selection on exact-name routes, plain servers and scoped routes are unchanged — except that IP-visibility now also governs scoped selection (available_on_public_internet: falseservers are denied from public IPs), but every OBO connect challenge'sresource_metadatamoved from the merge base's relative alias path (<alias>/mcp/<name>forms) to the absolute metadata URL of the route used — plain OBO servers included.config.yaml), the key's granted server now wins —/mcp/githubcan serve a different upstream than before. Rejecting the collision in the loader is a follow-up.Basic/Digest/scheme-less values are challenged, never sent to Entra. Everypre_mcp_callhook now receivesincoming_subject_token(the caller's non-LiteLLM bearer, ornull); hooks that forward the whole request dict (Noma v2, Conduct) pass it to their vendor.invalid_resourceis now a caller fault (401under both fallbacks — underfail_openthis is stricter than the merge base, which allowed the call unscanned),invalid_target/unsupported_grant_typeare now gateway faults (underfail_open, looser than base);invalid_grant,invalid_scopeand plaininvalid_clientkeep their status.initialize: a sessionlessDELETE, SSEGETortools/*that used to answer200 terminatedor anisErrorrejection now gets the401challenge with no Logs row. A bearer-carrying intruder naming another caller'smcp-session-idstill gets403.expires_inis absent, and one INFO log per successful exchange. Duplicatescopesentries are listed once in discovery.Link to Devin session: https://app.devin.ai/sessions/0c5e46d406144373b8b0daebb4049fc4
Open in Devin Desktop: https://app.devin.ai/desktop/session/0c5e46d406144373b8b0daebb4049fc4?variant=devin
Requested by: @yucheng-berri
Note
High Risk
Changes MCP authentication, OAuth discovery, and connect-time challenges across many entry points; misconfiguration or resolver differences can alter who gets 401 vs 403 and which IdP metadata clients see.
Overview
Introduces a
caller_sign_inseam so MCP connect and OAuth protected-resource metadata share one contract: OBO token-exchange servers and guardrails that implementCallerSignInProvidermerge required issuers/scopes, and a connect without a usable callerBearer(not a LiteLLM virtual/master key) returns RFC 9728401withWWW-Authenticatebefore JSON-RPC swallows the header.Agent 365 adopts that provider: connect-time challenge + preflight Entra OBO via the shared
OboTokenExchanger, discovery advertises the Entra issuer (and server scopes or gateway scope), and tool hooks useincoming_subject_tokeninstead of treating the admission key as the assertion. Token-exchange HTTP handling now treats 408/429 as upstream outage, distinguishes Entrainvalid_clientwith AADSTS 50027xx as caller fault, and challenges can carry the absolute metadata URL for the route the client used.Routing/authorization is aligned through
get_mcp_server_answering_toand scoped selection that prefers the key’s granted server, respects client IP visibility, and fails closed on unknown scoped names; connect can peek the body only when a gating provider needs to distinguishinitialize.Reviewed by Cursor Bugbot for commit 9d74643. Bugbot is set up for automated code reviews on this repo. Configure here.