Skip to content

Commit 343ef32

Browse files
author
LiryLee
committed
fix: prevent MCP tool name collision by prefixing with server name
When multiple MCP servers expose tools with the same name (e.g., ), selecting one would inadvertently select the other because both backend registration and the frontend-facing API used the raw tool name without any server identifier. Fix: - MCPTool.__init__: prefix tool name with so each tool gets a unique identifier in func_list - ToolsService.get_mcp_servers: return prefixed names in the server info so the frontend can match correctly with availableTools The actual MCP call still uses the original tool name (self.mcp_tool.name), so server communication is unaffected.
1 parent 372b9f5 commit 343ef32

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

astrbot/core/agent/mcp_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ def __init__(
686686
self, mcp_tool: mcp.Tool, mcp_client: MCPClient, mcp_server_name: str, **kwargs
687687
) -> None:
688688
super().__init__(
689-
name=mcp_tool.name,
689+
name=f"{mcp_server_name}:{mcp_tool.name}",
690690
description=mcp_tool.description or "",
691691
parameters=_normalize_mcp_input_schema(mcp_tool.inputSchema),
692692
)

astrbot/dashboard/services/tools_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def get_mcp_servers(self) -> list[dict]:
7979
for name_key, runtime in self.tool_mgr.mcp_server_runtime_view.items():
8080
if name_key == name:
8181
mcp_client = runtime.client
82-
server_info["tools"] = [tool.name for tool in mcp_client.tools]
82+
server_info["tools"] = [f"{name}:{tool.name}" for tool in mcp_client.tools]
8383
server_info["errlogs"] = mcp_client.server_errlogs
8484
break
8585
else:

0 commit comments

Comments
 (0)