Repository navigation
Conversation
Reject undeclared tool sampling and elicitation modes before invoking client handlers, and check roots and sampling before sending server requests. Fixes modelcontextprotocol#1303
This branch has not been deployed
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.
Fixes #1303.
A tool-enabled sampling request could reach a client that advertised only basic sampling, whose handler then answered without the requested tools. The server now checks declared roots, sampling and sampling.tools before sending a request. The client rejects undeclared tool sampling and elicitation modes with -32602 before calling the handler.
Sampling and elicitation checks also cover multi-round-trip input requests on both 2026-07-28 and legacy sessions. Existing roots fixtures now declare the capability they use.
Validation: the added regression tests fail on current main and pass with the fix;
go test -race ./...,go vet ./...,staticcheck ./...andgit diff --checkpass locally (Go 1.27.1, staticcheck 0.8.1).A separate, pre-existing gap remains: the modern multi-round-trip roots input path calls the client roots handler without a capability check. This PR gates outbound
ServerSession.ListRoots; it does not change that modern input path.