Skip to content

Add range validation for MCP::Annotations#priority per MCP specification#410

Merged
koic merged 1 commit into
modelcontextprotocol:mainfrom
yuki3738:add_priority_validation_to_annotations
Jun 15, 2026
Merged

Add range validation for MCP::Annotations#priority per MCP specification#410
koic merged 1 commit into
modelcontextprotocol:mainfrom
yuki3738:add_priority_validation_to_annotations

Conversation

@yuki3738

Copy link
Copy Markdown
Contributor

Motivation and Context

The MCP specification constrains Annotations.priority to the 0–1 range (@minimum 0, @maximum 1) (schema), but the Ruby SDK accepts any value. The other official SDKs already enforce this (TypeScript, Python, and PHP).

This follows the existing pattern in MCP::Icon, which validates its constrained theme value in the constructor and raises ArgumentError.

How Has This Been Tested?

Added tests in test/mcp/annotations_test.rb:

  • valid priority at the lower (0) and upper (1) bounds is accepted
  • out-of-range priority (above 1, below 0) raises ArgumentError

The full unit suite and RuboCop pass locally.

Breaking Changes

Strictly speaking yes: a caller that currently passes an out-of-range priority (e.g. priority: 99) will now get an ArgumentError. Such values already violate the MCP specification, and nil / in-range values are unaffected.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

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

…ation

## Motivation and Context

The MCP specification constrains `Annotations.priority` to the 0–1 range
(`@minimum 0`, `@maximum 1`), but the Ruby SDK accepts any value. The other
official SDKs already enforce this (TypeScript, Python, and PHP).

This follows the existing pattern in `MCP::Icon`, which validates its
constrained `theme` value in the constructor and raises `ArgumentError`.

## How Has This Been Tested?

Added tests in `test/mcp/annotations_test.rb`:

- valid `priority` at the lower (0) and upper (1) bounds is accepted
- out-of-range `priority` (above 1, below 0) raises `ArgumentError`

The full unit suite and RuboCop pass locally.

## Breaking Changes

Strictly speaking yes: a caller that currently passes an out-of-range
`priority` (e.g. `priority: 99`) will now get an `ArgumentError`. Such values
already violate the MCP specification, and `nil` / in-range values are
unaffected.
@koic koic merged commit acec71d into modelcontextprotocol:main Jun 15, 2026
11 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.

2 participants