Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Don't send a cached protocol version header with initialize - #2050

Open
shrutimane2409 wants to merge 1 commit into
modelcontextprotocol:mainfrom
shrutimane2409:fix-2044-initialize-fallback-protocol-header
Open

shrutimane2409 wants to merge 1 commit into
modelcontextprotocol:mainfrom
shrutimane2409:fix-2044-initialize-fallback-protocol-header

Conversation

@shrutimane2409

@shrutimane2409 shrutimane2409 commented Nov 26, 2026 •

Copy link
Copy Markdown

Fixes #2044

When the Streamable HTTP client falls back from server/discover to initialize, the transport still has the 2026-07-28 version cached from the server/discover request and sends it as the MCP-Protocol-Version header, while the initialize body asks for 2025-11-25. This change clears the cached version before sending initialize.

Motivation and Context

Servers reject the mismatched header with HTTP 400, so a client that falls back from server/discover to initialize can fail to connect. initialize negotiates the protocol version, so it shouldn't carry a version cached from an earlier request. With the cached value cleared, the fallback initialize goes out without the stale header, like a normal initialize, and the version is set from the initialize result as before.

How Has This Been Tested?

  • Added Client_OnDiscoverWithoutCommonVersion_FallsBackTo_Initialize_WithMatchingProtocolVersionHeader, based on the repro in the issue: server/discover succeeds but only lists 2025-11-25, and the server returns 400 if the initialize header doesn't match the body. It fails without the fix with Protocol header differs from initialize body, and passes with it.
  • The fallback and HTTP transport tests pass locally on net10.0 (80/80).

Breaking Changes

None.

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

Restore currently fails on main with NU1903 for Microsoft.DotNet.ILCompiler 9.0.20 in samples/TestServerWithHosting, so I ran the tests with -p:NuGetAudit=false

When the Streamable HTTP client fell back from server/discover to
initialize, the transport still had the 2026-07-28 version cached from
the server/discover request and sent it as the MCP-Protocol-Version
header, while the initialize request body asked for 2025-11-25. Servers
reject that mismatch with HTTP 400. Clear the cached version when
sending initialize, since initialize negotiates the version.

Fixes modelcontextprotocol#2044

@sivaraman-krishnan sivaraman-krishnan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for the focused fix and the regression test, @shrutimane2409!

I traced how the Streamable HTTP client caches the version header through server/discover, the initialize fallback, notifications/initialized, later POSTs, the standalone GET and DELETE on dispose:

  • Clearing _negotiatedProtocolVersion only for initialize keeps the fallback from inheriting the 2026-07-28 value cached from a successful server/discover.
  • A version in the request's _meta still takes priority.
  • After the initialize result is processed, the field is set again from its protocolVersion, so later requests still send MCP-Protocol-Version as the spec requires after initialization.

The new test fails without the transport change and passes with it. I didn't find a request that should carry the negotiated header and loses it.

@shrutimane2409

Copy link
Copy Markdown
Author

Thanks for tracing through all the request paths and confirming! @sivaraman-krishnan

This branch has not been deployed

No deployments
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.

Streamable HTTP initialize fallback sends a stale MCP-Protocol-Version header

2 participants