From bdb6d3c093583a2e908c0a2a2037b19b9f342f33 Mon Sep 17 00:00:00 2001 From: 3030332422 <3030332422@qq.com> Date: Tue, 26 Aug 2025 11:45:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E2=80=9C=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E7=AB=AFmcp=20=E6=9C=AA=E6=B7=BB=E5=8A=A0=E5=88=B0=20?= =?UTF-8?q?function=20=E5=88=97=E8=A1=A8=E4=B8=AD=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/providers/tools/server_mcp/mcp_executor.py | 2 +- .../core/providers/tools/server_mcp/mcp_manager.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/main/xiaozhi-server/core/providers/tools/server_mcp/mcp_executor.py b/main/xiaozhi-server/core/providers/tools/server_mcp/mcp_executor.py index 9ae15d4b..ee0bcb2a 100644 --- a/main/xiaozhi-server/core/providers/tools/server_mcp/mcp_executor.py +++ b/main/xiaozhi-server/core/providers/tools/server_mcp/mcp_executor.py @@ -18,8 +18,8 @@ class ServerMCPExecutor(ToolExecutor): """初始化MCP管理器""" if not self._initialized: self.mcp_manager = ServerMCPManager(self.conn) - await self.mcp_manager.initialize_servers() self._initialized = True + await self.mcp_manager.initialize_servers() async def execute( self, conn, tool_name: str, arguments: Dict[str, Any] diff --git a/main/xiaozhi-server/core/providers/tools/server_mcp/mcp_manager.py b/main/xiaozhi-server/core/providers/tools/server_mcp/mcp_manager.py index 52ab2b79..cf3deb21 100644 --- a/main/xiaozhi-server/core/providers/tools/server_mcp/mcp_manager.py +++ b/main/xiaozhi-server/core/providers/tools/server_mcp/mcp_manager.py @@ -68,6 +68,9 @@ class ServerMCPManager: # 输出当前支持的服务端MCP工具列表 if hasattr(self.conn, "func_handler") and self.conn.func_handler: + # 刷新工具缓存以确保服务端MCP工具被正确加载 + if hasattr(self.conn.func_handler, "tool_manager"): + self.conn.func_handler.tool_manager.refresh_tools() self.conn.func_handler.current_support_functions() def get_all_tools(self) -> List[Dict[str, Any]]: