Skip to content

fix: validate protocol version header on initialization requests#697

Open
devcrocod wants to merge 2 commits intomainfrom
devcrocod/check-protocol-version-init
Open

fix: validate protocol version header on initialization requests#697
devcrocod wants to merge 2 commits intomainfrom
devcrocod/check-protocol-version-init

Conversation

@devcrocod
Copy link
Copy Markdown
Contributor

Validate mcp-protocol-version HTTP header during InitializeRequest

Fix DEFAULT_NEGOTIATED_PROTOCOL_VERSION to match the spec

fixes #547

How Has This Been Tested?

Updated existing test (removed TODO referencing #547) to verify init request

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

…ssion header parsing, and add tests for unsupported protocol scenarios.
Copilot AI review requested due to automatic review settings April 14, 2026 19:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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-version on 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.

@devcrocod devcrocod requested a review from e5l April 14, 2026 20:13
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.

validateProtocolVersion happens after InitializationRequest

2 participants