Skip to content

Commit 4653773

Browse files
fix(mcp): match alias/server_name in _resolve_mcp_server_for_tool_call
The registry lookup in _resolve_mcp_server_for_tool_call previously only compared candidate.name against the provided server_name, but tool name prefixes can be derived from a server's alias or server_name (see get_server_prefix). When the tool→server mapping is empty/stale (cold start, dynamic tools), the lookup would fail for alias-configured servers even though get_mcp_server_by_name (used by the REST path) matches alias, server_name, and name. Match the same priority of identifiers in both the registry pass and the unprefixed fallback so the MCP protocol call_tool path is consistent with the REST path. Co-authored-by: Yassin Kortam <yassin@berri.ai>
1 parent d2438b5 commit 4653773

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

litellm/proxy/_experimental/mcp_server/mcp_server_manager.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2828,20 +2828,30 @@ def _resolve_mcp_server_for_tool_call(
28282828
prefixed_tool_name = add_server_prefix_to_name(name, server_name)
28292829
mcp_server = self._get_mcp_server_from_tool_name(prefixed_tool_name)
28302830
resolved_by_server_name_only = False
2831+
normalized_server_name = normalize_server_name(server_name)
2832+
2833+
def _candidate_matches_server_name(candidate: MCPServer) -> bool:
2834+
for identifier in (
2835+
candidate.alias,
2836+
candidate.server_name,
2837+
candidate.name,
2838+
):
2839+
if identifier and normalize_server_name(identifier) == (
2840+
normalized_server_name
2841+
):
2842+
return True
2843+
return False
2844+
28312845
if mcp_server is None:
28322846
for candidate in self.get_registry().values():
2833-
if normalize_server_name(candidate.name) == normalize_server_name(
2834-
server_name
2835-
):
2847+
if _candidate_matches_server_name(candidate):
28362848
mcp_server = candidate
28372849
resolved_by_server_name_only = True
28382850
break
28392851
if mcp_server is None:
28402852
fallback = self._get_mcp_server_from_tool_name(name)
28412853
if fallback is not None and (
2842-
not server_name
2843-
or normalize_server_name(fallback.name)
2844-
== normalize_server_name(server_name)
2854+
not server_name or _candidate_matches_server_name(fallback)
28452855
):
28462856
mcp_server = fallback
28472857
if mcp_server is None:

0 commit comments

Comments
 (0)