Skip to content

fix(mcp): use a toolset row's stored tool name as written - #34559

Merged
tin-berri merged 1 commit into
litellm_internal_stagingfrom
litellm_lit3419_toolset_prefix
Jul 25, 2026
Merged

tin-berri merged 1 commit into
litellm_internal_stagingfrom
litellm_lit3419_toolset_prefix

Conversation

@tin-berri

@tin-berri tin-berri commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • A toolset row could resolve to a different tool on the same server, so the selected tool disappeared from /toolset/<name>/mcp and an unselected sibling was served, and executed, under the selected tool's wire name
  • It fires whenever a native tool name happens to begin with what the gateway uses as that server's wire prefix followed by MCP_TOOL_PREFIX_SEPARATOR, so it reaches the default - separator too: a server aliased deepwiki serving a native deepwiki-contents reduces to contents
  • Toolsets are the tool-level permission boundary, so the row granted access to a tool that was never selected, while tools/list still returned the expected count under the expected name

How it solves it:

  • A row already carries server_id, so the stored tool_name is the tool's own name and is matched as written; only the live name coming off the server still has the wire prefix stripped

Relevant issues

  • Stops a toolset row from resolving to a different tool on the same MCP server, which listed and executed something the admin never selected
  • Removes the prefix reduction applied to stored names in resolve_toolset_tool_permissions, the single producer of the allowlist, so the MCP tools/list filter, the tools/call permission check, the REST listing and the Responses API path are all corrected without touching them
  • Net removal of logic, no schema change, no new field, and no behavior change for a row whose stored name does not begin with its server's prefix

Linear ticket

LIT-3419

Not marked as auto-closing: the reported deployment's effective MCP_TOOL_PREFIX_SEPARATOR has not been confirmed yet, and the dashboard renders the prefix with a hardcoded - (MCPToolsetTableColumns.tsx), so the reporter's screenshot cannot reveal it. This diff fixes the defect described in the ticket; whether it is the whole of what that deployment hit needs the env var plus the raw LiteLLM_MCPToolsetTable row from the running container.

Pre-Submission checklist

  • I have added meaningful tests
  • My PR passes all CI/CD checks (e.g., lint, format, unit tests); osv-scan is red, and it is red identically on every open PR checked (34586, 34588, 34589, 34590, 34591, 34592), so it is repo-wide and not this diff
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (5/5, and the earlier security finding is resolved)

Screenshots / Proof of Fix

Live proxy on 127.0.0.1:4419 against a real streamable-HTTP MCP upstream on a server prefixed greyhound, exposing two native tools: inspect_events and greyhound_inspect_events. The second name is what triggers the bug, since it begins with the server's own prefix.

Steps 1 to 5 run with MCP_TOOL_PREFIX_SEPARATOR=_, which is why the wire names below read greyhound_greyhound_inspect_events. Under the default - the same row lists as greyhound-greyhound_inspect_events; step 6 covers that separator.

  1. What each surface sees, with the separator set to _
curl -s "http://127.0.0.1:4419/mcp-rest/tools/list?server_id=$SID" -H 'Authorization: Bearer sk-1234'
#  picker tool_name: inspect_events
#  picker tool_name: greyhound_inspect_events     <- the tool's own name, what the dashboard persists

curl -s -X POST http://127.0.0.1:4419/mcp/ -H 'x-litellm-api-key: Bearer sk-1234' \
  -H 'Accept: application/json, text/event-stream' -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'
#  wire name: greyhound_inspect_events
#  wire name: greyhound_greyhound_inspect_events
  1. Grant exactly one tool, the native greyhound_inspect_events, as the dashboard writes it
curl -s -X POST http://127.0.0.1:4419/v1/mcp/toolset -H 'Authorization: Bearer sk-1234' \
  -H 'Content-Type: application/json' \
  -d "{\"toolset_name\":\"ts-ui\",\"tools\":[{\"server_id\":\"$SID\",\"tool_name\":\"greyhound_inspect_events\"}]}"

psql -h localhost -U tin -d litellm_lit3419 -At -c 'select toolset_name, tools from "LiteLLM_MCPToolsetTable";'
# ts-ui|[{"server_id": "a8947b6b...", "tool_name": "greyhound_inspect_events"}]
  1. Before. One tool is listed and the count looks right, but calling it runs the tool that was never granted
# tools/list
#  tools returned: 1
#    - greyhound_inspect_events

# tools/call greyhound_inspect_events
#  upstream ran: inspect_events ran with X | isError: False
#  ^ the unselected sibling executed, and the selected tool was unreachable

Note that the count and the displayed name are both correct here. Nothing on the listing surface indicates a problem, which is why this reads as working and is why the defect is an authorization one rather than a visibility one.

  1. After. The selected tool resolves, and the sibling is refused
# tools/list
#  tools returned: 1
#    - greyhound_greyhound_inspect_events

# tools/call greyhound_greyhound_inspect_events
#  upstream ran: greyhound_inspect_events ran with X | isError: False

# tools/call greyhound_inspect_events        (the sibling, never selected)
#  Error: Tool 'inspect_events' is not allowed for your key/team on server 'greyhound'
  1. An ordinary row is unaffected
# toolset holding the row "inspect_events"
#  tools returned: 1
#    - greyhound_inspect_events
# tools/call greyhound_inspect_events  ->  inspect_events ran with Y
  1. Default separator, after the change
