Expose create_mcp_http_client and McpHttpClientFactory as public API (2.0 made them private-only)
Summary
Customizing the HTTP client for streamable_http_client (custom headers, auth, timeout, proxy, etc.) is a common and legitimate need, but as of 2.0.0 the only supported way to build a conforming client is through helpers that live in the private module mcp.shared._httpx_utils. Users are therefore forced to depend on a private API.
What changed in 2.0
In 1.x, streamable_http_client accepted convenience kwargs directly:
streamable_http_client(url, headers=..., timeout=..., sse_read_timeout=..., auth=...)
2.0 (via #2972, which replaced httpx/httpx-sse with httpx2) removed those kwargs. The signature is now:
async def streamable_http_client(
url: str,
*,
http_client: httpx2.AsyncClient | None = None,
terminate_on_close: bool = True,
) -> ...
So the only way to pass custom headers/auth/timeout is to build an httpx2.AsyncClient yourself and pass it as http_client=. The standardized factory for doing so is create_mcp_http_client — but it is only available at the private path:
from mcp.shared._httpx_utils import create_mcp_http_client # private module
The same applies to McpHttpClientFactory: in 1.x it was importable from the public mcp.client.streamable_http, but in 2.0 it is defined in mcp.shared._httpx_utils and is no longer re-exported from any public module.
Why this is a problem
- "Connect to an MCP server that requires auth headers / a custom timeout / a proxy" is a standard use case, not an edge case.
- The leading underscore on
mcp.shared._httpx_utilssignals "private, may change without notice", so every downstream project that needs a custom client has to take on that fragility. - It's inconsistent: the consumption side (
streamable_http_client(url, http_client=...)) is public, but the construction side (create_mcp_http_client,McpHttpClientFactory) is private.
Suggestion
Re-export create_mcp_http_client and McpHttpClientFactory from a public module — e.g. mcp.client.streamable_http (where McpHttpClientFactory used to live) or mcp.shared — so building a custom HTTP client does not require importing a private module.
(Related: because the HTTP layer now uses httpx2, a short note in the migration docs on how to build/pass a custom http_client would also help.)
EcoCitizenz Ltd — ECZ-ID | MCP & Agent Trust
+1 to making the construction side of the HTTP transport API public.
Once streamable_http_client(..., http_client=...) is the supported
extension point, keeping the SDK's canonical construction mechanism
private creates an awkward contract:
publicly supported injection point
+
privately supported construction mechanism
Custom HTTP construction is normal rather than exceptional in enterprise
MCP deployments:
- OAuth/workload authentication;
- corporate proxies;
- mTLS/custom trust;
- timeout and retry policy;
- trace propagation;
- policy headers;
- transport instrumentation.
I would therefore favour exposing both create_mcp_http_client and
McpHttpClientFactory from a stable client-facing namespace and documenting
one canonical construction pattern.
There is a security benefit as well: downstream integrations become less
likely to independently reproduce subtly different redirect, timeout,
proxy, authentication or trust behaviour simply because the conforming SDK
helper sits behind a private import.
A stable transport construction boundary is also much easier to review and
produce assurance evidence against than a fleet of downstream integrations
built against private implementation details.
That transport → authority → accountable-operator relationship is directly
relevant to the MCP assurance work we are doing with ECZ-ID.
— Adam Al-Zayed
Founder | EcoCitizenz Ltd
*ECZ-ID — MCP & Agent Trust*
https://mcp.ecocitizenz.com/
Resolver proof / setup: https://trustops.ecocitizenz.com/start
On Mon, Aug 3, 2026 at 3:16 AM 程序猿过家家 ***@***.***> wrote:
> *ProgrammerPlus1998* created an issue
> (modelcontextprotocol/python-sdk#3238)
> <https://github.com/modelcontextprotocol/python-sdk/issues/3238>
> Summary
>
> Customizing the HTTP client for streamable_http_client (custom headers,
> auth, timeout, proxy, etc.) is a common and legitimate need, but as of
> 2.0.0 the only supported way to build a conforming client is through
> helpers that live in the *private* module mcp.shared._httpx_utils. Users
> are therefore forced to depend on a private API.
> What changed in 2.0
>
> In 1.x, streamable_http_client accepted convenience kwargs directly:
>
> streamable_http_client(url, headers=..., timeout=..., sse_read_timeout=..., auth=...)
>
> 2.0 (via #2972
> <https://github.com/modelcontextprotocol/python-sdk/pull/2972>, which
> replaced httpx/httpx-sse with httpx2) removed those kwargs. The signature
> is now:
>
> async def streamable_http_client(
> url: str,
> *,
> http_client: httpx2.AsyncClient | None = None,
> terminate_on_close: bool = True,
> ) -> ...
>
> So the only way to pass custom headers/auth/timeout is to build an
> httpx2.AsyncClient yourself and pass it as http_client=. The standardized
> factory for doing so is create_mcp_http_client — but it is only available
> at the private path:
>
> from mcp.shared._httpx_utils import create_mcp_http_client # private module
>
> The same applies to McpHttpClientFactory: in 1.x it was importable from
> the public mcp.client.streamable_http, but in 2.0 it is defined in
> mcp.shared._httpx_utils and is no longer re-exported from any public
> module.
> Why this is a problem
>
> - "Connect to an MCP server that requires auth headers / a custom
> timeout / a proxy" is a standard use case, not an edge case.
> - The leading underscore on mcp.shared._httpx_utils signals "private,
> may change without notice", so every downstream project that needs a custom
> client has to take on that fragility.
> - It's inconsistent: the *consumption* side (streamable_http_client(url,
> http_client=...)) is public, but the *construction* side (
> create_mcp_http_client, McpHttpClientFactory) is private.
>
> Suggestion
>
> Re-export create_mcp_http_client and McpHttpClientFactory from a public
> module — e.g. mcp.client.streamable_http (where McpHttpClientFactory used
> to live) or mcp.shared — so building a custom HTTP client does not
> require importing a private module.
>
> (Related: because the HTTP layer now uses httpx2, a short note in the
> migration docs on how to build/pass a custom http_client would also help.)
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/modelcontextprotocol/python-sdk/issues/3238?email_source=notifications&email_token=CBJRDB3RZFINES2JA6TH4M35H7YWDA5CNFSL4Z3JMQ5C6L3HNF2C22DVMIXUS43TOVSS6NJQGQ2TMNZVGI3DTJTSMVQXG33OVJZXKYTTMNZGSYTFMSSWK5TFNZ2KYZTPN52GK4S7MNWGSY3L>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/CBJRDB3VW4S6355SWF6TMAL5H7YWDAVCNFSNUABFKJSXA33TNF2G64TZHM4DMMRVHA2DAMJYHNEXG43VMU5TKMBUGU3DONJSGY42C5QC>
> .
> You are receiving this because you are subscribed to this thread.Message
> ID: ***@***.***>
>
Thanks Adam — I really appreciate you endorsing this fix and laying out the reasoning so clearly. The asymmetry you describe — a public injection point paired with a private construction mechanism — is exactly what this change addresses: it re-exports create_mcp_http_client, McpHttpClientFactory (and the two timeout constants) into the public, client-facing mcp.client.streamable_http namespace, and documents the recommended pattern in the migration guide. It's great to hear the security-consistency and auditability benefits resonate — they're a big part of why exposing the canonical construction mechanism felt worthwhile.
Thanks — that is exactly the distinction I was hoping to validate.
Re-exporting the canonical construction path should make downstream enterprise integrations materially easier to review: teams can standardise authentication, proxy, timeout, trust and instrumentation behaviour around one supported public boundary rather than depending on private implementation details.
The migration-guide example is particularly useful as well. I’ll keep an eye on the final shape as it lands and test the public construction path from an assurance and evidence perspective.
Nice improvement — and thanks for taking the security-consistency/auditability point on board.
— Adam Al-Zayed Founder, EcoCitizenz Ltd · ECZ-ID — MCP & Agent Trust ECZ-ID: https://resolver.ecocitizenz.org/passport/ECZ-GB-RBS1NW
I've already prepared an implementation for this (see the linked PR). Happy to be assigned whenever a maintainer has a chance to review — the PR will reopen automatically once assigned.
Closed by #3618 (merged to main), with docs rather than the export you asked for.
All create_mcp_http_client adds to a plain httpx2.AsyncClient is timeout=httpx2.Timeout(30.0, read=300.0). So instead of making it and McpHttpClientFactory public, the Transports docs page now says to keep that timeout on a client you build yourself, and our own examples that had left it off now pass it.
Thanks for the clear report and for #3239, which will stay closed since nothing is being exported.