Skip to content

Fix Client.connect not sending negotiated MCP-Protocol-Version - #1091

Merged
devcrocod merged 3 commits into
modelcontextprotocol:mainfrom
xu-baolin:fix/streamable-http-protocol-version-header
Nov 13, 2026
Merged

devcrocod merged 3 commits into
modelcontextprotocol:mainfrom
xu-baolin:fix/streamable-http-protocol-version-header

Conversation

@xu-baolin

Copy link
Copy Markdown
Contributor

Copy InitializeResult.protocolVersion onto StreamableHttpClientTransport before initialized so subsequent Streamable HTTP requests include the spec-required header.

After initialize succeeds, Client.connect now assigns InitializeResult.protocolVersion to StreamableHttpClientTransport.protocolVersion before sending notifications/initialized. Subsequent Streamable HTTP requests then include mcp-protocol-version.

Motivation and Context

The Streamable HTTP spec (2025-06-18 / 2025-11-25) requires clients to send the negotiated protocol version on HTTP requests after initialize. Servers that do not receive the header SHOULD assume 2025-03-26.

StreamableHttpClientTransport already appends mcp-protocol-version when protocolVersion is set, but Client.connect never copied the negotiated value, so the header was omitted unless callers set the field by hand.

Fixes #1090

How Has This Been Tested?

Unit tests in StreamableHttpClientTransportTest (JVM):

  • Existing: should send the protocol version header once it is set
  • New: connect should apply the negotiated protocol version to subsequent streamable HTTP requests — Client.connect over a mock Streamable HTTP transport, then ping; the ping POST includes mcp-protocol-version equal to the initialize result.

Breaking Changes

None. Clients that already set protocolVersion manually keep working. Callers that relied on the header being absent may now see mcp-protocol-version on post-initialize Streamable HTTP requests.

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

Assignment is gated on transport is StreamableHttpClientTransport because only that transport has protocolVersion. SSE is unchanged.

The initialize request itself still does not send the header (the field is set only after the initialize result is accepted), which matches “after successfully initializing”.

@xu-baolin
xu-baolin force-pushed the fix/streamable-http-protocol-version-header branch from 9dbf0d9 to 598918e Compare October 5, 2026 16:32
@xu-baolin

Copy link
Copy Markdown
Contributor Author

Hi @devcrocod — this is my first PR here, so GitHub Actions is waiting on
"Approve and run workflows". Could you approve the checks when you have a
moment? Happy to address review comments after CI runs.

@jetbrains-air jetbrains-air Bot 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.

Looks great — the negotiated version is now applied at exactly the right point, so this is good to merge.

Produced by Air Automations. Name: Code review / Run: https://air.jetbrains.cloud/org/05cf1a7f-6ab5-713b-abd3-29d0c8a05e2d/automations/409567ec-d3a7-40ac-ba95-8518ec577ac2?run=679168e7-961a-4c1e-a428-c8ec11527e07

@chrikrah chrikrah 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.

@xu-baolin approving at 598918e. With Client.kt at the merge base, your test finds transport.protocolVersion still null after connect. With the change, both it and the ping header carry the negotiated value.

$ ./gradlew :kotlin-sdk-client:jvmTest --tests "*StreamableHttpClientTransportTest"   # 598918e, Temurin 21, Gradle 9.8.0
tests=18 failures=0
$ # same command, Client.kt at 32e6483 (merge base), test kept
tests=18 failures=1
FAIL connect should apply the negotiated protocol version to subsequent streamable HTTP requests
  AssertionFailedError: Expected "2025-03-26" but actual was null

Client.connect sets the value before it sends notifications/initialized. The GET stream at StreamableHttpClientTransport.kt:189 opens after that notification and carries the header too.

@devcrocod your #985 makes the same assignment in settle(), so the two touch the same lines of connect. #985 is the breaking one. Would you take this now as the fix for #1090, and drop the lines from #985 on rebase?

Copy InitializeResult.protocolVersion onto StreamableHttpClientTransport before initialized so subsequent Streamable HTTP requests include the spec-required header.
@xu-baolin
xu-baolin force-pushed the fix/streamable-http-protocol-version-header branch from 598918e to e15eac4 Compare November 1, 2026 13:26
@xu-baolin

Copy link
Copy Markdown
Contributor Author

Rebased onto the latest main — head is now e15eac4 (was 598918e). The change itself is unchanged (same 2 files, same 74 lines); the workflow runs on the new head need a re-approval. Happy to rebase again if #985 lands first.

@jetbrains-air jetbrains-air Bot 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.

Happy to approve this one — thanks for the fix!


Produced by Air Automations. Name: Code review / Run: https://air.jetbrains.cloud/org/05cf1a7f-6ab5-713b-abd3-29d0c8a05e2d/automations/409567ec-d3a7-40ac-ba95-8518ec577ac2?run=eb5f860e-6c13-4019-87f4-ab965c2c11f1

@devcrocod devcrocod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

@devcrocod
devcrocod merged commit af5d784 into modelcontextprotocol:main Nov 13, 2026
19 checks passed
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.

Client.connect does not apply the negotiated protocol version to Streamable HTTP transport

3 participants