Skip to content

fix(tools): use non-deprecated streamable_http_client for MCP HTTP transport (salvage #3391)#3646

Merged
teknium1 merged 1 commit intomainfrom
hermes/hermes-0d76d7cd
Mar 29, 2026
Merged

fix(tools): use non-deprecated streamable_http_client for MCP HTTP transport (salvage #3391)#3646
teknium1 merged 1 commit intomainfrom
hermes/hermes-0d76d7cd

Conversation

@teknium1
Copy link
Copy Markdown
Contributor

Summary

Switches MCP HTTP transport from the deprecated streamablehttp_client() to the new streamable_http_client() API introduced in mcp v1.24.0 (PR modelcontextprotocol/python-sdk#1177).

Based on PR #3391 by @HenkDz (authorship preserved), with three fixes applied after deep-diving the SDK source:

Fix 1: Backward compat with older mcp versions

The original PR imported both functions in one line — breaks on mcp < 1.24.0 (our pin is >=1.2.0). Now uses separate try/except imports with a _MCP_NEW_HTTP flag, gracefully falling back to the deprecated API on older SDK versions.

Fix 2: httpx.AsyncClient lifecycle management

The new SDK API explicitly skips closing caller-provided clients (if not client_provided: await stack.enter_async_context(client) in the SDK source). The original PR created the client but never closed it — connection pool leak. Now wrapped in async with httpx.AsyncClient(...).

Fix 3: Match SDK defaults exactly

Built the httpx client to match create_mcp_http_client() defaults:

  • follow_redirects=True
  • httpx.Timeout(connect_timeout, read=300.0) (300s read timeout for SSE streams)

Test plan

  • pytest tests/tools/test_mcp_tool.py tests/tools/test_mcp_oauth.py tests/tools/test_mcp_probe.py — 172 passed
  • Full suite: 6552 passed, 0 failed

…ansport

Switch MCP HTTP transport from the deprecated streamablehttp_client()
(mcp < 1.24.0) to the new streamable_http_client() API that accepts a
pre-built httpx.AsyncClient.

Changes vs the original PR #3391:
- Separate try/except imports so mcp < 1.24.0 doesn't break (graceful
  fallback to deprecated API instead of losing HTTP MCP entirely)
- Wrap httpx.AsyncClient in async-with for proper lifecycle management
  (the new SDK API explicitly skips closing caller-provided clients)
- Match SDK's own create_mcp_http_client defaults: follow_redirects=True,
  Timeout(connect_timeout, read=300.0)
- Keep deprecated code path as fallback for older SDK versions
@teknium1 teknium1 merged commit 3e11570 into main Mar 29, 2026
2 checks passed
angelburgosrosado pushed a commit to angelburgosrosado/hermes-agent that referenced this pull request Apr 27, 2026
…ansport (NousResearch#3646)

Switch MCP HTTP transport from the deprecated streamablehttp_client()
(mcp < 1.24.0) to the new streamable_http_client() API that accepts a
pre-built httpx.AsyncClient.

Changes vs the original PR NousResearch#3391:
- Separate try/except imports so mcp < 1.24.0 doesn't break (graceful
  fallback to deprecated API instead of losing HTTP MCP entirely)
- Wrap httpx.AsyncClient in async-with for proper lifecycle management
  (the new SDK API explicitly skips closing caller-provided clients)
- Match SDK's own create_mcp_http_client defaults: follow_redirects=True,
  Timeout(connect_timeout, read=300.0)
- Keep deprecated code path as fallback for older SDK versions

Co-authored-by: HenkDz <HenkDz@users.noreply.github.com>
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.

2 participants