From 7094548ecfae997a8b2f021f3415d40c89935dd8 Mon Sep 17 00:00:00 2001 From: 3030332422 <3030332422@qq.com> Date: Fri, 16 Jan 2026 18:04:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=BC=80=E6=9C=BA?= =?UTF-8?q?=E7=AB=8B=E5=88=BB=E5=94=A4=E9=86=92=E5=AF=BC=E8=87=B4=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E7=AB=AF=20MCP=20=E5=B7=A5=E5=85=B7=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E4=B8=BA=E7=A9=BA=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/core/handle/helloHandle.py | 5 +---- .../core/providers/tools/device_mcp/mcp_handler.py | 5 +++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/main/xiaozhi-server/core/handle/helloHandle.py b/main/xiaozhi-server/core/handle/helloHandle.py index 129b0aa7..cda7d17f 100644 --- a/main/xiaozhi-server/core/handle/helloHandle.py +++ b/main/xiaozhi-server/core/handle/helloHandle.py @@ -11,8 +11,7 @@ from core.handle.sendAudioHandle import sendAudioMessage, send_tts_message from core.utils.util import remove_punctuation_and_length, opus_datas_to_wav_bytes from core.providers.tools.device_mcp import ( MCPClient, - send_mcp_initialize_message, - send_mcp_tools_list_request, + send_mcp_initialize_message ) TAG = __name__ @@ -56,8 +55,6 @@ async def handleHelloMessage(conn, msg_json): conn.mcp_client = MCPClient() # 发送初始化 asyncio.create_task(send_mcp_initialize_message(conn)) - # 发送mcp消息,获取tools列表 - asyncio.create_task(send_mcp_tools_list_request(conn)) await conn.websocket.send(json.dumps(conn.welcome_msg)) diff --git a/main/xiaozhi-server/core/providers/tools/device_mcp/mcp_handler.py b/main/xiaozhi-server/core/providers/tools/device_mcp/mcp_handler.py index 457b22fc..d41c7adb 100644 --- a/main/xiaozhi-server/core/providers/tools/device_mcp/mcp_handler.py +++ b/main/xiaozhi-server/core/providers/tools/device_mcp/mcp_handler.py @@ -141,6 +141,11 @@ async def handle_mcp_message(conn, mcp_client: MCPClient, payload: dict): logger.bind(tag=TAG).debug( f"客户端MCP服务器信息: name={name}, version={version}" ) + + await asyncio.sleep(1) + logger.bind(tag=TAG).debug("初始化完成,开始请求MCP工具列表") + await send_mcp_tools_list_request(conn) + return elif msg_id == 2: # mcpToolsListID