Skip to content

chore(release): backport #31029 to stable/1.86.x and cut 1.86.7 - #31158

Merged
yuneng-berri merged 3 commits into
stable/1.86.xfrom
litellm_backport_1_86_x_bp-31029-186
Jun 24, 2026
Merged

yuneng-berri merged 3 commits into
stable/1.86.xfrom
litellm_backport_1_86_x_bp-31029-186

Conversation

@yuneng-berri

Copy link
Copy Markdown
Contributor

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-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, and enforces it on the toolset-scoped routes as well.

Linear ticket

N/A

Pre-Submission checklist

  • I have added meaningful tests
  • My PR passes all unit tests on the touched files
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have requested a Greptile 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

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):

POST /key/generate  {"object_permission":{"mcp_servers":["no-mcp-servers"]}}
HTTP 403
{"error":{"message":"... Only globally available (allow_all_keys) MCP servers can be assigned: []. Disallowed servers: ['no-mcp-servers'].","code":"403"}}

After the pick (same request, same proxy):

POST /key/generate  {"object_permission":{"mcp_servers":["no-mcp-servers"]}}
HTTP 200   -> key created

GET /key/info?key=<new key>
object_permission.mcp_servers = ['no-mcp-servers']

The sentinel is stored verbatim and the read-time enforcement resolves the key to zero MCP servers, including on the /toolset/{name}/mcp route (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_team discard 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.py is 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:

  • The upstream hunk that preserved the sentinel inside _rewrite_object_permission_mcp_servers is 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_ids discarding the sentinel so key creation does not 403, is kept and is what the live proof above exercises.
  • In test_object_permission_utils.py, the upstream test_rewrite_object_permission_mcp_servers_preserves_sentinel and its import are dropped (they reference the absent function and would break the module's collection), and test_validate_no_mcp_servers_sentinel_passes_and_preserved keeps its behavioral assertions but drops assert result == obj_perm, since validate_key_mcp_servers_against_team returns None on 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 new mcp_tools/constants.ts) but does NOT include a rebuilt litellm/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.

ryan-crabbe-berri and others added 3 commits June 23, 2026 18:45
…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:32
@codecov

codecov Bot commented Jun 24, 2026 •

Copy link
Copy Markdown

@greptile-apps

greptile-apps Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This backport cherry-picks the no-mcp-servers sentinel feature from staging onto stable/1.86.x and cuts version 1.86.7. It gives virtual keys a way to explicitly opt out of all MCP servers (including team-inherited and allow_all_keys grants), mirroring the existing no-default-models pattern for models.

  • Backend: SpecialMCPServerNames.no_mcp_servers sentinel is added to _types.py; three enforcement sites (key auth, server manager, toolset scope) each short-circuit to zero / 403 before team inheritance or admin bypass can add servers back; key creation strips the sentinel from the server-ID set so validate_key_mcp_servers_against_team doesn't reject it.
  • UI: A new allowNoMcpServers prop on MCPServerSelector renders an exclusive "No MCP Servers / Block all" option; selecting it clears other choices and disables them; MCPServerPermissions renders a red "Blocked" banner instead of a server list; both the create-key and edit-key views filter the sentinel out before passing servers to MCPToolPermissions.
  • Tests: Eight new unit tests cover sentinel enforcement across all four touched Python test files, plus a new MCPServerSelector.test.tsx; the UI bundle rebuild is deferred to a separate step after merge.

Confidence Score: 4/5

Safe 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 get_allowed_mcp_servers, MCPServerManager.get_allowed_mcp_servers, and _apply_toolset_scope is consistent, the discard at key-creation time is correct, and eight new tests plus a UI test cover the key paths. The sole finding is that SpecialMCPServerNames lives in _types.py rather than a dedicated constants.py per the team's sentinel-placement rule, but this has no runtime impact.

No files require special attention beyond the minor organizational note on litellm/proxy/_types.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; 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

Comment thread litellm/proxy/_types.py
Comment on lines +3367 to +3369
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

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!

@yuneng-berri
yuneng-berri merged commit b9c4544 into stable/1.86.x Jun 24, 2026
31 of 32 checks passed
@yuneng-berri
yuneng-berri deleted the litellm_backport_1_86_x_bp-31029-186 branch June 24, 2026 03:00
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