Add annotations field to MCP::Resource and MCP::ResourceTemplate per MCP specification#2
Open
yuki3738 wants to merge 1 commit into
Open
Add annotations field to MCP::Resource and MCP::ResourceTemplate per MCP specification#2yuki3738 wants to merge 1 commit into
annotations field to MCP::Resource and MCP::ResourceTemplate per MCP specification#2yuki3738 wants to merge 1 commit into
Conversation
…` per MCP specification ## Motivation and Context The MCP specification defines an optional `annotations` field on both the `Resource` and `ResourceTemplate` types: https://modelcontextprotocol.io/specification/2025-11-25/server/resources#annotations Annotations provide hints to clients about how to use or display a resource (`audience`, `priority`, `lastModified`). The SDK already ships the `MCP::Annotations` class, and `MCP::Tool` and the content classes already accept annotations, but plain `MCP::Resource` and `MCP::ResourceTemplate` had no way to declare them. Following `MCP::Tool`'s pattern, the field accepts an `MCP::Annotations` instance and serializes it via `annotations&.to_h`, which also normalizes `last_modified` to the spec's `lastModified` key. ## 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.
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 defines an optional
annotationsfield on both theResourceandResourceTemplatetypes:https://modelcontextprotocol.io/specification/2025-11-25/server/resources#annotations
Annotations provide hints to clients about how to use or display a resource (
audience,priority,lastModified).The SDK already ships the
MCP::Annotationsclass, andMCP::Tooland the content classes already accept annotations, but plainMCP::ResourceandMCP::ResourceTemplatehad no way to declare them.Following
MCP::Tool's pattern, the field accepts anMCP::Annotationsinstance and serializes it viaannotations&.to_h, which also normalizeslast_modifiedto the spec'slastModifiedkey.How Has This Been Tested?
Added tests in
test/mcp/resource_test.rbandtest/mcp/resource_template_test.rb:#to_homitsannotationswhen nil#to_hincludesannotationswhen present (also asserting thatlast_modifiedis serialized aslastModified)The full unit suite and RuboCop pass locally.
Breaking Changes
None.
annotations:is a new optional keyword argument defaulting tonil, and it is omitted from#to_houtput when not set.Types of changes
Checklist