Skip to content

Add audience role validation for MCP::Annotations per MCP specification#4

Draft
yuki3738 wants to merge 1 commit into
mainfrom
add_audience_validation_to_annotations
Draft

Add audience role validation for MCP::Annotations per MCP specification#4
yuki3738 wants to merge 1 commit into
mainfrom
add_audience_validation_to_annotations

Conversation

@yuki3738

Copy link
Copy Markdown
Owner

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.

…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.
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.

1 participant