Skip to content

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

Closed
yuki3738 wants to merge 3 commits into
mainfrom
add_priority_validation_to_annotations
Closed

Add range validation for MCP::Annotations#priority per MCP specification#3
yuki3738 wants to merge 3 commits into
mainfrom
add_priority_validation_to_annotations

Conversation

@yuki3738

Copy link
Copy Markdown
Owner

Note: This is a practice / self-review PR inside my own fork. Not the upstream contribution.

Motivation and Context

The MCP specification constrains Annotations.priority to the 0–1 range (@minimum 0, @maximum 1) (spec), 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

atesgoral and others added 3 commits June 14, 2026 17:46
Require rubocop-minitest 0.39.0 or newer so Minitest/AssertEmptyLiteral uses its newer default disabled state.
…eanup-existing-offenses

chore: require rubocop-minitest 0.39
…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.
@yuki3738 yuki3738 force-pushed the add_priority_validation_to_annotations branch from 25f0560 to c588582 Compare June 15, 2026 15:33
@yuki3738

Copy link
Copy Markdown
Owner Author

Practice/self-review complete. The real contribution is upstream at modelcontextprotocol#410.

@yuki3738 yuki3738 closed this Jun 15, 2026
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.

3 participants