feat: add per-request HTTP headers support for client session methods#1515
feat: add per-request HTTP headers support for client session methods#1515damianoneill wants to merge 3 commits intomodelcontextprotocol:mainfrom
Conversation
c595101 to
abce375
Compare
|
@felixweinberger any feedback on this PR would be much appreciated. First time committing to the repo, I'm not sure what the correct process is for submission. Thanks in advance, Damian. |
|
Is there any update on this PR, we are interesting in this patch |
0e86471 to
c17841e
Compare
|
@juanmolle I've rebased to latest, this required adding new tests as coverage had dropped elsewhere, this is now complete. The failing check looks like a pipeline problem, I have no way to trigger this again. Assume maintainer can do this during review. |
|
@maxisbey @felixweinberger see comment above about failed check. I cannot re-run this check, its seems to be a flaky test outside of my code change. |
Implements per-request headers functionality across all ClientSession methods to enable multi-tenant authentication, request tracing, A/B testing, and debugging while maintaining a single persistent connection. Technical Implementation: - Headers are passed through ClientMessageMetadata to transport layer - Per-request headers take precedence over connection-level headers - All methods follow consistent extra_headers: dict[str, str] | None = None pattern Addresses: modelcontextprotocol#1509
- Add test_streamablehttp_client_tool_invocation_with_extra_headers for POST requests - Add test_streamablehttp_client_resumption_with_extra_headers for resumption with extra headers - Refactor common resumption setup code into _setup_resumption_test helper - Achieve 100% coverage for streamable_http.py
c17841e to
13975ac
Compare
The deprecated streamablehttp_client was removed from main during the rebase. Update the example to use streamable_http_client with create_mcp_http_client for connection-level headers.
13975ac to
022d680
Compare
|
@maxisbey I've rebased to latest Same as before there is now another test failing tests\client\test_stdio.py not in code I've modified, test looks flaky, it passes on other python version runs. |
Implements per-request headers functionality to enable various use cases such as multi-tenant authentication, request tracing, A/B testing, and debugging while maintaining a single persistent connection.
Changes:
This addresses GitHub issues #1509 and supports multi-tenant scenarios where different requests require different authentication tokens or contextual headers.
Motivation and Context
Disscussed in issue #1509
How Has This Been Tested?
UTs, commit provided for review, is approach is agreed will proceed with extensive real world testing before finalising this PR.
Breaking Changes
N/A
Types of changes
Checklist
Additional context