feat: add support for custom HTTP headers in StreamableHttpClient#655
Merged
alexhancock merged 2 commits intomodelcontextprotocol:mainfrom Feb 13, 2026
Merged
Conversation
alexhancock
reviewed
Feb 13, 2026
Contributor
alexhancock
left a comment
There was a problem hiding this comment.
This is a good idea - thanks for the contribution. I left one recommendation in the code.
| request = request.bearer_auth(auth_header); | ||
| } | ||
| // Apply custom headers | ||
| for (name, value) in custom_headers { |
Contributor
There was a problem hiding this comment.
Perhaps disallow any of the headers that are controlled by the default client logic?
ACCEPT HEADER_SESSION_ID etc
Contributor
There was a problem hiding this comment.
I would check https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#streamable-http for a full list
MCP-Protocol-Version is another one that comes to mind
Contributor
Author
There was a problem hiding this comment.
Good idea. I've updated the PR to add the check.
…eamableHttpClient
alexhancock
approved these changes
Feb 13, 2026
Contributor
|
Nice one @Arichy - thanks |
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.
This PR adds support for custom HTTP headers in the
StreamableHttpClienttransport, allowing users to pass additional headers when connecting to remote MCP servers.Motivation and Context
When connecting to the GitHub MCP server remotely, custom headers are required to filter and control server behavior. Specifically, the GitHub MCP server uses the
X-MCP-Toolsetsheader to allow clients to specify which toolsets to load (e.g.,X-MCP-Toolsets: issuesto only load issue-related tools).Reference: https://github.com/github/github-mcp-server/blob/main/docs/remote-server.md
The Rust SDK did not previously support custom headers, making it impossible to use these filtering capabilities. This PR addresses that limitation by adding custom header support to the
StreamableHttpClienttransport configuration.How Has This Been Tested?
All tests pass locally with
just test.Breaking Changes
None. This is a fully backward-compatible addition. Existing code continues to work without modification, as custom headers default to an empty HashMap.
Types of changes
Checklist
Additional context
Implementation details:
custom_headers: HashMap<HeaderName, HeaderValue>field toStreamableHttpClientTransportConfigcustom_headers()builder method for fluent API configurationStreamableHttpClienttrait'spost_messagemethod signature to accept custom headersExample usage: