Skip to content

streamable: validate Mcp-Protocol-Version header matches body protocolVersion on initialize#974

Open
Lordfiber wants to merge 1 commit into
modelcontextprotocol:mainfrom
Lordfiber:codex/validate-protocol-version-mismatch
Open

streamable: validate Mcp-Protocol-Version header matches body protocolVersion on initialize#974
Lordfiber wants to merge 1 commit into
modelcontextprotocol:mainfrom
Lordfiber:codex/validate-protocol-version-mismatch

Conversation

@Lordfiber
Copy link
Copy Markdown

Summary

Fix #963

The Streamable HTTP server now validates that the Mcp-Protocol-Version header matches the protocolVersion field in the initialize request body. Previously, mismatched versions were silently accepted.

Changes

  • mcp/streamable.go: In servePOST, after extracting protocolVersion from both the HTTP header and the initialize body params, compare them. If both are present and differ, return a CodeHeaderMismatch (-32001) error with a 400 status.
  • mcp/streamable_test.go: Add test case "protocol version mismatch" that sends an initialize request with header 2025-11-25 but body 2025-06-18, verifying a 400 Bad Request response.

Testing

go test ./mcp/ -run TestStreamableServerTransport/protocol_version_mismatch -v

PASS

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 server accepts mismatched MCP-Protocol-Version header and body protocolVersion on initialize

1 participant