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
89baec6abc
commit
5014d3014b
2 changed files with 10 additions and 3 deletions
|
@ -380,7 +380,7 @@ async def process_messages(group_id: int):
|
|||
new_messages.append({
|
||||
"role": "tool",
|
||||
"tool_call_id": tool_call.id,
|
||||
"content": str(result.content)
|
||||
"content": str(result)
|
||||
})
|
||||
|
||||
# 将工具调用的结果交给 LLM
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from contextlib import AsyncExitStack
|
||||
import asyncio
|
||||
|
||||
from mcp import ClientSession, StdioServerParameters
|
||||
from mcp.client.sse import sse_client
|
||||
|
@ -64,9 +65,15 @@ class MCPClient:
|
|||
server_name, real_tool_name = tool_name.split("___")
|
||||
logger.info(f"正在服务器[{server_name}]上调用工具[{real_tool_name}]")
|
||||
session = self.sessions[server_name]
|
||||
response = await session.call_tool(real_tool_name, tool_args)
|
||||
try:
|
||||
response = await asyncio.wait_for(
|
||||
session.call_tool(real_tool_name, tool_args), timeout=10
|
||||
)
|
||||
except asyncio.TimeoutError:
|
||||
logger.error(f"调用工具[{real_tool_name}]超时")
|
||||
return f"调用工具[{real_tool_name}]超时"
|
||||
logger.debug(f"工具[{real_tool_name}]调用完成,响应: {response}")
|
||||
return response
|
||||
return response.content
|
||||
|
||||
def get_friendly_name(self, tool_name: str):
|
||||
server_name, real_tool_name = tool_name.split("___")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue