Skip to content

Add annotations field to MCP::Resource and MCP::ResourceTemplate per MCP specification#403

Merged
koic merged 1 commit into
modelcontextprotocol:mainfrom
yuki3738:add_annotations_field_to_resource
Jun 14, 2026
Merged

Add annotations field to MCP::Resource and MCP::ResourceTemplate per MCP specification#403
koic merged 1 commit into
modelcontextprotocol:mainfrom
yuki3738:add_annotations_field_to_resource

Conversation

@yuki3738

Copy link
Copy Markdown
Contributor

Motivation and Context

The MCP specification defines an optional annotations field on both the Resource and ResourceTemplate types (spec), but the Ruby SDK is the only official SDK that does not wire it up — TypeScript, Python, and PHP all implement it.

The MCP::Annotations class already exists; this PR connects it. The field accepts an MCP::Annotations instance rather than a raw hash, for consistency with other typed fields and to get lastModified key normalization for free.

How Has This Been Tested?

Added tests in test/mcp/resource_test.rb and test/mcp/resource_template_test.rb:

  • #to_h omits annotations when nil
  • #to_h includes annotations when present (also asserting that last_modified is serialized as lastModified)

The full unit suite and RuboCop pass locally.

Breaking Changes

None. annotations: is a new optional keyword argument defaulting to nil, and it is omitted from #to_h output when not set.

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

…` per MCP specification

## Motivation and Context

The MCP specification defines an optional `annotations` field on both the
`Resource` and `ResourceTemplate` types, but the Ruby SDK is the only official
SDK that does not wire it up — TypeScript, Python, and PHP all implement it.
https://modelcontextprotocol.io/specification/2025-11-25/server/resources#annotations

The `MCP::Annotations` class already exists; this commit connects it. The field
accepts an `MCP::Annotations` instance rather than a raw hash, for consistency
with other typed fields and to get `lastModified` key normalization for free.

## How Has This Been Tested?

Added tests in `test/mcp/resource_test.rb` and
`test/mcp/resource_template_test.rb`:

- `#to_h` omits `annotations` when nil
- `#to_h` includes `annotations` when present (also asserting that
  `last_modified` is serialized as `lastModified`)

The full unit suite and RuboCop pass locally.

## Breaking Changes

None. `annotations:` is a new optional keyword argument defaulting to `nil`,
and it is omitted from `#to_h` output when not set.
@koic koic merged commit 3a163ad into modelcontextprotocol:main Jun 14, 2026
11 checks passed
@koic

koic commented Jun 14, 2026

Copy link
Copy Markdown
Member

Thanks!

@yuki3738 yuki3738 deleted the add_annotations_field_to_resource branch June 14, 2026 15:57
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