Skip to content

feat(client): add a maximum MCP protocol version - #1977

Open
Coding-Professional wants to merge 2 commits into
modelcontextprotocol:mainfrom
Coding-Professional:feat/1868-protocol-version-ceiling
Open

Coding-Professional wants to merge 2 commits into
modelcontextprotocol:mainfrom
Coding-Professional:feat/1868-protocol-version-ceiling

Conversation

@Coding-Professional

Copy link
Copy Markdown
Contributor

Summary

Add McpClientOptions.MaximumProtocolVersion so clients can choose an upper protocol bound while accepting an older mutually supported revision. This is useful for MCP hosts and gateways that have validated a limited range of protocol revisions.

Fixes #1868.

Behavior

  • Validate the ceiling against SDK-supported revisions and reject configuration that also sets the existing exact ProtocolVersion pin before opening a transport.
  • A ceiling on an initialize-handshake revision requests that revision directly and accepts an older supported response. A 2026-07-28 ceiling retains discovery and fallback, filtering advertised versions before selecting one.
  • Reject malformed/newer initialize responses and advertised version sets with no compatible revision. Resumed sessions cannot exceed the configured ceiling.
  • Leave connection behavior unchanged when the new option is unset. Document the difference between an exact pin and a ceiling.

Verification

  • Focused protocol negotiation tests: 58 passed on Windows net10.0 and net8.0. These cover ceiling match, downgrade, discovery fallback, no overlap, invalid response, conflicting options, and resume.
  • dotnet build src/ModelContextProtocol.Core/ModelContextProtocol.Core.csproj --no-restore: passed for netstandard2.0, net8.0, net9.0, and net10.0 with no warnings or errors.
  • git diff --check: passed.
  • dotnet format whitespace --verify-no-changes --include ... reports existing whitespace violations on untouched lines in McpClient.Methods.cs and McpClientImpl.cs; this PR does not reformat those unrelated sections.

AI assistance was used to investigate and draft this change; I reviewed the implementation and ran the tests above.

Copilot AI balanced review requested due to automatic review settings October 30, 2026 11:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@chrikrah chrikrah left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@Coding-Professional, this covers rules 1 to 4 of #1868 with tests, and caps resume. From my perspective it can be merged; the API call stays open on #1868.

non-blocking: both ceiling .Where filters can't fire before a revision after 2026-07-28, so removing them still passes 58. I'd keep them. Could you add a comment that the next revision needs a ceiling test?

$ dotnet test tests/ModelContextProtocol.Tests -f net10.0 --filter "FullyQualifiedName~July2026ProtocolFallbackTests"   # head dd3bef4, git archive export, sdk 10.0.403
Passed: 58
$ <same, both ceiling filters removed from McpClientImpl.cs>
Passed: 58

@Coding-Professional
Coding-Professional force-pushed the feat/1868-protocol-version-ceiling branch from efbf0ab to a5b8f02 Compare November 11, 2026 10:09
@Coding-Professional

Copy link
Copy Markdown
Contributor Author

CI after rebasing onto upstream main (64cfd66b): five of six build/test matrix jobs passed. Ubuntu Release built successfully and passed its .NET 10 and .NET 9 core test runs. Its .NET 8 core test host was then terminated by the configured seven-minute inactivity timeout, with 3,674 tests passed and five skipped before the abort. The blame log lists StdioClientTransportTests.InheritEnvironmentVariables_False_ChildDoesNotSeeParentEnvVars as the active test; this PR does not change that test or the stdio transport.

The focused protocol negotiation tests pass locally (58/58 on net10.0) against the rebased branch. I cannot rerun the upstream job from my contributor account. Could a maintainer please rerun the failed Ubuntu Release job?

This branch has not been deployed

No deployments
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.

MCP Protocol-Version Ceiling for the C# Client SDK

3 participants