Backtestslitellmrun-20261018-182052#44831

Issue #44831 Merged fix PR #46225 Run 18 Oct 2026 · run-20261018-182052 BerriAI/litellm

[Bug]: MCP tools/call with an unprefixed tool name on /{server_name}/mcp resolves via the global tool-name mapping, not the server in the path (404 when cold, 403 when another server has a tool with the same name)

Better

Our patch was judged better than the merged fix.

In this judgment, Patch B = our agent, Patch A = the merged fix.

Both patches make the same core change: when the request is scoped to a single server (/{server_name}/mcp or x-mcp-servers), pass that server's id as requested_server_id to execute_mcp_tool so an unprefixed name resolves against the path server rather than the last-listed-wins global mapping. Both pass all six independent tests covering cold, collision, flip, and delete scenarios. The differences are at the edges. Patch B's narrowing condition (`mcp_servers` non-empty and allowed servers narrowed to one) is a closer match to 'the scope names one server' than Patch A's requirement that the raw list have exactly one entry, so B also handles a header naming two servers where only one is allowed to the key, or an alias plus id for the same server. More importantly, B keeps billing consistent with routing: on base, dispatch and billing_auth_for_tool_call both consulted the tool-name mapping, so they agreed. Patch A changes dispatch to the scoped server but leaves billing on the mapping, so in the issue's collision scenario the call now runs on server_b while spend is attributed to server_a's granting team. B threads mcp_servers into billing_auth_for_tool_call and adds a test (including case-insensitive scope) proving the billed team matches the routed server. That is adjacent work, but it closes a mismatch the fix itself creates, so it counts for correctness rather than being neutral churn. Costs of B: an extra allowed-servers lookup on the billing path and a lazy import from operations inside the auth module, both modest. Patch A's strengths are a tidy named helper, a fresh-manager test rig, and a useful negative test that an ambiguous bare name still 404s rather than being guessed; B's integration test against the global manager with manual save/restore is more fragile. On balance B is the more complete fix for the scenarios the issue describes.

Four judges ruled on this ticket in parallel, and the verdict comes from counting their votes. Each saw the issue and the two patches, labelled A and B in random order (two of them saw ours as A), with issue links and version numbers removed. Where tests could check the fix, they also saw the results of tests a separate agent wrote for the issue, run on both patches. None was told which patch was ours. The reasoning above is one judge's, shown verbatim.

Solve

1h 36m

Wall-clock time in the container

Full test suite

Not run

The harness did not reach the test stage

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

159vs 139 merged

Changed lines, ours vs merged

Description

On a single-server MCP endpoint (/{server_name}/mcp), a tools/call with an unprefixed tool name is not resolved against the server in the URL path. LiteLLM resolves it through the process-wide tool_name_to_mcp_server_name_mapping, which is keyed by the unprefixed tool name, filled only by tools/list, and overwritten by whichever server was listed last. So the outcome depends on what any caller listed before:

  1. Cold mapping → 404. If nobody has listed the server since startup (or since another server was deleted, which removes its entries), the call returns Error: Tool '<tool>' not found. This still happens on v1.104.0, which already includes #42072 (_list_tools_before_first_call). The prefixed name works on the same cold worker.
  2. Name collision → 403. If two servers expose a tool with the same name, the mapping points to the server listed last. Calling the tool on the other server's endpoint returns Error: User not allowed to call this tool., even though the key can access the server in the path. Listing the second server flips it, and the first server starts returning 403.

One caller's tools/list changes how another caller's tools/call resolves. In our deployment, several servers share tool names (they are instances of the same MCP app, and all of them expose a common get_task_result tool), so calls fail intermittently depending on traffic.

The prefixed name (<alias>-<tool>) always works.

Config

Kubernetes, 1 replica, DB-managed MCP servers (store_model_in_db: true), virtual keys

LiteLLM Version

v1.104.0

Steps to Repro

Setup:

  • Single replica and single worker.
  • Two DB-managed MCP servers, server_a and server_b, created through POST /v1/mcp/server with transport: http and auth_type: none. Both expose a tool with the same name, list_items.
  • $KEY is a virtual key with access to both servers.
  • The proxy has just been restarted.

Helper used in the steps below:

H=http://localhost:4000
call() {
  curl -s -X POST "$H/$1/mcp" \
    -H "Authorization: Bearer $KEY" \
    -H "Accept: application/json, text/event-stream" \
    -H "Content-Type: application/json" \
    -d "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"$2\",\"params\":$3}"
}