# MCP_TOOL_PREFIX_SEPARATOR=- , same ts-ui row
#  tools returned: 1
#    - greyhound-greyhound_inspect_events
# unchanged from before the fix, so this row is unregressed on the default separator

This row is unregressed on - because greyhound_inspect_events does not start with greyhound-, so the old reduction was already a no-op for it. The default separator is not immune in general: strip_known_server_prefix strips {known_prefix}{separator} for any of the server's registered prefixes, so a native name such as deepwiki-contents on a server aliased deepwiki was reduced to contents on stock defaults.

  1. The one behavior this removes: a row storing an already-prefixed name
# MCP_TOOL_PREFIX_SEPARATOR=- , row stores "greyhound-inspect_events" while the native tool is "inspect_events"
#  tools returned: 0

This is acceptable because the dashboard picker reads the REST listing with add_prefix=False and therefore only ever persists bare native names, so it cannot create such a row.

Type

🐛 Bug Fix

Changes

  • resolve_toolset_tool_permissions uses tool_name as stored instead of reducing it by the server's wire prefix, which also drops the per-row server lookup and the strip_known_server_prefix import
  • Documents the contract on the method: a row names a tool on the server given by server_id, so the stored name is the tool's own name and the wire prefix is never treated as part of it
  • Reworks the LIT-3419 regression class in test_mcp_toolset_scope.py around the new contract: the stored name survives verbatim, a name that looks like its own server prefix still resolves end to end through the listing filter, and the unselected sibling is not reachable
  • Replaces the test that asserted a stored prefixed name is reduced, since that is the behavior being removed

QA runbook

Point an MCP client at /toolset/<name>/mcp with a key granted that toolset. Add a tool through the dashboard whose native name begins with the server's alias followed by the configured MCP_TOOL_PREFIX_SEPARATOR, and confirm tools/list offers it, tools/call reaches the upstream function of that name, and a sibling tool that was not added is refused. Repeat with an ordinary tool name and confirm it is unchanged. Check the sibling explicitly rather than the listed count, since the pre-fix behavior returns the correct count under the correct name.

@greptile-apps

greptile-apps Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR makes toolset permission resolution preserve each stored native tool name verbatim and updates regression coverage for names that resemble server wire prefixes.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains in the fix for the previously reported ambiguous tool-name resolution.

Important Files Changed

Filename Overview
litellm/proxy/_experimental/mcp_server/mcp_server_manager.py Removes stored-name prefix normalization so each toolset row resolves only to the exact server-scoped tool name selected by the administrator.
tests/test_litellm/proxy/_experimental/mcp_server/test_mcp_toolset_scope.py Updates prefix-resolution tests and verifies that a prefix-like native name grants only the selected tool rather than its stripped sibling.

Reviews (3): Last reviewed commit: "fix(mcp): use a toolset row's stored too..." | Re-trigger Greptile

@veria-ai

veria-ai Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Security review

No open security issues remain on this pull request.

Fixed/addressed: 1 · PR risk: 0/10

@tin-berri
tin-berri force-pushed the litellm_lit3419_toolset_prefix branch from 94efe3a to 31caaec Compare July 24, 2026 22:11
@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@codecov

codecov Bot commented Jul 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_lit3419_toolset_prefix (3489e65) with litellm_internal_staging (7263aa0)1

Open in CodSpeed

Footnotes

  1. No successful run was found on litellm_internal_staging (842f32d) during the generation of this report, so 7263aa0 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

A toolset row is {server_id, tool_name}. The server is already identified by
server_id, so the stored name is the tool's own name and there is nothing for a
prefix to disambiguate. Resolution nevertheless reduced the stored name by the
server's wire prefix, which is a guess about a string that carries no such
marker.

The wire prefix is added on the way out and is not part of any tool's identity,
so when a native tool name happens to begin with it the guess renamed the tool:
a row for greyhound_internal_events on a server prefixed greyhound resolved to
internal_events. That is a different tool on the same server, so the selected
tool disappeared from /toolset/<name>/mcp and an unselected sibling was served,
and executed, under the selected tool's wire name. Toolsets are the tool-level
permission boundary, so the row granted access to something never selected.

Match the stored name as written and keep stripping the prefix off the live name
only. This is the only producer that rewrote allowlist values; every other one
stores what the admin typed, so the tools/list filter, the tools/call permission
check, the REST listing and the Responses API path are all corrected without
touching them.

A row that stores an already-prefixed name no longer resolves. Such a row names
a tool that does not exist on the server, and the dashboard has never written
one; it was only ever accepted because of the guess this removes.
@tin-berri
tin-berri force-pushed the litellm_lit3419_toolset_prefix branch from 31caaec to 3489e65 Compare July 25, 2026 00:09
@tin-berri tin-berri changed the title fix(mcp): resolve a toolset row by both readings of its stored tool name fix(mcp): use a toolset row's stored tool name as written Jul 25, 2026
@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

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.

✅ Bugbot reviewed your changes and found no new issues!

1 issue from previous review remains unresolved.

Fix All in Cursor

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 3489e65. Configure here.

@tin-berri
tin-berri merged commit 4e3dbea into litellm_internal_staging Jul 25, 2026
84 of 85 checks passed
@tin-berri
tin-berri deleted the litellm_lit3419_toolset_prefix branch July 25, 2026 18:31
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.

2 participants