Validate MCP-Protocol-Version header in Streamable HTTP handler#1277
Open
Validate MCP-Protocol-Version header in Streamable HTTP handler#1277
Conversation
If the server receives a request with an invalid or unsupported MCP-Protocol-Version header, respond with 400 Bad Request per the MCP spec. A missing header is allowed for backwards compatibility. Exposes McpSession.SupportedProtocolVersions as a public static property so the AspNetCore handler can validate against it. Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add validation for MCP-Protocol-Version header
Validate MCP-Protocol-Version header in Streamable HTTP handler
Feb 15, 2026
stephentoub
reviewed
Feb 15, 2026
tests/ModelContextProtocol.AspNetCore.Tests/StreamableHttpServerConformanceTests.cs
Show resolved
Hide resolved
…ns class, use nullable out param - Move SupportedProtocolVersions from McpSession to new ProtocolVersions static class in Protocol namespace (following RequestMethods/NotificationMethods pattern) - Revert McpSession.cs to original state - Change out string to out string? with null on success - Add ProtocolVersionsTests for the new public property Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
The SupportedProtocolVersions doesn't need to be exposed publicly. Instead, use InternalsVisibleTo to let ModelContextProtocol.AspNetCore access the internal McpSessionHandler.SupportedProtocolVersions directly. - Delete ProtocolVersions.cs public static class - Delete ProtocolVersionsTests.cs - Add InternalsVisibleTo in Core csproj for AspNetCore - Reference McpSessionHandler.SupportedProtocolVersions directly Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
…idation Define supported protocol versions as a private HashSet directly in StreamableHttpHandler instead of referencing McpSessionHandler internals or adding any cross-assembly visibility. No new public API surface needed. Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
stephentoub
reviewed
Feb 15, 2026
Add abstract SupportedProtocolVersions property to McpServer, implemented by McpServerImpl (delegating to McpSessionHandler.SupportedProtocolVersions) and DestinationBoundMcpServer. Protocol version validation in StreamableHttpHandler now occurs after session resolution, querying the server instance directly. Remove private HashSet from handler. Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Use TryGetValue to check version first, then TryRemove to actually delete. This prevents losing the session if validation fails. Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
stephentoub
reviewed
Feb 15, 2026
…yList<string> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
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.
MCP-Protocol-Versionheader validation inStreamableHttpHandler.csfor POST, GET, and DELETE handlersStreamableHttpServerConformanceTests.csSupportedProtocolVersionsas an abstract instance property onMcpServer(notMcpSession— only relevant to servers)McpServerImpl(delegates toMcpSessionHandler.SupportedProtocolVersions) andDestinationBoundMcpServerSupportedProtocolVersionsfromICollection<string>toIReadOnlyList<string>Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.