FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Expose create_mcp_http_client and McpHttpClientFactory from mcp.client.streamable_http by ProgrammerPlus1998 · Pull Request #3239 · modelcontextprotocol/python-sdk · GitHub

Expose create_mcp_http_client and McpHttpClientFactory from mcp.client.streamable_http - #3239

Closed
ProgrammerPlus1998 wants to merge 2 commits into
modelcontextprotocol:mainfrom
ProgrammerPlus1998:feat/expose-httpx-client-factory-public
Closed

Expose create_mcp_http_client and McpHttpClientFactory from mcp.client.streamable_http#3239
ProgrammerPlus1998 wants to merge 2 commits into
modelcontextprotocol:mainfrom
ProgrammerPlus1998:feat/expose-httpx-client-factory-public

Conversation

Copy link
Copy Markdown

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-export create_mcp_http_client, McpHttpClientFactory, MCP_DEFAULT_TIMEOUT, and MCP_DEFAULT_SSE_READ_TIMEOUT from the same module that already exposes streamable_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 — new test_public_reexport_from_streamable_http asserting 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 broader mcp.shared) because that's where streamable_http_client lives and where McpHttpClientFactory was 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 check and ruff format --check clean on the changed files.

…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

cubic-dev-ai Bot left a comment
edited
Loading

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/mcp/client/streamable_http.py Outdated
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

ProgrammerPlus1998 commented Aug 3, 2026
edited
Loading

Copy link
Copy Markdown
Author

fixed. I removed the module-level __all__ and switched to redundant-alias re-exports (X as X), which keeps ruff's F401 satisfied while remaining purely additive.

Verified locally that the star-import surface is unchanged apart from the newly exported names: diffing dir(m) (no-underscore names) before vs. after shows nothing lost — SessionMessageOrError, DEFAULT_RECONNECTION_DELAY_MS, CONNECTION_CLOSED, etc. are all still exported, and create_mcp_http_client / McpHttpClientFactory / the two timeout constants are added.

github-actions Bot added the missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md) label Aug 17, 2026

Copy link
Copy Markdown
Contributor

Thanks for the contribution. This repository only keeps pull requests open when they're linked to an issue that a maintainer has assigned to the author — CONTRIBUTING.md explains why and how we work. This PR has been closed for now because you aren't currently assigned to #3238.

If a maintainer would like this change as a PR from you, they'll assign you to #3238 and this PR will reopen automatically — there's nothing more you need to do. (If you opened the issue, this PR already shows up on its timeline.)

There's no need to open a new PR — this one will be reopened. While it's closed, please push any updates as new commits rather than force-pushing, since GitHub can't reopen a PR whose branch has been rewritten.

Maintainers: reopening this PR, removing the missing-issue-link label, or adding bypass-issue-check bypasses the check.

github-actions Bot closed this Aug 17, 2026
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

Labels

missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose create_mcp_http_client and McpHttpClientFactory as public API (2.0 made them private-only)

1 participant


Back | FazBrowse Home | New Git URL