Repository navigation
chore(release): backport #31029 to stable/1.88.x and cut 1.88.5 - #31160
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)
Greptile SummaryThis PR backports the
Confidence Score: 4/5The backport is behaviorally correct and well-tested; the only finding is a style inconsistency in where the new enum is defined. All enforcement points (team inheritance, allow_all_keys layer, toolset path) are guarded by the sentinel and covered by dedicated unit tests. The permission-utils rewrite and extraction functions handle the sentinel cleanly. The sole finding is that
|
| Filename | Overview |
|---|---|
| litellm/proxy/_types.py | Adds SpecialMCPServerNames enum with no_mcp_servers = "no-mcp-servers" sentinel, mirroring the existing SpecialModelNames pattern; violates the custom rule requiring sentinels to live in constants.py. |
| litellm/proxy/_experimental/mcp_server/auth/user_api_key_auth_mcp.py | Adds sentinel short-circuit in both _get_allowed_mcp_servers_for_key (surfaces unexpanded sentinel) and get_allowed_mcp_servers (returns [] before team inheritance); logic and tests look correct. |
| litellm/proxy/_experimental/mcp_server/mcp_server_manager.py | Adds sentinel check at the top of get_allowed_mcp_servers, returning [] before the allow_all_keys layer is applied; correctly makes the opt-out absolute. |
| litellm/proxy/_experimental/mcp_server/server.py | Adds sentinel guard in _apply_toolset_scope before the admin-bypass check, raising 403 for keys scoped to no MCP servers; intentional behaviour verified by the parametrised admin test. |
| litellm/proxy/management_helpers/object_permission_utils.py | Sentinel passes through _rewrite_object_permission_mcp_servers unchanged and is discarded from _extract_requested_mcp_server_ids, preventing spurious DB lookups and "stale identifier" warnings. |
| tests/test_litellm/proxy/_experimental/mcp_server/auth/test_user_api_key_auth_mcp.py | Adds two new unit tests: sentinel returns [] even when team servers are non-empty, and _get_allowed_mcp_servers_for_key surfaces the sentinel unexpanded regardless of other entries. |
| tests/test_litellm/proxy/_experimental/mcp_server/test_mcp_server_manager.py | Adds test_no_mcp_servers_sentinel_blocks_allow_all_keys which verifies the inner resolver is never called and result is [] when the sentinel is set; mock usage is sound. |
| tests/test_litellm/proxy/_experimental/mcp_server/test_mcp_toolset_scope.py | Adds parametrised test (None and PROXY_ADMIN roles) confirming sentinel raises 403 in toolset path before admin bypass; resolve mock is never awaited as expected. |
| tests/test_litellm/proxy/management_helpers/test_object_permission_utils.py | Three new tests covering sentinel exclusion from server-id extraction, sentinel preservation in rewrite, and sentinel passing team validation untouched; all mock-only, no network calls. |
| ui/litellm-dashboard/src/components/mcp_tools/constants.ts | New file exporting NO_MCP_SERVERS_SENTINEL = "no-mcp-servers" with a comment tying it to the backend enum; correct placement for a UI-side constant. |
| ui/litellm-dashboard/src/components/mcp_server_management/MCPServerSelector.tsx | Adds allowNoMcpServers prop that renders the sentinel option at the top, clears other selections when chosen, and disables all regular options while sentinel is active. |
| ui/litellm-dashboard/src/components/permissions/MCPServerPermissions.tsx | Filters sentinel from the display list and shows a red "Blocked" badge with explanatory text when the key is scoped to no MCP servers. |
| ui/litellm-dashboard/src/components/organisms/create_key_button.tsx | Enables allowNoMcpServers on the selector and filters the sentinel out of selectedServers passed to MCPToolPermissions to avoid showing phantom tool permission entries. |
| ui/litellm-dashboard/src/components/templates/key_edit_view.tsx | Same allowNoMcpServers enablement and sentinel filter for MCPToolPermissions as create_key_button.tsx; consistent treatment between create and edit paths. |
| ui/litellm-dashboard/src/components/mcp_server_management/MCPServerSelector.test.tsx | New Vitest file with three UI-level tests: sentinel hidden by default, emits exclusive sentinel on selection, disables regular options while sentinel is active. |
Reviews (1): Last reviewed commit: "chore: refresh uv.lock for 1.88.5" | 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
Per the project's custom rule, sentinel-like constants must live in constants.py so that changes are centralised and future additions are consistent. SpecialMCPServerNames is placed in _types.py, mirroring the pre-existing SpecialModelNames, but that existing class is itself non-compliant with the rule. Adding a second sentinel here compounds the drift. There is no litellm/proxy/constants.py today, so the right fix is either to create one and move both enums there, or at minimum start the pattern correctly for the new enum. Four production modules already import from _types, so a move would require updating those imports — but the rule exists precisely to prevent this kind of growing dependency.
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!
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Relevant issues
Backports #31029 onto
stable/1.88.xand cuts1.88.5. The change adds ano-mcp-serverssentinel (mirroringno-default-modelsfor models) so a virtual key can be scoped to zero MCP servers. Before this, an emptymcp_serverslist always meant "inherit the team", so there was no value a user could set to say "this key gets none"; the sentinel is the explicit zero that overrides team inheritance, additive access-group grants, andallow_all_keysservers, and also denies toolset-scoped access.This is a feature backport. The pick applied cleanly except for one context-only conflict in a test file (details below); no production logic line was altered from the staging commit.
What is included
19a29e0UI rebuild deferred
This pick changes production UI source (
MCPServerSelector.tsx,create_key_button.tsx,MCPServerPermissions.tsx,key_edit_view.tsx, andmcp_tools/constants.ts). The proxy serves a prebuilt Next.js bundle fromlitellm/proxy/_experimental/out/, and that bundle is NOT rebuilt in this PR. The stable UI will be rebuilt separately on this branch after merge. Until that rebuild lands, the backend opt-out is fully functional over the API (a key whoseobject_permission.mcp_serversholdsno-mcp-serversreturns zero tools), but the "No MCP Servers" option will not yet appear in the key create/edit forms on the stable build.Adaptation notes
The pick is patch-id ADAPTED relative to staging, but only in surrounding context; none of the PR's own added lines were modified. The divergences are:
ip_address_utilsvsuser_api_key_auth,MCPEnvVarvsMCPAuthType, and the repository-imports block vs aTYPE_CHECKINGblock). The PR's addedSpecialMCPServerNamesimports are byte-identical; only the unrelated neighbor lines differ, so these resolved as clean context drift.tests/test_litellm/proxy/_experimental/mcp_server/auth/test_user_api_key_auth_mcp.py: 1.88.x carries an extrafrom litellm.proxy.auth.user_api_key_auth import user_api_key_authimport directly under the_typesimport that staging's version of the file does not have at that spot. Resolved by keeping that 1.88.x import and applying the PR's multi-line_typesimport that addsSpecialMCPServerNames. The two new sentinel test methods the PR adds were taken verbatim.Known noise on this line
None. The targeted baseline (the test files this PR touches, plus the mirrored source tests, run on the line tip before picking) was 416 passed / 0 failed / 0 errors. After the pick the same set is 425 passed / 0 failed, a clean +9 that matches the tests the PR adds.
Screenshots / Proof of Fix
Verified against a live proxy running the 1.88.x worktree code with the pick applied, with two config MCP servers (
wikipediastdio anddeepwikihttp) markedallow_all_keys: true, against an isolated Postgres carrying the 1.88.x schema. The shared dev DB could not be used because it sits on an older schema (a prisma-client mismatch under the shared.venv, unrelated to this pick), so an isolated DB was stood up for the replay.Every key that is not scoped with the sentinel sees the allow-all servers union (4 tools); only the sentinel key sees zero. Create-key commands are
POST /key/generatewithobject_permission.mcp_serversset, thentools/listoverPOST /mcp/:The naive baseline-vs-after
tools/listdiff for the sentinel key alone is not meaningful, because feeding the newno-mcp-serversstring to the old code coincidentally resolves to zero (it is a non-existent server name and an explicitobject_permissionsuppresses inheritance). The authoritative behavioral proof is the unit-test delta above: all 20 sentinel and toolset tests pass on the line, includingtest_no_mcp_servers_sentinel_blocks_allow_all_keys(allow-all override) andtest_no_mcp_servers_sentinel_denies_toolset_access[None, proxy_admin](toolset 403), which the live curl cannot easily isolate.Gauntlet (behavioral, universal, deep): SURVIVED, zero verified findings, seal holds. Five of six adversarial lenses support the hypothesis; the lone non-supporting lens conceded its verdict was driven solely by a transient working-tree fingerprint mismatch from the gauntlet's own concurrent mutation testing, not by any defect in the pick. The mutation run is itself supporting evidence: reverting the five production hunks turned the sentinel tests red, and restoring them turned them green, so the tests genuinely pin the feature. Symbol closure resolves (
SpecialMCPServerNamesdefined in_types.py, ruff clean on all touched modules).Type
🆕 New Feature
Changes
Backport of the no-mcp-servers sentinel onto stable/1.88.x with a 1.88.5 version bump. Backend, tests, and UI source are carried; the UI bundle is rebuilt separately after merge.