Skip to content

fix: read sampling and roots capabilities through the shared lookup - #757

Open
yorzi wants to merge 1 commit into
modelcontextprotocol:mainfrom
yorzi:fix/sampling-and-roots-capability-checks
Open

yorzi wants to merge 1 commit into
modelcontextprotocol:mainfrom
yorzi:fix/sampling-and-roots-capability-checks

Conversation

@yorzi

@yorzi yorzi commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Motivation and Context

build_sampling_params and ServerSession#list_roots read the client's capabilities with dig, so a client that declares sampling: true made create_sampling_message with tools: or tool_choice: raise TypeError, and capabilities stored with string keys were taken as undeclared.

They now read the capabilities through the private ClientCapabilities.value from #731, as the elicitation checks and require_client_capability! do. That takes symbol or string keys and reads tools only from a Hash, so sampling: true with tools gets the documented RuntimeError. 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, and sampling: true with tools: or tool_choice: raises the unsupported-option error without sending anything.
  • test/mcp/server_roots_test.rb: list_roots sends its request for a string-keyed roots declaration.
  • The three tests fail on main.
  • With this change the script in the issue raises RuntimeError: Client does not support sampling with tools. and sends both string-keyed requests.

bundle exec rake passes on Ruby 4.0.10 (RuboCop, 2860 runs with 0 failures, and the conformance baseline). yard --no-output passes.

  • Automated unit / integration tests
  • Tested manually
  • Tested in a real application

Breaking Changes

None for clients that declare capabilities as objects. sampling: true with tools now raises RuntimeError instead of TypeError.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Test update (non-breaking change which adds or updates tests)
  • Refactoring (non-breaking change which makes things better)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • CI/build script update (update CI workflow or build scripts)

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • I have added automated tests for my change
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

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

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.

Sampling with tools raises TypeError for a scalar sampling capability

1 participant