1. Cold mapping, unprefixed name → 404. It keeps failing on retries.

call server_b tools/call '{"name":"list_items","arguments":{}}'
{"jsonrpc":"2.0","id":1,"result":{"content":[{"type":"text","text":"Error: Tool 'list_items' not found"}],"isError":true}}

2. Same call with the prefixed name → OK.

call server_b tools/call '{"name":"server_b-list_items","arguments":{}}'

3. List server_a, then call server_b unprefixed → 403.

call server_a tools/list '{}'
call server_b tools/call '{"name":"list_items","arguments":{}}'
{"jsonrpc":"2.0","id":1,"result":{"content":[{"type":"text","text":"Error: User not allowed to call this tool."}],"isError":true}}

4. List server_b → server_b works, but server_a now returns 403.

call server_b tools/list '{}'
call server_b tools/call '{"name":"list_items","arguments":{}}'   # OK
call server_a tools/call '{"name":"list_items","arguments":{}}'   # 403
{"jsonrpc":"2.0","id":1,"result":{"content":[{"type":"text","text":"Error: User not allowed to call this tool."}],"isError":true}}

5. Delete server_b → unprefixed calls to server_a return 404 until server_a is listed again.

curl -s -X DELETE "$H/v1/mcp/server/<server_b_id>" -H "Authorization: Bearer $MASTER_KEY"
call server_a tools/call '{"name":"list_items","arguments":{}}'
{"jsonrpc":"2.0","id":1,"result":{"content":[{"type":"text","text":"Error: Tool 'list_items' not found"}],"isError":true}}

Expected behaviour

On /{server_name}/mcp, an unprefixed tool name should resolve against the server in the path. The result should not depend on which servers any caller listed earlier, and two servers exposing the same tool name should not affect each other.

Relevant code (v1.104.0, litellm/proxy/_experimental/mcp_server/)

  • mcp_server_manager.py (~6536): after listing, tool_name_to_mcp_server_name_mapping[original_name] = server.name. The key is the unprefixed name, so the last server listed wins.
  • mcp_server_manager.py (~6553): resolution checks that mapping first.
  • operations.py (~1890): first_call_target uses requested_server for unprefixed names. Since we still get 404 for unprefixed calls on /{server_name}/mcp, requested_server seems not to be set from the URL path on the MCP protocol route; #42655 points at the same thing. I haven't traced it further.
  • operations.py (~1965): when the mapping points to a server outside the ones allowed for the request path, the call returns User not allowed to call this tool.
  • mcp_server_manager.py (~2823-2846): deleting a server removes its mapping entries, which re-colds tools that other servers share.

Related

  • #42655 / #42072: single-server endpoint does not use the server in the path. Fixed for the cold-worker case in v1.104.0-rc.1, but unprefixed names on /{server_name}/mcp still fail.
  • #44373, #39751, #24089: cold or empty tool_name_to_mcp_server_name_mapping → 404.
  • None of these cover the cross-server collision (403) case.

Relevant log output

LiteLLM:ERROR: server.py - HTTPException in MCP tool call: 404: Tool 'list_items' not found
LiteLLM:ERROR: server.py - HTTPException in MCP tool call: 403: User not allowed to call this tool.

Which part of LiteLLM is this about?

MCP: servers, tools, OAuth

How are you deploying?

Docker

The two patches

