Repository navigation
chore(release): backport #31029 to stable/1.86.x and cut 1.86.7 - #31158
Conversation
…el (#31029) * feat(mcp): scope a key to zero MCP servers with no-mcp-servers sentinel A key under a team that has MCP servers had no way to opt out of them; an empty list has always meant "inherit the team". This adds a no-mcp-servers sentinel (mirroring no-default-models for models) so a key can declare an explicit zero that overrides team inheritance, additive grants, and allow_all_keys servers, surfaced as an exclusive "No MCP Servers" option in the key create/edit UI. * refactor(ui): centralize no-mcp-servers sentinel in a shared constant The sentinel string was defined under two different local names and inlined in two more files; a single exported constant removes the drift risk flagged in review. * fix(mcp): enforce no-mcp-servers sentinel on toolset-scoped routes Toolset scoping replaced a key's mcp_servers with the toolset's servers, dropping the no-mcp-servers sentinel, so a key opted out of all MCP could still execute a granted toolset's tools via /toolset/{name}/mcp. Deny toolset access when the key carries the sentinel, checked before the admin branch to match get_allowed_mcp_servers. (cherry picked from commit 19a29e0)
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Greptile SummaryThis backport cherry-picks the
Confidence Score: 4/5Safe to merge — the sentinel logic is well-isolated and all three enforcement sites are guarded; the only note is a code-organization issue with the sentinel's home module. The change is a clean, well-tested backport. Sentinel enforcement in No files require special attention beyond the minor organizational note on
|
| Filename | Overview |
|---|---|
| litellm/proxy/_types.py | Adds SpecialMCPServerNames enum with no_mcp_servers = "no-mcp-servers" sentinel, mirroring the existing SpecialModelNames pattern; the enum is defined in _types.py rather than a dedicated constants.py. |
| litellm/proxy/management_helpers/object_permission_utils.py | Adds one line to _extract_requested_mcp_server_ids that discards the sentinel before returning, preventing key creation from failing with a 403 when the sentinel is the only entry in mcp_servers. |
| litellm/proxy/_experimental/mcp_server/auth/user_api_key_auth_mcp.py | Two sentinel checks added: _get_allowed_mcp_servers_for_key surfaces the sentinel unexpanded; get_allowed_mcp_servers short-circuits to an empty list before consulting team servers, so the opt-out is absolute. |
| litellm/proxy/_experimental/mcp_server/mcp_server_manager.py | Early sentinel guard added in get_allowed_mcp_servers that returns [] before allow_all_keys servers can be layered on, making the opt-out immune to global grants. |
| litellm/proxy/_experimental/mcp_server/server.py | Sentinel check added to _apply_toolset_scope before the admin branch, raising 403 for any key carrying the sentinel even on toolset-scoped routes. |
| ui/litellm-dashboard/src/components/mcp_server_management/MCPServerSelector.tsx | Adds allowNoMcpServers prop; selecting the sentinel clears all other selections, and other options are disabled while the sentinel is active. |
| ui/litellm-dashboard/src/components/permissions/MCPServerPermissions.tsx | Sentinel is filtered from the displayed server list; a red "Blocked" badge and explanatory banner are shown when it is present. |
Reviews (1): Last reviewed commit: "chore: refresh uv.lock for 1.86.7" | Re-trigger Greptile
| class SpecialMCPServerNames(enum.Enum): | ||
| no_mcp_servers = "no-mcp-servers" | ||
|
|
There was a problem hiding this comment.
Sentinel defined in
_types.py instead of constants.py
The team rule requires sentinel-like variables to live in a dedicated constants.py rather than in other modules. SpecialMCPServerNames is placed in _types.py, which mirrors the existing SpecialModelNames precedent but still violates the rule's intent. There is currently no litellm/proxy/constants.py, so this is a good moment to create one (or add the enum there if it already exists) and import it from _types.py, keeping a single authoritative source for the string value "no-mcp-servers" — especially since the UI constants.ts carries a matching comment pointing back to this backend enum.
Rule Used: What: Require sentinel-like variables (e.g., `_NEG... (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Relevant issues
Backports #31029 ("feat(mcp): scope a key to zero MCP servers with no-mcp-servers sentinel") onto stable/1.86.x and cuts 1.86.7. Before this, a virtual key under a team that has MCP servers had no way to opt out of them; an empty list has always meant "inherit the team". The change adds a
no-mcp-serverssentinel (mirroringno-default-modelsfor models) so a key can declare an explicit zero that overrides team inheritance, additive grants, and allow_all_keys servers, and enforces it on the toolset-scoped routes as well.Linear ticket
N/A
Pre-Submission checklist
CI (LiteLLM team)
Screenshots / Proof of Fix
Live proxy on stable/1.86.x with the pick applied, hitting the real key-management path. The customer-facing symptom is that before the fix you cannot create a key scoped to zero MCP servers; the sentinel is rejected as an unknown server.
Before the pick (baseline on the line tip):
After the pick (same request, same proxy):
The sentinel is stored verbatim and the read-time enforcement resolves the key to zero MCP servers, including on the
/toolset/{name}/mcproute (403).Targeted tests on the line, judged as a delta: baseline before the pick was 281 passed / 0 failures across the four touched test files; after the pick it is 289 passed / 0 failures, i.e. the eight new sentinel tests all pass and nothing regressed.
Deep behavioral stress-test passed: symbol closure is clean (no reference to the dropped normalization machinery anywhere on the tree), the new tests pass as a delta with no regressions, and no existing caller of the five modified functions is broken. Both production callers of
validate_key_mcp_servers_against_teamdiscard its return value, so the adapted test that no longer asserts on the return value still reflects real behavior.Type
🐛 Bug Fix
Changes
What is included, in order:
Adaptation notes
The pick is not byte-identical to the staging commit.
object_permission_utils.pyis roughly 200 lines older on 1.86.x; the write-time normalization machinery (_rewrite_object_permission_mcp_servers,_dedupe_preserving_order, and friends) was added to staging after this line was cut and is absent here. Two adaptations follow from that:_rewrite_object_permission_mcp_serversis dropped, because that function does not exist on this line. There is no normalization step here that would expand or strip the sentinel, so it is stored verbatim and the hunk is unnecessary; this is not a behavior loss. The hunk that matters on this line,_extract_requested_mcp_server_idsdiscarding the sentinel so key creation does not 403, is kept and is what the live proof above exercises.test_object_permission_utils.py, the upstreamtest_rewrite_object_permission_mcp_servers_preserves_sentineland its import are dropped (they reference the absent function and would break the module's collection), andtest_validate_no_mcp_servers_sentinel_passes_and_preservedkeeps its behavioral assertions but dropsassert result == obj_perm, sincevalidate_key_mcp_servers_against_teamreturnsNoneon this line rather than the object_permission it returns on staging. The remaining assertions still fail if the discard hunk is removed, so the test stays a real regression guard.The two enforcement test files and the manager/toolset tests apply unchanged and reference only symbols present on the line.
UI rebuild
This PR carries the production UI source changes (
MCPServerSelector.tsx,create_key_button.tsx,MCPServerPermissions.tsx,key_edit_view.tsx, plus a newmcp_tools/constants.ts) but does NOT include a rebuiltlitellm/proxy/_experimental/out/bundle. The Next.js bundle for this stable line will be rebuilt separately after merge. Until then the proxy on stable/1.86.x serves the prior UI for these screens; the backend enforcement above is fully in effect regardless.