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资源")