fix: validate protocol version header on initialization requests#697
Open
fix: validate protocol version header on initialization requests#697
Conversation
…ssion header parsing, and add tests for unsupported protocol scenarios.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Streamable HTTP server transport to validate the mcp-protocol-version HTTP header during initialize requests, and aligns the SDK’s default negotiated protocol version with the spec.
Changes:
- Validate
mcp-protocol-versionon initialization requests (in addition to existing validation on other request types). - Adjust priming-event gating to consistently use a concrete client protocol version.
- Update protocol version constants and extend tests to cover unsupported protocol versions during init.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/StreamableHttpServerTransport.kt | Moves protocol-version validation into the initialization path and refactors protocol version handling for priming events. |
| kotlin-sdk-server/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/server/StreamableHttpServerTransportTest.kt | Adds/updates tests to ensure init requests with unsupported protocol versions fail. |
| kotlin-sdk-core/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/types/common.kt | Updates DEFAULT_NEGOTIATED_PROTOCOL_VERSION to match the spec. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/StreamableHttpServerTransport.kt
Show resolved
Hide resolved
...commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/StreamableHttpServerTransport.kt
Show resolved
Hide resolved
...commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/StreamableHttpServerTransport.kt
Show resolved
Hide resolved
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.
Validate
mcp-protocol-versionHTTP header duringInitializeRequestFix
DEFAULT_NEGOTIATED_PROTOCOL_VERSIONto match the specfixes #547
How Has This Been Tested?
Updated existing test (removed TODO referencing #547) to verify init request
Breaking Changes
none
Types of changes
Checklist