Skip to content

fix: enforce declared client capabilities and modes - #731

Merged
koic merged 1 commit into
modelcontextprotocol:mainfrom
yorzi:fix/falsy-and-url-only-client-capabilities
Dec 1, 2026
Merged

koic merged 1 commit into
modelcontextprotocol:mainfrom
yorzi:fix/falsy-and-url-only-client-capabilities

Conversation

@yorzi

@yorzi yorzi commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Form elicitation is no longer sent to clients that declare only URL mode, and a capability declared as false counts as not declared.

Fixes #728

Motivation and Context

create_form_elicitation sends to any client that declares elicitation, including one that declares only elicitation.url, which the specification forbids. The input_required check and require_client_capability! take false as declared, and create_url_elicitation raises TypeError on a declaration that is not an object.

The lookup (symbol or string keys) and the mode rule move to a private ClientCapabilities module used by all of them. The rule is the one the input_required check already had: form mode is declared by elicitation.form, or implied when neither form nor url is declared. That keeps elicitation: {} working, as well as declarations with other members, such as the top-level applyDefaults of TypeScript SDK 1.22.0.

How Has This Been Tested?

  • Automated unit / integration tests

  • Tested manually

  • Tested in a real application

  • test/mcp/server_elicitation_test.rb: form mode is refused for a URL-only, false or non-object declaration, and accepted when neither mode or both are declared. URL mode is refused for a non-object declaration.

  • test/mcp/server/input_required_result_test.rb and test/mcp/server_context_test.rb: false counts as not declared, and form mode is implied when neither mode is declared.

Five of the seven tests fail on main; the two for accepted declarations guard existing behavior. Reverting any one part of the change fails one of them. The fixture of test/mcp/server_session_request_timeout_test.rb declared only URL mode while sending a form request, so it now declares both. bundle exec rake test (2,815 tests, 10,202 assertions on Ruby 4.0.9; also run on 2.7), bundle exec rake rubocop, bundle exec yard --no-output and bundle exec rake conformance:test (baseline) pass locally.

Breaking Changes

None for clients that declare the modes they support. A server that sends form requests to a URL-only client, or to one declaring elicitation as something other than an object, now gets the RuntimeError documented for an unsupported client.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change that 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 (docs/_server/elicitation.md)

Additional context

The TypeScript server's session check refuses form mode unless form is declared or elicitation is empty; its multi round-trip check and the Python SDK's also accept other members. This PR uses one rule for both, so no declaration the input_required check accepts today is refused, apart from capabilities set to false. Using the stricter rule for sessions is easy if you prefer it.

## Motivation and Context

`create_form_elicitation` sends to any client that declares `elicitation`, including one that declares only
`elicitation.url`, which the specification forbids. The `input_required` check and `require_client_capability!` take
`false` as declared, and `create_url_elicitation` raises `TypeError` on a declaration that is not an object.

The lookup (symbol or string keys) and the mode rule move to a private `ClientCapabilities` module used by all of
them. The rule is the one the `input_required` check already had: form mode is declared by `elicitation.form`, or
implied when neither `form` nor `url` is declared. That keeps `elicitation: {}` working, as well as declarations with
other members, such as the top-level `applyDefaults` of TypeScript SDK 1.22.0.

## How Has This Been Tested?

- `test/mcp/server_elicitation_test.rb`: form mode is refused for a URL-only, `false` or non-object declaration, and
  accepted when neither mode or both are declared. URL mode is refused for a non-object declaration.
- `test/mcp/server/input_required_result_test.rb` and `test/mcp/server_context_test.rb`: `false` counts as not
  declared, and form mode is implied when neither mode is declared.

Five of the seven tests fail on `main`; the two for accepted declarations guard existing behavior. Reverting any one
part of the change fails one of them. The fixture of `test/mcp/server_session_request_timeout_test.rb` declared only
URL mode while sending a form request, so it now declares both.

## Breaking Changes

None for clients that declare the modes they support. A server that sends form requests to a URL-only client, or to
one declaring `elicitation` as something other than an object, now gets the `RuntimeError` documented for an
unsupported client.

Fixes modelcontextprotocol#728.
@koic
koic merged commit 810c45c into modelcontextprotocol:main Dec 1, 2026
13 checks passed
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.

Form elicitation is sent to URL-only clients, and capabilities declared as false count as declared

2 participants