Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Configuring HTTP client for streamablehttp #742

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

fabioyamate
Copy link

@fabioyamate fabioyamate commented May 17, 2025

Motivation and Context

The current streamablehttp_client doesn't support customizing the new client except header and timeout. I need to customize the httpx client because my MCP server integration requires mTLS connection, thus I need to setup certification during connection.

This allow to pass a http client or default to the existing factory.

I was able to "successfully" test my MCP integration by "monkey patching" the introduced mcp.shared._httpx_utils.create_mcp_client = my_custom_client_factory.

Also, this supports base_url support by httpx, which is minor, but for my case, URLs are injected as they vary on deployment.

How Has This Been Tested?

I tested my branch integrating with the deployed MCP, and it worked the same way with the monkey patch version, except that this became explicit.

Breaking Changes

This doesn't introduce any breaking change.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

This approach is similar to how other SDK configuration works, allow users to change the http client based on infrastructure requirements.

Why not kwargs? It felt that passing the client instance is more flexible than picking or passing the init constructors.

This couples with httpx.AsyncClient. Yes, in comparison to the current implementation that hides this detail. But, I didn't consider the scope of this PR, introducing a "wrapper" for the async client.

Update: I discovered a recent PR #734 after the PR opened. I didn't notice because I started to work prior it.

@fabioyamate fabioyamate force-pushed the custom-http-client branch 3 times, most recently from 868c24f to 26b1bcc Compare May 17, 2025 03:24
@fabioyamate fabioyamate force-pushed the custom-http-client branch from 26b1bcc to c16c99e Compare May 17, 2025 03:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant