mirror of
https://github.com/FuQuan233/nonebot-plugin-llmchat.git
synced 2025-09-04 10:20:45 +00:00
♻️ 增加MCP服务器友好名称为空时的处理
This commit is contained in:
parent
318e5b91c1
commit
506024c8f5
3 changed files with 7 additions and 4 deletions
|
@ -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}
|
||||
|
|
|
@ -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配置"""
|
||||
|
|
|
@ -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资源")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue