Skip to content

Add support for _meta field on tool schema - #124

Merged
atesgoral merged 6 commits into
modelcontextprotocol:mainfrom
tuntisz:tau/support-_meta-field
Oct 1, 2025
Merged

Add support for _meta field on tool schema#124
atesgoral merged 6 commits into
modelcontextprotocol:mainfrom
tuntisz:tau/support-_meta-field

Conversation

@tuntisz

@tuntisztuntisz commented Aug 31, 2025

Copy link
Copy Markdown
Contributor

Motivation and Context

This PR adds support for the _meta property in tool definitions, bringing the Ruby SDK to feature parity with the TypeScript SDK and other official MCP implementations. Previously, Ruby-based MCP servers couldn't attach metadata to tools, limiting interoperability with protocol extensions that rely on this standard field. Resolves issue #123 .

How Has This Been Tested?

  • Added comprehensive unit tests for the metadata functionality in test/mcp/tool_test.rb
  • Tests verify metadata can be set via both class-based and define method approaches
  • Tests confirm _meta appears correctly in tool serialization for tools/list responses
  • Verified metadata is optional and doesn't break existing tool definitions
  • Ran the official MCP inspector ensuring that the server returns the expect _meta field. Screenshot below

Breaking Changes

None. The metadata parameter is optional and existing code continues to work unchanged.

Types of changes

  • New feature (non-breaking change which adds functionality)

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

Additional context

The implementation follows the MCP specification exactly:

  • Metadata is exposed as _meta in the serialized tool schema (matching the spec)
  • The Ruby API uses metadata for consistency with other SDK methods
  • Both class-based and define method approaches are supported

Example usage:

# Class-based approachclassMyTool < MCP::Tooltool_name"my_tool"description"Example tool with metadata"metadata({"example.com/priority"=>"high"})end# Define method approachserver.define_tool(name: "my_tool",description: "Example tool",metadata: {"internal-id"=>"tool-123"})do |args|
MCP::Tool::Response.new([{type: "text",text: "OK"}])end
Image

Comment threadlib/mcp/tool.rb
@tuntisz
tuntiszforce-pushed the tau/support-_meta-field branch from 0f5b460 to 3127bb6CompareSeptember 1, 2025 13:59
@tuntisz
tuntisz requested a review from koicSeptember 1, 2025 14:04
@codenamev

Copy link
Copy Markdown
Contributor

I really need this! Looking forward to seeing this.

Comment threadlib/mcp/server.rb Outdated

@topherbullocktopherbullock left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please update the name to meta to closely match the field's name in the spec?

LGTM otherwise, thanks @tuntisz!

Comment threadlib/mcp/server.rb Outdated
Comment threadlib/mcp/server.rb Outdated
Comment threadlib/mcp/server.rb Outdated
Comment threadlib/mcp/tool.rb Outdated
Comment threadlib/mcp/tool.rb Outdated
Comment threadlib/mcp/tool.rb Outdated
Comment threadlib/mcp/tool.rb Outdated
Comment threadlib/mcp/tool.rb Outdated
Comment threadtest/mcp/server_test.rb Outdated
Comment threadtest/mcp/server_test.rb Outdated
Comment threadtest/mcp/tool_test.rb Outdated
Comment threadtest/mcp/tool_test.rb Outdated
Comment threadtest/mcp/tool_test.rb Outdated
Comment threadtest/mcp/tool_test.rb Outdated
Co-authored-by: Ateş Göral <ates@magnetiq.com>
Comment threadlib/mcp/tool.rb Outdated
Co-authored-by: Ateş Göral <ates@magnetiq.com>
Comment threadlib/mcp/tool.rb
Co-authored-by: Ateş Göral <ates@magnetiq.com>
@atesgoral
atesgoral merged commit 73cec83 into modelcontextprotocol:mainOct 1, 2025
5 checks passed
@topherbullocktopherbullock mentioned this pull request Oct 15, 2025
Sign up for freeto 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.

5 participants

@tuntisz@codenamev@koic@atesgoral@topherbullock