Skip to content

Add test coverage for AdditionalHeaders in Streamable HTTP transport#1218

Merged
halter73 merged 3 commits intomainfrom
copilot/fix-additional-headers-issue
Jan 30, 2026
Merged

Add test coverage for AdditionalHeaders in Streamable HTTP transport#1218
halter73 merged 3 commits intomainfrom
copilot/fix-additional-headers-issue

Conversation

Copy link
Contributor

Copilot AI commented Jan 30, 2026

Investigated report that HttpClientTransportOptions.AdditionalHeaders was not applied to all MCP requests.

Findings

Implementation is correct. All transports already call CopyAdditionalHeaders for every HTTP request:

  • SSE Transport: GET (line 150), POST (line 86)
  • Streamable HTTP: POST (line 91), GET (line 248), DELETE (line 377)

Changes

  • Added AdditionalHeaders_AreSent_InPostAndDeleteRequests test in MapMcpStreamableHttpTests.cs to verify Streamable HTTP transport headers
  • Complements existing AdditionalHeaders_AreSent_InGetAndPostRequests test which only covers SSE transport
  • Test skipped in stateless mode (no DELETE sent without session ID)
Original prompt

This section details on the original issue you should resolve

<issue_title>HttpClientTransportOptions.AdditionalHeaders not applied to all MCP requests in MCP client</issue_title>
<issue_description>When HttpClientTransport is created with HttpClientTransportOptions.AdditionalHeaders (e.g. Authorization: Bearer ), the header is applied for the initial handshake but is missing on subsequent MCP requests (tools/list, tools/call). Server receives requests without the Authorization header.

  1. Create transport with HttpClientTransportOptions.AdditionalHeaders = { ["Authorization"] = "Bearer " }.
  2. Create MCP client with that transport.
  3. Call ListToolsAsync() and then CallToolAsync(...).
  4. Observe server-side middleware: initial request may show token, later MCP calls report missing Authorization.

Headers provided in AdditionalHeaders (especially Authorization) should be present on every HTTP request the transport issues, not only during the initial handshake.

• Client logs: token created and initial request shows header present.
• Server logs: later requests report No Bearer token provided and incomplete session context.
• Pattern: different connection/RequestId used for later requests that lack the header.
• Likely cause: transport creates or uses multiple HttpClient instances and does not apply AdditionalHeaders to every outgoing HttpRequestMessage.</issue_description>

<agent_instructions>Investigate whether:

  1. The claims made in the issue are correct.
  2. The implementation is supposed to be sending these headers on every request.

If it's correct that the headers are supposed to be sent on every request but they're not, fix the implementation to do so and ensure tests are in place in existing files (ideally in existing tests that can just be augmented) to validate this behavior.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 30, 2026 15:36
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix missing Authorization header in MCP requests Add test coverage for AdditionalHeaders in Streamable HTTP transport Jan 30, 2026
Copilot AI requested a review from stephentoub January 30, 2026 15:48
@stephentoub stephentoub marked this pull request as ready for review January 30, 2026 15:49
@stephentoub stephentoub requested a review from halter73 January 30, 2026 15:50
@halter73 halter73 merged commit 82bd980 into main Jan 30, 2026
16 of 17 checks passed
@halter73 halter73 deleted the copilot/fix-additional-headers-issue branch January 30, 2026 22:07
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.

HttpClientTransportOptions.AdditionalHeaders not applied to all MCP requests in MCP client

3 participants