Skip to content

Commit acec71d

Browse files
authored
Merge pull request #410 from yuki3738/add_priority_validation_to_annotations
Add range validation for `MCP::Annotations#priority` per MCP specification
2 parents 2f24cdf + c588582 commit acec71d

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

‎lib/mcp/annotations.rb‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ class Annotations
55
attr_reader :audience, :priority, :last_modified
66

77
def initialize(audience: nil, priority: nil, last_modified: nil)
8+
raise ArgumentError, "The value of priority must be between 0 and 1." if priority && !priority.between?(0, 1)
9+
810
@audience = audience
911
@priority = priority
1012
@last_modified = last_modified

‎test/mcp/annotations_test.rb‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,31 @@ def test_initialization_with_last_modified_only
5555

5656
assert_equal({ lastModified: timestamp }, annotations.to_h)
5757
end
58+
59+
def test_valid_priority_at_lower_bound
60+
assert_nothing_raised do
61+
Annotations.new(priority: 0)
62+
end
63+
end
64+
65+
def test_valid_priority_at_upper_bound
66+
assert_nothing_raised do
67+
Annotations.new(priority: 1)
68+
end
69+
end
70+
71+
def test_invalid_priority_above_upper_bound
72+
exception = assert_raises(ArgumentError) do
73+
Annotations.new(priority: 1.5)
74+
end
75+
assert_equal("The value of priority must be between 0 and 1.", exception.message)
76+
end
77+
78+
def test_invalid_priority_below_lower_bound
79+
exception = assert_raises(ArgumentError) do
80+
Annotations.new(priority: -0.1)
81+
end
82+
assert_equal("The value of priority must be between 0 and 1.", exception.message)
83+
end
5884
end
5985
end

0 commit comments

Comments
 (0)