**fix(mcp): Remove default timeout for HTTP transport to avoid tool timeout conflicts**

Always provide an explicit httpx client to prevent MCP HTTP transport from inheriting httpx's default 5-second timeout, thereby avoiding conflicts with the upper layer tool's timeout settings.
This commit is contained in:
dulltackle
2026-02-24 01:26:56 +08:00
parent 2f573e591b
commit f8dc6fafa9

View File

@@ -69,20 +69,18 @@ async def connect_mcp_servers(
read, write = await stack.enter_async_context(stdio_client(params)) read, write = await stack.enter_async_context(stdio_client(params))
elif cfg.url: elif cfg.url:
from mcp.client.streamable_http import streamable_http_client from mcp.client.streamable_http import streamable_http_client
if cfg.headers: # Always provide an explicit httpx client so MCP HTTP transport does not
http_client = await stack.enter_async_context( # inherit httpx's default 5s timeout and preempt the higher-level tool timeout.
httpx.AsyncClient( http_client = await stack.enter_async_context(
headers=cfg.headers, httpx.AsyncClient(
follow_redirects=True headers=cfg.headers or None,
) follow_redirects=True,
) timeout=None,
read, write, _ = await stack.enter_async_context(
streamable_http_client(cfg.url, http_client=http_client)
)
else:
read, write, _ = await stack.enter_async_context(
streamable_http_client(cfg.url)
) )
)
read, write, _ = await stack.enter_async_context(
streamable_http_client(cfg.url, http_client=http_client)
)
else: else:
logger.warning("MCP server '{}': no command or url configured, skipping", name) logger.warning("MCP server '{}': no command or url configured, skipping", name)
continue continue