Repository navigation
feat: cap the includeContext a sampling handler sees - #411
Merged
varun06 merged 1 commit intoNov 30, 2026
Merged
Conversation
A server can request includeContext: allServers, which asks the client to share context from every connected MCP server with that one server. The 2025-11-25 specification soft-deprecates thisServer and allServers, and servers should use them only when the client declares sampling.context; SEP-2596 deprecates them. Add Client.Configuration.maxContextInclusion, default .none. Before a sampling handler runs, the client lowers a higher includeContext to the cap. The cap applies in withMethodHandler, so it covers requests at 2025-11-25 and input requests at 2026-07-28, and reads the configuration when the request arrives. A request without includeContext is unchanged. Sampling.ContextInclusion becomes Comparable (none < thisServer < allServers). The configuration saves the cap; a missing key decodes to .none. Co-authored-by: Alex Bullitt <[email protected]>
varun06
merged commit Nov 30, 2026
d96515e
into
modelcontextprotocol:rel/1.0.0
12 of 14 checks passed
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.
Summary
A server can request
includeContext: allServersinsampling/createMessage, which asks the client to share context from every connected MCP server with that one server. The 2025-11-25 specification soft-deprecatesthisServerandallServers(servers should use them only when the client declaressampling.context), and SEP-2596 deprecates them. This PR lets the app cap what a sampling handler sees.Changes
Client.Configuration.maxContextInclusion(default.none). Before a sampling handler runs, the client lowers a higherincludeContextto the cap. A request withoutincludeContextis unchanged.Client.withMethodHandler, next to the existing sampling checks. It coverssampling/createMessagerequests (2025-11-25) and sampling input requests (2026-07-28), and reads the configuration when the request arrives.Sampling.ContextInclusionisComparable:none < thisServer < allServers. The ordering reads the raw value, so the SDK does not name the deprecated cases.Client.Configurationencodes the cap; a missing key decodes to.none, so configurations saved by earlier versions still decode.The wire format does not change. The deprecation of
thisServerandallServersis already onrel/1.0.0(#341), so this PR does not touch it.API changes
Client.Configuration.maxContextInclusionClient.Configuration.init(...maxContextInclusion:).noneSampling.ContextInclusion: ComparableBehavior changes
By default a sampling handler now sees
includeContext == .nonewhen a server asks forthisServerorallServers. Apps that want the previous behavior setmaxContextInclusion: .allServers. This is the one decision I would like a maintainer's view on: the default is the safe one, and it is a change for apps onrel/1.0.0.Tests
SamplingContextInclusionCapTestsinSamplingTests.swift:.none;includeContextstaying without one;capping(includeContext:)keeping every other field.I checked that the matrix fails at both eras when the cap is not applied. An existing integration test that expected the handler to see
thisServernow setsmaxContextInclusion: allServers.Verification on macOS:
swift test(1540 tests pass),swift scripts/weave.swift --check,swift scripts/doc-coverage.swift, and DocC with--warnings-as-errors. I did not run the conformance legs, the interop check or Linux.Co-authored-by: Alex Bullitt
AI usage disclosure: the rebase onto
rel/1.0.0, the tests, the docs and this description were written with Claude and reviewed by the author.