From e542deabdb71a86431dc1a9cc43344c9545a1ed7 Mon Sep 17 00:00:00 2001 From: FuQuan <87348379+FuQuan233@users.noreply.github.com> Date: Fri, 7 Nov 2025 11:58:16 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E5=90=88=E5=B9=B6=E7=A7=81?= =?UTF-8?q?=E8=81=8A=E6=8C=87=E4=BB=A4=EF=BC=8C=E6=9B=B4=E6=96=B0=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=9D=83=E9=99=90=E5=92=8C=E7=8A=B6=E6=80=81=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonebot_plugin_llmchat/mcpclient.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/nonebot_plugin_llmchat/mcpclient.py b/nonebot_plugin_llmchat/mcpclient.py index 4d38f0a..9a53865 100644 --- a/nonebot_plugin_llmchat/mcpclient.py +++ b/nonebot_plugin_llmchat/mcpclient.py @@ -106,7 +106,7 @@ class MCPClient: return SessionContext() - async def get_available_tools(self): + async def get_available_tools(self, is_group: bool): """获取可用工具列表,使用缓存机制""" if self._tools_cache is not None: logger.debug("返回缓存的工具列表") @@ -115,10 +115,11 @@ class MCPClient: logger.info(f"初始化工具列表缓存,需要连接{len(self.server_config)}个服务器") available_tools = [] - # 添加OneBot内置工具 - onebot_tools = self.onebot_tools.get_available_tools() - available_tools.extend(onebot_tools) - logger.debug(f"添加了{len(onebot_tools)}个OneBot内置工具") + if is_group: + # 添加OneBot内置工具,仅在群聊中可用 + onebot_tools = self.onebot_tools.get_available_tools() + available_tools.extend(onebot_tools) + logger.debug(f"添加了{len(onebot_tools)}个OneBot内置工具") # 添加MCP服务器工具 for server_name in self.server_config.keys():