Our patch+137 −22
litellm/proxy/_experimental/mcp_server/auth/user_api_key_auth_mcp.pyindex 18b7c27960..437faec40f 100644@@ -2161,14 +2161,17 @@ class MCPRequestHandler:         return list(reachable)      @staticmethod-    async def billing_auth_for_tool_call(auth: UserAPIKeyAuth, tool_name: str) -> UserAPIKeyAuth:+    async def billing_auth_for_tool_call(+        auth: UserAPIKeyAuth, tool_name: str, mcp_servers: Sequence[str] | None = None+    ) -> UserAPIKeyAuth:         """The auth object a tool call's SPEND should be recorded against.          ``auth`` unchanged for any non-admitted caller (key/JWT billing byte-identical). For an admitted         subject whose call is reached through a team's grant, a copy carrying that team's ``team_id`` and-        owning ``org_id`` so the team's budget accumulates and the right org is charged. Falls back to-        user-level attribution (rather than guessing a team) when the tool name does not resolve to a-        server, reusing the manager's own tool-name lookup."""+        owning ``org_id`` so the team's budget accumulates and the right org is charged. A request scoped+        to exactly one server (``mcp_servers``) is billed against that server, since the call is routed+        there; otherwise falls back to the manager's own tool-name lookup, and to user-level attribution+        (rather than guessing a team) when the tool name does not resolve to a server."""         if not is_mcp_admitted_user_subject(auth):             return auth         try:@@ -2176,7 +2179,29 @@ class MCPRequestHandler:                 global_mcp_server_manager,             ) -            server: Final = global_mcp_server_manager.get_mcp_server_from_tool_name(tool_name)+            from litellm.proxy._experimental.mcp_server.operations import (+                _get_allowed_mcp_servers_from_mcp_server_names,+            )++            # Same scope narrowing call_mcp_tool routes with (case-insensitive names, ids, access+            # groups, limited to the caller's allowed servers), so the billed server is the routed one.+            scoped_servers: Final = (+                await _get_allowed_mcp_servers_from_mcp_server_names(+                    mcp_servers=mcp_servers,+                    allowed_mcp_servers=[+                        s+                        for sid in await global_mcp_server_manager.get_allowed_mcp_servers(user_api_key_auth=auth)+                        if (s := global_mcp_server_manager.get_mcp_server_by_id(sid)) is not None+                    ],+                )+                if mcp_servers+                else []+            )+            server: Final = (+                scoped_servers[0]+                if len(scoped_servers) == 1+                else global_mcp_server_manager.get_mcp_server_from_tool_name(tool_name)+            )             if server is None:                 return auth             source: Final = await MCPRequestHandler.attributing_source_for_server(auth, server.server_id)litellm/proxy/_experimental/mcp_server/operations.pyindex 5087bc6df0..49340ea0dc 100644@@ -2512,6 +2512,13 @@ async def call_mcp_tool(                 detail="User not allowed to call this tool.",             ) +        # A scope that narrows to one server (``/{server_name}/mcp`` or ``x-mcp-servers``) names the+        # server an unprefixed tool belongs to; the process-wide tool-name mapping is last-listed-wins+        # across servers and empty until something lists, so it must not decide the target here.+        scoped_server_id: Final[str | None] = (+            allowed_mcp_servers[0].server_id if mcp_servers and len(allowed_mcp_servers) == 1 else None+        )+         # Delegate to execute_mcp_tool for execution         response = await execute_mcp_tool(             name=name,@@ -2528,6 +2535,7 @@ async def call_mcp_tool(             input_responses=input_responses,             request_state=request_state,             incoming_bearer_token=incoming_bearer_token,+            requested_server_id=scoped_server_id,             **kwargs,         )     except Exception as e:@@ -2954,7 +2962,7 @@ async def _execute_mcp_server_tool_call(                 # Authorization is unaffected: it ran before this, and the union is resolved                 # from the untouched auth object passed to call_mcp_tool below.                 user_api_key_dict=await MCPRequestHandler.billing_auth_for_tool_call(-                    user_api_key_auth, tool_name=params.name+                    user_api_key_auth, tool_name=params.name, mcp_servers=mcp_servers                 ),                 proxy_config=proxy_config,             )tests/unit/proxy/_experimental/mcp_server/auth/test_user_api_key_auth_mcp.pyindex 078fff0266..4dd434770b 100644@@ -8571,6 +8571,29 @@ class TestUserSubjectTeamUnion:         assert (billed.team_id, billed.org_id) == ("t-grant", "org-team")         assert (auth.team_id, auth.org_id) == (None, "org-user-primary"), "authz object must be untouched" +    async def test_single_server_scope_bills_the_server_in_scope_not_the_last_listed_owner_of_the_tool_name(self):+        """On /srv1/mcp an unprefixed ``list_items`` runs on srv1, so srv1's granting team is billed even+        when the process-wide tool-name mapping last saw ``list_items`` on srv2."""+        teams = {"t-one": _make_team("t-one", ["srv1"]), "t-two": _make_team("t-two", ["srv2"])}+        auth = _make_admitted_subject("sso-user")+        manager = self._manager_with(["srv1", "srv2"])+        manager.tool_name_to_mcp_server_name_mapping["list_items"] = "srv2"+        with (+            self._patch(teams_by_id=teams, user_teams=["t-one", "t-two"]),+            patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", manager),+        ):+            scoped = await MCPRequestHandler.billing_auth_for_tool_call(+                auth, tool_name="list_items", mcp_servers=["srv1"]+            )+            unscoped = await MCPRequestHandler.billing_auth_for_tool_call(auth, tool_name="list_items")+            # Routing matches the scope name case-insensitively; billing must land on the same server.+            scoped_other_case = await MCPRequestHandler.billing_auth_for_tool_call(+                auth, tool_name="list_items", mcp_servers=["SRV1"]+            )+        assert scoped.team_id == "t-one", "the scoped server's granting team must be billed"+        assert scoped_other_case.team_id == "t-one", "billing must match the scope the call is routed to"+        assert unscoped.team_id == "t-two", "without a scope the tool-name mapping still decides"+     async def test_own_grant_bills_the_user_not_a_team(self):         """A server the user's OWN grant reaches is not reached "through a team", so it bills the         user and their own org — attributing it to an unrelated team the user happens to belong totests/unit/proxy/_experimental/mcp_server/test_mcp_server.pyindex 3345683517..aa1c06d7c1 100644@@ -3016,6 +3016,10 @@ async def test_call_mcp_tool_uses_manager_permission_lookup():             "litellm.proxy._experimental.mcp_server.server.MCPRequestHandler.is_tool_allowed",             return_value=True,         ),+        patch(+            "litellm.proxy._experimental.mcp_server.operations._list_tools_before_first_call",+            new_callable=AsyncMock,+        ),     ):         mock_get_allowed.return_value = [mock_server.server_id]         mock_tool_registry.get_tool.return_value = None@@ -3029,24 +3033,20 @@ async def test_call_mcp_tool_uses_manager_permission_lookup():      assert result == expected_response     mock_get_allowed.assert_awaited_once()-    # We call `_get_mcp_server_from_tool_name` multiple times:-    # - for logging/metadata-    # - for resolving the server during dispatch-    # - and inside `call_tool` for guardrails/hooks-    # The exact count isn't important, only that it is used.-    assert mock_get_server.call_count >= 2-    # First call should use the prefixed tool name-    assert (-        mock_get_server.call_args_list[0][0][0]-        == f"{mock_server.name}/gmail_send_email"+    # "/" is not the tool prefix separator, so on the single-server scope the whole string is the+    # upstream tool name and the call is routed to the server in scope.+    dispatched = mock_handle_managed.await_args.kwargs+    assert (dispatched["server_name"], dispatched["name"]) == (+        mock_server.name,+        f"{mock_server.name}/gmail_send_email",     )   @pytest.mark.asyncio async def test_call_mcp_tool_resolves_unprefixed_tool_name_and_checks_permissions():     """-    Ensure `call_mcp_tool` correctly resolves the MCP server for an unprefixed tool-    name and enforces server-level permissions using that resolved server.+    Ensure `call_mcp_tool` resolves an unprefixed tool name on a single-server scope to the+    server in scope and enforces server-level permissions using that resolved server.     """     from litellm.proxy._experimental.mcp_server.server import (         call_mcp_tool,@@ -3092,12 +3092,16 @@ async def test_call_mcp_tool_resolves_unprefixed_tool_name_and_checks_permission             "litellm.proxy._experimental.mcp_server.server.MCPRequestHandler.is_tool_allowed",             return_value=True,         ) as mock_is_allowed,+        patch(+            "litellm.proxy._experimental.mcp_server.operations._list_tools_before_first_call",+            new_callable=AsyncMock,+        ),     ):         mock_get_allowed.return_value = [mock_server.server_id]         mock_tool_registry.get_tool.return_value = None         mock_handle_managed.return_value = expected_response -        # Call with UNPREFIXED tool name; server should be resolved via mapping+        # Call with UNPREFIXED tool name; server should be resolved from the scope         result = await call_mcp_tool(             name="gmail_send_email",             arguments={"body": "hello"},@@ -3106,11 +3110,11 @@ async def test_call_mcp_tool_resolves_unprefixed_tool_name_and_checks_permission      assert result == expected_response     mock_get_allowed.assert_awaited_once()-    # We should resolve the server at least once using the unprefixed name-    assert mock_get_server.call_count >= 1-    assert mock_get_server.call_args_list[0][0][0] == "gmail_send_email"+    dispatched = mock_handle_managed.await_args.kwargs+    assert (dispatched["server_name"], dispatched["name"]) == (mock_server.name, "gmail_send_email")     # Permissions check should be invoked with the resolved server name     mock_is_allowed.assert_called_once()+    assert mock_is_allowed.call_args.kwargs["server_name"] == mock_server.name   @pytest.mark.asynciotests/unit/proxy/_experimental/mcp_server/test_mcp_server_tool_calls_and_headers.pyindex ab6ab88209..dfb8ba0394 100644@@ -7670,6 +7670,61 @@ async def test_execute_mcp_tool_rest_server_id_lists_never_listed_server_first()     assert worker.dispatched["name"] == "add"  +def _shared_tool_name_server(name: str) -> MCPServer:+    return MCPServer(+        server_id=f"{name}-id",+        name=name,+        server_name=name,+        url=f"https://{name}.example.com/mcp",+        transport=MCPTransport.http,+        auth_type=MCPAuth.none,+    )+++@pytest.mark.asyncio+@pytest.mark.parametrize("mapping_owner", [None, "server_a"], ids=["cold_mapping", "other_server_listed_last"])+async def test_call_mcp_tool_unprefixed_name_on_single_server_path_runs_on_the_server_in_the_path(+    mapping_owner: str | None,+):+    """On /server_b/mcp an unprefixed tools/call must run on server_b whatever the process-wide+    tool-name mapping holds: cold it used to answer 404, and pointing at server_a (another server+    exposing the same tool name, listed last) it used to answer 403."""+    from litellm.proxy._experimental.mcp_server.operations import call_mcp_tool++    manager = mcp_operations.global_mcp_server_manager+    server_a = _shared_tool_name_server("server_a")+    server_b = _shared_tool_name_server("server_b")+    saved_mapping = dict(manager.tool_name_to_mcp_server_name_mapping)+    manager.tool_name_to_mcp_server_name_mapping.pop("list_items", None)+    if mapping_owner is not None:+        manager.tool_name_to_mcp_server_name_mapping["list_items"] = mapping_owner+    manager.registry[server_a.server_id] = server_a+    try:+        with (+            _worker_that_never_listed(server_b, upstream_tools=("list_items",)) as worker,+            patch.object(+                manager,+                "get_allowed_mcp_servers",+                new=AsyncMock(return_value=[server_a.server_id, server_b.server_id]),+            ),+            patch("litellm.proxy.proxy_server.proxy_logging_obj", _mock_mcp_proxy_logging()),+        ):+            await call_mcp_tool(+                name="list_items",+                arguments={},+                user_api_key_auth=UserAPIKeyAuth(api_key="sk-both-servers"),+                mcp_servers=["server_b"],+            )+    finally:+        for server in (server_a, server_b):+            manager.registry.pop(server.server_id, None)+            manager._listed_tools_by_server_id.pop(server.server_id, None)+        manager.tool_name_to_mcp_server_name_mapping.clear()+        manager.tool_name_to_mcp_server_name_mapping.update(saved_mapping)++    assert (worker.dispatched.get("server_name"), worker.dispatched.get("name")) == ("server_b", "list_items")++ @pytest.mark.asyncio async def test_execute_mcp_tool_unknown_tool_on_never_listed_server_lists_once_then_404s():     from litellm.proxy._experimental.mcp_server import server as mcp_module 
Merged fix · PR #46225+112 −27
litellm/proxy/_experimental/mcp_server/operations.pyindex 5087bc6df09..889ca709eb9 100644@@ -2451,6 +2451,20 @@ async def fire_mcp_tool_call_failure_logging(     )  +def _single_scoped_server(+    mcp_servers: Sequence[str] | None, allowed_mcp_servers: Sequence[MCPServer]+) -> MCPServer | None:+    """The one server a ``/{server_name}/mcp`` path or ``x-mcp-servers`` header scoped this call to.++    A bare tool name on such a request resolves against that server, the way a REST ``server_id``+    does, instead of against the per-process tool-name map, which stays empty for a server whose+    upstream only lists tools with the caller's own credentials until this process has listed it.+    """+    if mcp_servers is None or len(mcp_servers) != 1 or len(allowed_mcp_servers) != 1:+        return None+    return allowed_mcp_servers[0]++ @client @catalog_operation(lambda: global_mcp_server_manager) async def call_mcp_tool(@@ -2512,6 +2526,7 @@ async def call_mcp_tool(                 detail="User not allowed to call this tool.",             ) +        scoped_server: Final = _single_scoped_server(mcp_servers, allowed_mcp_servers)         # Delegate to execute_mcp_tool for execution         response = await execute_mcp_tool(             name=name,@@ -2528,6 +2543,7 @@ async def call_mcp_tool(             input_responses=input_responses,             request_state=request_state,             incoming_bearer_token=incoming_bearer_token,+            requested_server_id=scoped_server.server_id if scoped_server is not None else None,             **kwargs,         )     except Exception as e:tests/unit/proxy/_experimental/mcp_server/test_mcp_server.pyindex 3345683517b..de711d737d0 100644@@ -3000,11 +3000,7 @@ async def test_call_mcp_tool_uses_manager_permission_lookup():             "get_mcp_server_by_id",             return_value=mock_server,         ),-        patch.object(-            global_mcp_server_manager,-            "get_mcp_server_from_tool_name",-            return_value=mock_server,-        ) as mock_get_server,+        patch.object(global_mcp_server_manager, "server_exposes_tool", return_value=True),         patch(             "litellm.proxy._experimental.mcp_server.operations.global_mcp_tool_registry"         ) as mock_tool_registry,@@ -3029,24 +3025,18 @@ async def test_call_mcp_tool_uses_manager_permission_lookup():      assert result == expected_response     mock_get_allowed.assert_awaited_once()-    # We call `_get_mcp_server_from_tool_name` multiple times:-    # - for logging/metadata-    # - for resolving the server during dispatch-    # - and inside `call_tool` for guardrails/hooks-    # The exact count isn't important, only that it is used.-    assert mock_get_server.call_count >= 2-    # First call should use the prefixed tool name-    assert (-        mock_get_server.call_args_list[0][0][0]-        == f"{mock_server.name}/gmail_send_email"-    )+    # The request names exactly one server, so that server is the dispatch target+    # and the tool name reaches it untouched (the "/" is not a LiteLLM prefix).+    mock_handle_managed.assert_awaited_once()+    assert mock_handle_managed.await_args.kwargs["server_name"] == mock_server.name+    assert mock_handle_managed.await_args.kwargs["name"] == f"{mock_server.name}/gmail_send_email"   @pytest.mark.asyncio async def test_call_mcp_tool_resolves_unprefixed_tool_name_and_checks_permissions():     """-    Ensure `call_mcp_tool` correctly resolves the MCP server for an unprefixed tool-    name and enforces server-level permissions using that resolved server.+    Ensure `call_mcp_tool` resolves an unprefixed tool name on a request scoped to+    one server against that server and enforces server-level permissions with it.     """     from litellm.proxy._experimental.mcp_server.server import (         call_mcp_tool,@@ -3076,11 +3066,7 @@ async def test_call_mcp_tool_resolves_unprefixed_tool_name_and_checks_permission             "get_mcp_server_by_id",             return_value=mock_server,         ),-        patch.object(-            global_mcp_server_manager,-            "get_mcp_server_from_tool_name",-            return_value=mock_server,-        ) as mock_get_server,+        patch.object(global_mcp_server_manager, "server_exposes_tool", return_value=True),         patch(             "litellm.proxy._experimental.mcp_server.operations.global_mcp_tool_registry"         ) as mock_tool_registry,@@ -3097,7 +3083,7 @@ async def test_call_mcp_tool_resolves_unprefixed_tool_name_and_checks_permission         mock_tool_registry.get_tool.return_value = None         mock_handle_managed.return_value = expected_response -        # Call with UNPREFIXED tool name; server should be resolved via mapping+        # Call with UNPREFIXED tool name; the single server the request names is the target         result = await call_mcp_tool(             name="gmail_send_email",             arguments={"body": "hello"},@@ -3106,11 +3092,12 @@ async def test_call_mcp_tool_resolves_unprefixed_tool_name_and_checks_permission      assert result == expected_response     mock_get_allowed.assert_awaited_once()-    # We should resolve the server at least once using the unprefixed name-    assert mock_get_server.call_count >= 1-    assert mock_get_server.call_args_list[0][0][0] == "gmail_send_email"+    mock_handle_managed.assert_awaited_once()+    assert mock_handle_managed.await_args.kwargs["server_name"] == mock_server.name+    assert mock_handle_managed.await_args.kwargs["name"] == "gmail_send_email"     # Permissions check should be invoked with the resolved server name     mock_is_allowed.assert_called_once()+    assert mock_is_allowed.call_args.kwargs["server_name"] == mock_server.name   @pytest.mark.asynciotests/unit/proxy/_experimental/mcp_server/test_operations.pyindex dcc4eb1a570..af547ebf6c7 100644@@ -565,6 +565,88 @@ async def test_tools_call_warmup_does_not_consume_mcp_server_rpm() -> None:     assert [tool.name for tool in listing.tools] == ["echo"]  ++def _scoped_rig(+    monkeypatch: pytest.MonkeyPatch,+) -> tuple[MCPServer, MCPServer, AsyncMock, AsyncMock]:+    """Two config servers that both expose a bare ``list_rules`` on a manager that has listed neither."""+    from mcp.types import CallToolResult, TextContent++    from litellm.proxy import proxy_server+    from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager++    manager: Final = MCPServerManager()+    memory: Final = MCPServer(+        server_id="id-memory", name="memory_server", server_name="memory_server", transport=MCPTransport.http+    )+    other: Final = MCPServer(+        server_id="id-other", name="other_server", server_name="other_server", transport=MCPTransport.http+    )+    manager.config_mcp_servers = {server.server_id: server for server in (memory, other)}+    monkeypatch.setattr(proxy_server, "prisma_client", None)+    monkeypatch.setattr(operations, "global_mcp_server_manager", manager)+    monkeypatch.setattr(+        manager, "get_allowed_mcp_servers", AsyncMock(return_value=[memory.server_id, other.server_id])+    )+    monkeypatch.setattr(global_mcp_tool_registry, "published_tools", {})+    listing: Final = AsyncMock()+    monkeypatch.setattr(operations, "_get_tools_from_mcp_servers", listing)+    handled: Final = AsyncMock(+        return_value=CallToolResult(content=[TextContent(type="text", text="ok")], isError=False)+    )+    monkeypatch.setattr(operations, "_handle_managed_mcp_tool", handled)+    return memory, other, listing, handled+++@pytest.mark.asyncio+@pytest.mark.parametrize("scope", ["memory_server", "other_server"])+async def test_bare_tool_name_on_a_single_server_scope_routes_to_that_server_cold(+    monkeypatch: pytest.MonkeyPatch, scope: str+) -> None:+    """``/{server_name}/mcp`` (or ``x-mcp-servers`` naming one server) with the upstream's bare tool name+    must list and call the scoped server on a process whose tool-name map has never seen it, and when two+    servers share the bare name the scope decides (BerriAI/litellm#44831)."""+    memory, other, listing, handled = _scoped_rig(monkeypatch)+    expected: Final = memory if scope == "memory_server" else other++    async with operations.global_mcp_server_manager.catalog.operation():+        result: Final = await operations.call_mcp_tool(+            name="list_rules",+            arguments={},+            user_api_key_auth=UserAPIKeyAuth(api_key="sk-scoped"),+            mcp_servers=[scope],+        )++    assert result.is_error is False+    assert listing.await_args.kwargs["mcp_servers"] == [expected.server_id]+    assert handled.await_args.kwargs["server_name"] == expected.name+    assert handled.await_args.kwargs["name"] == "list_rules"+++@pytest.mark.asyncio+@pytest.mark.parametrize("mcp_servers", [None, ["memory_server", "other_server"]])+async def test_bare_tool_name_without_a_single_server_scope_is_still_unresolved_cold(+    monkeypatch: pytest.MonkeyPatch, mcp_servers: list[str] | None+) -> None:+    """The scope shortcut only applies when the request names exactly one server; an ambiguous bare name+    keeps today's answer rather than being guessed onto the first allowed server."""+    from fastapi import HTTPException++    _memory, _other, listing, handled = _scoped_rig(monkeypatch)++    async with operations.global_mcp_server_manager.catalog.operation():+        with pytest.raises(HTTPException) as unresolved:+            await operations.call_mcp_tool(+                name="list_rules",+                arguments={},+                user_api_key_auth=UserAPIKeyAuth(api_key="sk-scoped"),+                mcp_servers=mcp_servers,+            )++    assert unresolved.value.status_code == 404+    listing.assert_not_awaited()+    handled.assert_not_awaited()+ @pytest.mark.asyncio async def test_tools_call_pre_call_check_enforces_mcp_server_rpm() -> None:     from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager