Send and validate MCP-Protocol-Version header on Streamable HTTP transport#675
Draft
Send and validate MCP-Protocol-Version header on Streamable HTTP transport#675
Conversation
34c64a3 to
d997737
Compare
d997737 to
f0bc7f9
Compare
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.
Closes #587
Motivation and Context
The MCP 2025-06-18 spec requires clients to send an
MCP-Protocol-Versionheader containing the negotiated protocol version on every HTTP request after initialization. Servers must return400 Bad Requestif the header contains an unsupported value. Neither side currently handles this header, which is one of the blockers for 2025-06-18 compliance.On the client side, the worker now extracts the negotiated version from the
initializeresponse and injects it as anMCP-Protocol-Versionheader into every subsequent POST, GET, and DELETE request. On the server side,StreamableHttpServicevalidates the header on all non-initialization requests and rejects unsupported values with a 400 response. Requests without the header are accepted for backwards compatibility with older clients, per the spec.How Has This Been Tested?
Added integration tests to cover the changes, and all the existing tests are still passing.
Breaking Changes
The
StreamableHttpClienttrait now requires acustom_headers: HashMap<HeaderName, HeaderValue>parameter onget_streamanddelete_session. This is a breaking change for anyone implementing the trait directly, butpost_messagealready had this parameter so the update is straightforward. The publicStreamableHttpClientTransportAPI is unchanged.Types of changes
Checklist
Additional context