Add audience role validation for MCP::Annotations per MCP specification#4
Closed
yuki3738 wants to merge 5 commits into
Closed
Add audience role validation for MCP::Annotations per MCP specification#4yuki3738 wants to merge 5 commits into
audience role validation for MCP::Annotations per MCP specification#4yuki3738 wants to merge 5 commits into
Conversation
New features and changes have landed, making it a good time to cut a release. Further feature proposals can be incorporated in future releases.
## Motivation and Context The gemspec already declares `required_ruby_version >= 2.7.0`, but `ServerContext` used the `...` arguments forwarding syntax in `method_missing`. That syntax was added in Ruby 2.7.3, so requiring the gem raised a `SyntaxError` on Ruby 2.7.0 through 2.7.2, and the library could not be loaded at all. RuboCop did not catch this because its Parser backend runs on Ruby 2.7.8, where the syntax is valid. CI missed it too because the test matrix tested `2.7`, which resolves to the latest 2.7.x rather than the declared minimum. ## How Has This Been Tested? Forward arguments explicitly with `*args, **kwargs, &block` so the method loads on Ruby 2.7.0, and pin the CI test matrix to 2.7.0 so the suite runs against the declared minimum instead of the latest 2.7.x. Running the suite on 2.7.0 also requires a `Hash.ruby2_keywords_hash?` shim in the test helper, since mocha would otherwise raise a `NoMethodError` on that version. ## Breaking Changes None. Closes modelcontextprotocol#418
…r_on_ruby_2_7_0 Fix a `SyntaxError` on Ruby 2.7.0 caused by arguments forwarding syntax
33d5800 to
7097dde
Compare
…cation The MCP specification constrains `Annotations.audience` to an array of `Role` values (`"user"` or `"assistant"`), 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`. Added tests in `test/mcp/annotations_test.rb`: - valid `audience` (`["user"]`, `["assistant"]`, `["user", "assistant"]`, and an empty array) is accepted - an unknown role, a mixed valid/invalid array, or a non-array `audience` raises `ArgumentError` Existing tests used `["developers"]`, which is not a valid `Role`, and are updated to `["user"]`. The full unit suite and RuboCop pass locally. Strictly speaking this is a breaking change: a caller that currently passes an invalid `audience` (e.g. `["developers"]`) will now get an `ArgumentError`. Such values already violate the MCP specification, and `nil` / valid-role values are unaffected.
7097dde to
4c3268c
Compare
Owner
Author
|
Practice/self-review complete. The real contribution is upstream at modelcontextprotocol#422. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
The MCP specification constrains
Annotations.audienceto an array ofRolevalues ("user"or"assistant"), 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 constrainedthemevalue in the constructor and raisesArgumentError.How Has This Been Tested?
Added tests in
test/mcp/annotations_test.rb:audience(["user"],["assistant"],["user", "assistant"],and an empty array) is accepted
audienceraises
ArgumentErrorExisting tests used
["developers"], which is not a validRole, and areupdated to
["user"].The full unit suite and RuboCop pass locally.
Breaking Changes
Strictly speaking yes: a caller that currently passes an invalid
audience(e.g.
["developers"]) will now get anArgumentError. Such values alreadyviolate the MCP specification, and
nil/ valid-role values are unaffected.