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 1/2] =?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 b5fd93727..3f3216ac2 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): From 7163abbbe32896d7acfb468cb4afbc87e60a6e82 Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Mon, 9 Jun 2025 00:20:49 +0800 Subject: [PATCH 2/2] =?UTF-8?q?update:=E4=BF=AE=E5=A4=8Dwindows=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E6=97=A0=E6=B3=95=E4=BD=BF=E7=94=A8fcntl=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=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/utils/wakeup_word.py | 9 ++++----- main/xiaozhi-server/requirements.txt | 3 ++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/main/xiaozhi-server/core/utils/wakeup_word.py b/main/xiaozhi-server/core/utils/wakeup_word.py index 258f879bf..299290810 100644 --- a/main/xiaozhi-server/core/utils/wakeup_word.py +++ b/main/xiaozhi-server/core/utils/wakeup_word.py @@ -2,9 +2,8 @@ import os import yaml import time import hashlib -import fcntl +import portalocker from typing import Dict -from contextlib import contextmanager class FileLock: @@ -17,15 +16,15 @@ class FileLock: self.start_time = time.time() while True: try: - fcntl.flock(self.file, fcntl.LOCK_EX | fcntl.LOCK_NB) + portalocker.lock(self.file, portalocker.LOCK_EX | portalocker.LOCK_NB) return self.file - except IOError: + except portalocker.LockException: if time.time() - self.start_time > self.timeout: raise TimeoutError("获取文件锁超时") time.sleep(0.1) def __exit__(self, exc_type, exc_val, exc_tb): - fcntl.flock(self.file, fcntl.LOCK_UN) + portalocker.unlock(self.file) class WakeupWordsConfig: diff --git a/main/xiaozhi-server/requirements.txt b/main/xiaozhi-server/requirements.txt index dc5a2294b..3ffbcfa46 100755 --- a/main/xiaozhi-server/requirements.txt +++ b/main/xiaozhi-server/requirements.txt @@ -32,4 +32,5 @@ aioconsole==0.8.1 markitdown==0.1.1 mcp-proxy==0.6.0 PyJWT==2.8.0 -psutil==7.0.0 \ No newline at end of file +psutil==7.0.0 +portalocker==2.10.1 \ No newline at end of file