Expose create_mcp_http_client and McpHttpClientFactory from mcp.client.streamable_http
Closed
PR
2mo ago+28+28+01234567890123456789-0-0-0123456789
Summary
Implements the suggestion in #3238: re-export the HTTP-client helpers from a public module so that customizing the streamable-HTTP client (headers/auth/timeout) no longer requires importing the private mcp.shared._httpx_utils.
Since 2.0 removed the headers/timeout/auth kwargs from streamable_http_client, the only supported way to build a conforming httpx2.AsyncClient is create_mcp_http_client — but it, the McpHttpClientFactory protocol, and the default-timeout constants were only reachable via the private module.
Changes
src/mcp/client/streamable_http.py— re-exportcreate_mcp_http_client,McpHttpClientFactory,MCP_DEFAULT_TIMEOUT, andMCP_DEFAULT_SSE_READ_TIMEOUTfrom the same module that already exposesstreamable_http_client, and add a module-level__all__declaring the public surface. The redundant-alias /__all__forms keep this a pure re-export (no behavior change) and satisfy ruff's F401.tests/shared/test_httpx_utils.py— newtest_public_reexport_from_streamable_httpasserting the public names resolve to the same objects as the private ones.docs/migration.md— point the "build the http_client" guidance at the public import path, with an example.
Notes
- This is intentionally additive: nothing is removed or renamed, the private module still works, and existing imports are unaffected. No external code uses
import *from this module (tests import names explicitly), so adding__all__does not change any current consumer. - I scoped the re-export to
mcp.client.streamable_http(rather than a broadermcp.shared) because that's wherestreamable_http_clientlives and whereMcpHttpClientFactorywas importable from in 1.x — happy to also/instead export from elsewhere if you'd prefer a different home.
Fixes #3238
Testing
tests/shared/test_httpx_utils.py— 3 passed (2 pre-existing + 1 new).ruff checkandruff format --checkclean on the changed files.