Skip to content

Commit 8b26103

Browse files
authored
fix: improve server name parsing in tool calls (#65)
1 parent 504e73a commit 8b26103

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/mcp_agent/mcp/mcp_aggregator.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,17 @@ async def call_tool(
267267
local_tool_name: str = None
268268

269269
if SEP in name: # Namespaced tool name
270-
server_name, local_tool_name = name.split(SEP, 1)
270+
parts = name.split(SEP)
271+
272+
for i in range(len(parts) - 1, 0, -1):
273+
potential_server_name = SEP.join(parts[:i])
274+
if potential_server_name in self.server_names:
275+
server_name = potential_server_name
276+
local_tool_name = SEP.join(parts[i:])
277+
break
278+
279+
if server_name is None:
280+
server_name, local_tool_name = name.split(SEP, 1)
271281
else:
272282
# Assume un-namespaced, loop through all servers to find the tool. First match wins.
273283
for _, tools in self._server_to_tool_map.items():

0 commit comments

Comments
 (0)