Conversation
…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
4 tasks
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>
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.
Summary
Switches MCP HTTP transport from the deprecated
streamablehttp_client()to the newstreamable_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_HTTPflag, 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 inasync with httpx.AsyncClient(...).Fix 3: Match SDK defaults exactly
Built the httpx client to match
create_mcp_http_client()defaults:follow_redirects=Truehttpx.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