Repository navigation
Conversation
Read the sampling, sampling.tools and roots declarations with ClientCapabilities.value, as the elicitation checks do. String keys are accepted, and sampling: true with tools or tool_choice raises the documented RuntimeError instead of TypeError. Fixes modelcontextprotocol#750.
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.
Motivation and Context
build_sampling_paramsandServerSession#list_rootsread the client's capabilities withdig, so a client that declaressampling: truemadecreate_sampling_messagewithtools:ortool_choice:raiseTypeError, and capabilities stored with string keys were taken as undeclared.They now read the capabilities through the private
ClientCapabilities.valuefrom #731, as the elicitation checks andrequire_client_capability!do. That takes symbol or string keys and readstoolsonly from a Hash, sosampling: truewith tools gets the documentedRuntimeError. A scalar declaration still counts as declared for sampling without tools and for roots, as it did before; this change does not adopt the elicitation rule that refuses a declaration that is not an object.Fixes #750
How Has This Been Tested?
test/mcp/server_sampling_test.rb: string keys enable tool-enabled sampling, andsampling: truewithtools:ortool_choice:raises the unsupported-option error without sending anything.test/mcp/server_roots_test.rb:list_rootssends its request for a string-keyedrootsdeclaration.main.RuntimeError: Client does not support sampling with tools.and sends both string-keyed requests.bundle exec rakepasses on Ruby 4.0.10 (RuboCop, 2860 runs with 0 failures, and the conformance baseline).yard --no-outputpasses.Breaking Changes
None for clients that declare capabilities as objects.
sampling: truewith tools now raisesRuntimeErrorinstead ofTypeError.Types of changes
Checklist