fix(mcpplugin): use create_mcp_http_client for streamable HTTP transport#315
Open
sharath-tursio wants to merge 1 commit intomicrosoft:mainfrom
Open
fix(mcpplugin): use create_mcp_http_client for streamable HTTP transport#315sharath-tursio wants to merge 1 commit intomicrosoft:mainfrom
sharath-tursio wants to merge 1 commit intomicrosoft:mainfrom
Conversation
When headers are provided (e.g. Authorization: Bearer), the transport was creating a bare httpx.AsyncClient with the default 5s timeout, causing MCP tool calls to silently time out on slow backends. Use create_mcp_http_client() which sets a 30s connect timeout and 300s read timeout — the same defaults the MCP SDK uses when no http_client is provided.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When headers are provided to create_streamable_http_transport (e.g. an
Authorization: Bearer token for authenticated MCP servers), the transport
creates a bare httpx.AsyncClient(headers=...) which inherits httpx's default
timeout of 5 seconds for all operations.
This causes MCP tool calls to silently time out on any backend that takes longer
than 5 seconds to respond — which is common for LLM-backed or database-backed
MCP servers. The request hangs with no error, and the tool result is never
returned to the agent.
Notably, when no headers are passed, the code falls through to
streamable_http_client(url) which internally calls create_mcp_http_client()
— giving a 30s connect timeout and 300s read timeout. So unauthenticated
servers work fine, but authenticated ones silently fail.
Fix
Replace the conditional httpx.AsyncClient / streamable_http_client branches
with a single call using create_mcp_http_client(headers=...), which applies
the correct MCP-recommended timeouts consistently regardless of whether headers
are present.
Before
if resolved_headers:
async with httpx.AsyncClient(headers=resolved_headers) as http_client: # 5s timeout!
async with streamable_http_client(url, http_client=http_client) as (r, w, _):
yield r, w
else:
async with streamable_http_client(url) as (r, w, _): # 300s read timeout
yield r, w
After
async with create_mcp_http_client(headers=resolved_headers or None) as http_client:
async with streamable_http_client(url, http_client=http_client) as (r, w, _):
yield r, w
Impact