mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-05 02:41:34 +00:00
fix: MCP tool calls ignore AIOHTTP_CLIENT_TIMEOUT_TOOL_SERVER (#31641)
A tool call to an MCP server had no time limit, so a server that hung kept the chat waiting until a reverse proxy or the server itself closed the connection, even with AIOHTTP_CLIENT_TIMEOUT_TOOL_SERVER set. The call now stops after the configured number of seconds and the model sees the timeout as a tool error, which is how OpenAPI tool servers already behave. When the variable is unset it falls back to AIOHTTP_CLIENT_TIMEOUT, and with neither set (or a value of 0 or below) MCP tool calls still have no time limit. Fixes #31640
This commit is contained in:
parent
3819dc2793
commit
c1f245845c
1 changed files with 6 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import asyncio
|
||||
import logging
|
||||
from contextlib import AsyncExitStack
|
||||
from datetime import timedelta
|
||||
from typing import Optional
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
|
@ -116,7 +117,11 @@ class MCPClient:
|
|||
if not self.session:
|
||||
raise RuntimeError('MCP client is not connected.')
|
||||
|
||||
result = await self.session.call_tool(function_name, function_args)
|
||||
tool_call_timeout = None
|
||||
if AIOHTTP_CLIENT_TIMEOUT_TOOL_SERVER is not None and AIOHTTP_CLIENT_TIMEOUT_TOOL_SERVER > 0:
|
||||
tool_call_timeout = timedelta(seconds=AIOHTTP_CLIENT_TIMEOUT_TOOL_SERVER)
|
||||
|
||||
result = await self.session.call_tool(function_name, function_args, read_timeout_seconds=tool_call_timeout)
|
||||
if not result:
|
||||
raise Exception('No result returned from MCP tool call.')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue