Skip to content

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

Merged
koic merged 1 commit into
modelcontextprotocol:mainfrom
yuki3738:add_audience_validation_to_annotations
Jun 21, 2026
Merged

Add audience role validation for MCP::Annotations per MCP specification#422
koic merged 1 commit into
modelcontextprotocol:mainfrom
yuki3738:add_audience_validation_to_annotations

Conversation

@yuki3738

Copy link
Copy Markdown
Contributor

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"],
    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.

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.

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

…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.
@koic koic merged commit 6bf0a06 into modelcontextprotocol:main Jun 21, 2026
11 checks passed
@koic

koic commented Jun 21, 2026

Copy link
Copy Markdown
Member

Thanks!

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.

2 participants