Add audience role validation for MCP::Annotations per MCP specification#4
Draft
yuki3738 wants to merge 1 commit into
Draft
Add audience role validation for MCP::Annotations per MCP specification#4yuki3738 wants to merge 1 commit into
audience role validation for MCP::Annotations per MCP specification#4yuki3738 wants to merge 1 commit into
Conversation
…cation ## Motivation and Context 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`. ## How Has This Been Tested? Added tests in `test/mcp/annotations_test.rb`: - valid `audience` (`["user"]`, `["assistant"]`, `["user", "assistant"]`) is accepted - an unknown role 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. ## Breaking Changes Strictly speaking yes: 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.
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 anyvalue. The other official SDKs already enforce this (TypeScript, Python,
and PHP).
This follows the existing pattern in
MCP::Icon, which validates itsconstrained
themevalue in the constructor and raisesArgumentError.How Has This Been Tested?
Added tests in
test/mcp/annotations_test.rb:audience(["user"],["assistant"],["user", "assistant"])is accepted
audienceraisesArgumentErrorExisting 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.