feat: add strict stateless protocol metadata validation - #1091
Merged
DaleSeo merged 2 commits intoJul 30, 2026
Merged
Conversation
mrcs64
marked this pull request as ready for review
July 30, 2026 08:19
DaleSeo
force-pushed
the
fix/reject-missing-request-protocol-metadata
branch
from
July 30, 2026 19:51
eae071a to
bc3f072
Compare
DaleSeo
approved these changes
Jul 30, 2026
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.
Add an opt-in Streamable HTTP server setting that requires stateless JSON-RPC
request POSTs to carry their per-request protocol signals before handler
dispatch.
Motivation and Context
The general-purpose SDK preserves compatibility when
MCP-Protocol-Versionis absent by treating a stateless request as protocolversion
2025-03-26. Modern-only servers need a supported way to reject thatfallback without changing the SDK default or maintaining custom middleware.
StreamableHttpServerConfig::with_stateless_protocol_metadata_required(true)adds that enforcement on requests routed statelessly:
MCP-Protocol-Versionreturn HTTP 400 withHeaderMismatch(-32020) before dispatch_meta.io.modelcontextprotocol/protocolVersionreturn HTTP 400 withInvalid Params(-32602) before dispatchtheir existing behavior and error precedence
The validator checks metadata presence rather than applying a version
allowlist. In practice, rmcp clients negotiated below
2026-07-28do notattach per-request protocol metadata, so enabling this setting rejects their
ordinary requests. Servers using it should normally restrict
ServerHandler::supported_protocol_versions()to2026-07-28and later.This complements #1089. That PR validates required body metadata when a
request already selects
2026-07-28; this opt-in setting additionally lets astrict stateless server reject requests that omit both version signals and
would otherwise take the compatibility fallback.
How Has This Been Tested?
Added invocation-counter integration tests covering:
2026-07-28rmcp clientsThe focused Streamable HTTP protocol-version suite passes 18 tests.
Also ran:
Breaking Changes
None. The new setting defaults to
false, and the legacy session path isunchanged.
Types of changes
Checklist
Additional context
The setting is enforced only after routing selects the stateless branch. Set
legacy_session_mode(false)when every request must use that path. With mixedrouting enabled, regression coverage verifies that the setting does not shadow
legacy session dispatch or the required 404 response for unknown and
terminated sessions.