Add _meta field to resource, content, and result classes#310
Open
koic wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
Add _meta field to resource, content, and result classes#310koic wants to merge 1 commit intomodelcontextprotocol:mainfrom
_meta field to resource, content, and result classes#310koic wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
## Motivation and Context MCP 2025-11-25 spec defines a `_meta` general field on many types, but the Ruby SDK only exposed it on `Tool` and `Prompt`. To attach metadata (e.g. MCP Apps CSP hints on resource contents), consumers had to subclass existing classes and override `to_h`. Add a `meta:` keyword argument and `_meta` serialization to: - `Resource::Contents`, `Resource::TextContents`, `Resource::BlobContents` - `Resource`, `ResourceTemplate` - `Content::Text`, `Content::Image`, `Content::Audio`, `Content::EmbeddedResource` - `Tool::Response` (`CallToolResult`) - `Prompt::Result` (`GetPromptResult`) This aligns the Ruby SDK with the Python and TypeScript SDKs, which both expose `_meta` on these types. Resolves modelcontextprotocol#308. ## How Has This Been Tested? Added unit tests for each updated class covering two patterns: `_meta` present (asserts the value is reflected in `to_h[:_meta]`) and `_meta` omitted (asserts no `:_meta` key in `to_h`, i.e., `.compact` behavior). All existing tests continue to pass, and `rake rubocop` is clean. ## Breaking Changes None. All new `meta:` parameters are optional keyword arguments defaulting to `nil`. The `to_h` output stays backward-compatible because `nil` values are removed by the existing `.compact` call, so existing callers require no changes.
atesgoral
approved these changes
Apr 11, 2026
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
MCP 2025-11-25 spec defines a
_metageneral field on many types, but the Ruby SDK only exposed it onToolandPrompt. To attach metadata (e.g. MCP Apps CSP hints on resource contents), consumers had to subclass existing classes and overrideto_h.Add a
meta:keyword argument and_metaserialization to:Resource::Contents,Resource::TextContents,Resource::BlobContentsResource,ResourceTemplateContent::Text,Content::Image,Content::Audio,Content::EmbeddedResourceTool::Response(CallToolResult)Prompt::Result(GetPromptResult)This aligns the Ruby SDK with the Python and TypeScript SDKs, which both expose
_metaon these types.Resolves #308.
How Has This Been Tested?
Added unit tests for each updated class covering two patterns:
_metapresent (asserts the value is reflected into_h[:_meta]) and_metaomitted (asserts no:_metakey into_h, i.e.,.compactbehavior). All existing tests continue to pass, andrake rubocopis clean.Breaking Changes
None. All new
meta:parameters are optional keyword arguments defaulting tonil. Theto_houtput stays backward-compatible becausenilvalues are removed by the existing.compactcall, so existing callers require no changes.Types of changes
Checklist