Expose create_mcp_http_client and McpHttpClientFactory from mcp.client.streamable_http - #3239
Open
ProgrammerPlus1998 wants to merge 2 commits into
Conversation
…e_http Customizing the streamable-HTTP client's headers/auth/timeout requires building an httpx2.AsyncClient, but the standardized factory (create_mcp_http_client), the McpHttpClientFactory protocol, and the default timeout constants only lived in the private mcp.shared._httpx_utils module. Re-export them from the public mcp.client.streamable_http module — where streamable_http_client itself lives — so building a custom client does not require importing a private module. Add a regression test asserting the public names resolve to the same objects as the private ones, and point the migration guide at the public import path. Refs modelcontextprotocol#3238
There was a problem hiding this comment.
All reported issues were addressed across 3 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Review feedback: the module-level __all__ added previously would have replaced Python's implicit star-import behavior and dropped previously exported names (SessionMessageOrError, DEFAULT_RECONNECTION_DELAY_MS, etc.) for any `from mcp.client.streamable_http import *` consumer. Drop __all__ and mark the re-exports with redundant aliases instead, which is additive only — the star-import surface is unchanged apart from the newly exported names. Refs modelcontextprotocol#3238
Author
|
Good catch — fixed. I removed the module-level Verified locally that the star-import surface is unchanged apart from the newly exported names: diffing |
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
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/authkwargs fromstreamable_http_client, the only supported way to build a conforminghttpx2.AsyncClientiscreate_mcp_http_client— but it, theMcpHttpClientFactoryprotocol, 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
import *from this module (tests import names explicitly), so adding__all__does not change any current consumer.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.