From 506024c8f59d5b48f99bfca9c3dcfd8561ad486e Mon Sep 17 00:00:00 2001 From: FuQuan233 Date: Sat, 26 Apr 2025 22:45:53 +0800 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=E5=A2=9E=E5=8A=A0MCP?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E5=8F=8B=E5=A5=BD=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E4=B8=BA=E7=A9=BA=E6=97=B6=E7=9A=84=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonebot_plugin_llmchat/__init__.py | 5 ++++- nonebot_plugin_llmchat/config.py | 4 ++-- nonebot_plugin_llmchat/mcpclient.py | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/nonebot_plugin_llmchat/__init__.py b/nonebot_plugin_llmchat/__init__.py index 37bd29f..c2a803d 100644 --- a/nonebot_plugin_llmchat/__init__.py +++ b/nonebot_plugin_llmchat/__init__.py @@ -243,7 +243,10 @@ async def process_messages(group_id: int): """ if preset.support_mcp: systemPrompt += "你也可以使用一些工具,下面是关于这些工具的额外说明:\n" - systemPrompt += "\n".join([mcp_config.addtional_prompt for mcp_config in plugin_config.mcp_servers.values()]) + for mcp_name, mcp_config in plugin_config.mcp_servers.items(): + if mcp_config.addtional_prompt: + systemPrompt += f"{mcp_name}:{mcp_config.addtional_prompt}" + systemPrompt += "\n" messages: list[ChatCompletionMessageParam] = [ {"role": "system", "content": systemPrompt} diff --git a/nonebot_plugin_llmchat/config.py b/nonebot_plugin_llmchat/config.py index 5f316f8..c802a8d 100644 --- a/nonebot_plugin_llmchat/config.py +++ b/nonebot_plugin_llmchat/config.py @@ -21,8 +21,8 @@ class MCPServerConfig(BaseModel): url: str | None = Field(None, description="sse模式下MCP服务器地址") # 额外字段 - friendly_name: str = Field("", description="MCP服务器友好名称") - addtional_prompt: str = Field("", description="额外提示词") + friendly_name: str | None = Field(None, description="MCP服务器友好名称") + addtional_prompt: str | None = Field(None, description="额外提示词") class ScopedConfig(BaseModel): """LLM Chat Plugin配置""" diff --git a/nonebot_plugin_llmchat/mcpclient.py b/nonebot_plugin_llmchat/mcpclient.py index 3ea7d3d..7031d34 100644 --- a/nonebot_plugin_llmchat/mcpclient.py +++ b/nonebot_plugin_llmchat/mcpclient.py @@ -70,7 +70,7 @@ class MCPClient: def get_friendly_name(self, tool_name: str): server_name, real_tool_name = tool_name.split("___") - return self.server_config[server_name].friendly_name + " - " + real_tool_name + return (self.server_config[server_name].friendly_name or server_name) + " - " + real_tool_name async def cleanup(self): logger.debug("正在清理MCPClient资源")