Skip to content

chore(release): backport #31029 to stable/1.88.x and cut 1.88.5 - #31160

Merged
yuneng-berri merged 3 commits into
stable/1.88.xfrom
litellm_backport_1_88_x_bp-no-mcp-sentinel-0623
Jun 24, 2026
Merged

yuneng-berri merged 3 commits into
stable/1.88.xfrom
litellm_backport_1_88_x_bp-no-mcp-sentinel-0623

Conversation

@yuneng-berri

Copy link
Copy Markdown
Contributor

Relevant issues

Backports #31029 onto stable/1.88.x and cuts 1.88.5. The change adds a no-mcp-servers sentinel (mirroring no-default-models for models) so a virtual key can be scoped to zero MCP servers. Before this, an empty mcp_servers list 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, and allow_all_keys servers, 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

UI rebuild deferred

This pick changes production UI source (MCPServerSelector.tsx, create_key_button.tsx, MCPServerPermissions.tsx, key_edit_view.tsx, and mcp_tools/constants.ts). The proxy serves a prebuilt Next.js bundle from litellm/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 whose object_permission.mcp_servers holds no-mcp-servers returns 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:

  • Import-block neighbors differ between 1.88.x and staging in three source files (for example ip_address_utils vs user_api_key_auth, MCPEnvVar vs MCPAuthType, and the repository-imports block vs a TYPE_CHECKING block). The PR's added SpecialMCPServerNames imports are byte-identical; only the unrelated neighbor lines differ, so these resolved as clean context drift.
  • One real conflict in tests/test_litellm/proxy/_experimental/mcp_server/auth/test_user_api_key_auth_mcp.py: 1.88.x carries an extra from litellm.proxy.auth.user_api_key_auth import user_api_key_auth import directly under the _types import 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 _types import that adds SpecialMCPServerNames. 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 (wikipedia stdio and deepwiki http) marked allow_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/generate with object_permission.mcp_servers set, then tools/list over POST /mcp/:

master key                                  -> 4 tools  (wikipedia-fetch + 3 deepwiki-*)
team key, mcp_servers: []        (inherit)  -> 4 tools
team key, mcp_servers: ["no-mcp-servers"]   -> 0 tools   (opt-out; stored as {no-mcp-servers})
team key, mcp_servers: ["wikipedia"]        -> 4 tools  (allow_all union still applies)
direct key, mcp_servers: ["no-mcp-servers"] -> 0 tools   (overrides allow_all_keys)
direct key, no object_permission            -> 4 tools  (inherits allow_all)

The naive baseline-vs-after tools/list diff for the sentinel key alone is not meaningful, because feeding the new no-mcp-servers string to the old code coincidentally resolves to zero (it is a non-existent server name and an explicit object_permission suppresses inheritance). The authoritative behavioral proof is the unit-test delta above: all 20 sentinel and toolset tests pass on the line, including test_no_mcp_servers_sentinel_blocks_allow_all_keys (allow-all override) and test_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 (SpecialMCPServerNames defined 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.

ryan-crabbe-berri and others added 3 commits June 23, 2026 18:55
…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)
@yuneng-berri
yuneng-berri requested a review from a team June 24, 2026 02:47
@greptile-apps

greptile-apps Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR backports the no-mcp-servers sentinel feature from staging onto stable/1.88.x and cuts version 1.88.5. The sentinel lets a virtual key explicitly opt out of every MCP server (including team-inherited and allow_all_keys servers), mirroring the existing no-default-models pattern for model scoping.

  • Backend: SpecialMCPServerNames.no_mcp_servers enum added to _types.py; three enforcement points added — MCPRequestHandler.get_allowed_mcp_servers, MCPServerManager.get_allowed_mcp_servers, and _apply_toolset_scope (raises 403 before the admin-bypass branch, intentionally denying toolset access even to admin-role keys that carry the sentinel).
  • Permission utils: _extract_requested_mcp_server_ids discards the sentinel before DB lookup; _rewrite_object_permission_mcp_servers passes it through unchanged, preventing spurious "stale identifier" warnings on key create/update.
  • Frontend (UI source only, bundle rebuilt separately): MCPServerSelector gains an allowNoMcpServers prop rendering an exclusive "Block all" option; MCPServerPermissions shows a red badge; create_key_button and key_edit_view filter the sentinel from selectedServers passed to MCPToolPermissions.

Confidence Score: 4/5

The 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 SpecialMCPServerNames lands in _types.py rather than constants.py, following the pre-existing SpecialModelNames pattern that itself pre-dates the rule.

litellm/proxy/_types.py — the new sentinel enum is placed here rather than in a dedicated constants.py.

Important Files Changed

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

Comment thread litellm/proxy/_types.py
Comment on lines +3383 to +3385
class SpecialMCPServerNames(enum.Enum):
no_mcp_servers = "no-mcp-servers"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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

codecov Bot commented Jun 24, 2026 •

Copy link
Copy Markdown

@yuneng-berri
yuneng-berri enabled auto-merge June 24, 2026 03:02
@yuneng-berri
yuneng-berri merged commit 4cdd90f into stable/1.88.x Jun 24, 2026
31 of 32 checks passed
@yuneng-berri
yuneng-berri deleted the litellm_backport_1_88_x_bp-no-mcp-sentinel-0623 branch June 24, 2026 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants