Skip to content

fix(mcpplugin): use create_mcp_http_client for streamable HTTP transport#315

Open
sharath-tursio wants to merge 1 commit intomicrosoft:mainfrom
sharath-tursio:fix/mcpplugin-streamable-http-timeout
Open

fix(mcpplugin): use create_mcp_http_client for streamable HTTP transport#315
sharath-tursio wants to merge 1 commit intomicrosoft:mainfrom
sharath-tursio:fix/mcpplugin-streamable-http-timeout

Conversation

@sharath-tursio
Copy link

@sharath-tursio sharath-tursio commented Mar 16, 2026

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

  • No breaking changes — behaviour is identical for unauthenticated servers
  • Authenticated MCP servers (Bearer token, API key headers, etc.) now get the same 300s read timeout as unauthenticated ones
  • Simplifies the code by removing the if/else branch

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant