From 182acc0787423e34011fd01e76cf6cbdc6d0c7b5 Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Sun, 8 Jun 2025 15:51:57 +0800 Subject: [PATCH] =?UTF-8?q?update:=E6=9B=BF=E6=8D=A2=E6=8F=8F=E8=BF=B0?= =?UTF-8?q?=E9=87=8C=E6=B6=89=E5=8F=8A=E5=88=B0=E7=9A=84=E5=8E=9F=E5=A7=8B?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/core/handle/mcpHandle.py | 23 ++++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/main/xiaozhi-server/core/handle/mcpHandle.py b/main/xiaozhi-server/core/handle/mcpHandle.py index b5fd9372..3f3216ac 100644 --- a/main/xiaozhi-server/core/handle/mcpHandle.py +++ b/main/xiaozhi-server/core/handle/mcpHandle.py @@ -136,9 +136,6 @@ async def handle_mcp_message(conn, mcp_client: MCPClient, payload: dict): conn.logger.bind(tag=TAG).info( f"客户端MCP服务器信息: name={name}, version={version}" ) - await send_mcp_tools_list_request( - conn - ) # After initialization, request tool list return elif msg_id == 2: # mcpToolsListID @@ -177,6 +174,20 @@ async def handle_mcp_message(conn, mcp_client: MCPClient, payload: dict): await mcp_client.add_tool(new_tool) conn.logger.bind(tag=TAG).debug(f"客户端工具 #{i+1}: {name}") + # 替换所有工具描述中的工具名称 + for tool_data in mcp_client.tools.values(): + if "description" in tool_data: + description = tool_data["description"] + # 遍历所有工具名称进行替换 + for ( + sanitized_name, + original_name, + ) in mcp_client.name_mapping.items(): + description = description.replace( + original_name, sanitized_name + ) + tool_data["description"] = description + next_cursor = result.get("nextCursor", "") if next_cursor: conn.logger.bind(tag=TAG).info( @@ -222,8 +233,6 @@ async def send_mcp_initialize_message(conn): "token": token, } - conn.logger.bind(tag=TAG).info(f"视觉服务信息: {vision}") - payload = { "jsonrpc": "2.0", "id": 1, # mcpInitializeID @@ -345,7 +354,7 @@ async def call_mcp_tool( } conn.logger.bind(tag=TAG).info( - f"发送客户端mcp工具调用请求: {tool_name},参数: {args}" + f"发送客户端mcp工具调用请求: {actual_name},参数: {args}" ) await send_mcp_message(conn, payload) @@ -353,7 +362,7 @@ async def call_mcp_tool( # Wait for response or timeout raw_result = await asyncio.wait_for(result_future, timeout=timeout) conn.logger.bind(tag=TAG).info( - f"客户端mcp工具调用 {tool_name} 成功,原始结果: {raw_result}" + f"客户端mcp工具调用 {actual_name} 成功,原始结果: {raw_result}" ) if isinstance(raw_result, dict):