This commit is contained in:
Timothy Jaeryang Baek
2026-06-01 12:44:16 -07:00
parent 9035601bdb
commit 4297c02b12
2 changed files with 11 additions and 2 deletions
+9
View File
@@ -545,6 +545,15 @@ else:
except Exception:
AIOHTTP_CLIENT_TIMEOUT_TOOL_SERVER = AIOHTTP_CLIENT_TIMEOUT
# Timeout (in seconds) for the MCP session.initialize() handshake.
# The handshake performs a list-tools round-trip and can take tens of
# seconds on cold-start servers or servers exposing many tools.
MCP_INITIALIZE_TIMEOUT = os.getenv('MCP_INITIALIZE_TIMEOUT', '10')
try:
MCP_INITIALIZE_TIMEOUT = int(MCP_INITIALIZE_TIMEOUT)
except (ValueError, TypeError):
MCP_INITIALIZE_TIMEOUT = 10
####################################
# AIOHTTP Connection Pool
+2 -2
View File
@@ -11,7 +11,7 @@ from mcp import ClientSession
from mcp.client.auth import OAuthClientProvider, TokenStorage
from mcp.client.streamable_http import streamablehttp_client
from mcp.shared.auth import OAuthClientInformationFull, OAuthClientMetadata, OAuthToken
from open_webui.env import AIOHTTP_CLIENT_SESSION_TOOL_SERVER_SSL, AIOHTTP_CLIENT_TIMEOUT_TOOL_SERVER
from open_webui.env import AIOHTTP_CLIENT_SESSION_TOOL_SERVER_SSL, AIOHTTP_CLIENT_TIMEOUT_TOOL_SERVER, MCP_INITIALIZE_TIMEOUT
def _build_httpx_client(headers=None, timeout=None, auth=None, verify=True):
@@ -69,7 +69,7 @@ class MCPClient:
self._session_context = ClientSession(read_stream, write_stream) # pylint: disable=W0201
self.session = await exit_stack.enter_async_context(self._session_context)
with anyio.fail_after(10):
with anyio.fail_after(MCP_INITIALIZE_TIMEOUT):
await self.session.initialize()
self.exit_stack = exit_stack.pop_all()
except Exception as e: