Skip to content

Conversation

tuntisz
Copy link
Contributor

@tuntisz tuntisz commented Aug 31, 2025

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 approach
class MyTool < MCP::Tool
  tool_name "my_tool"
  description "Example tool with metadata"
  metadata({ "example.com/priority" => "high" })
end

# Define method approach
server.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

@tuntisz tuntisz force-pushed the tau/support-_meta-field branch from 0f5b460 to 3127bb6 Compare September 1, 2025 13:59
@tuntisz tuntisz requested a review from koic September 1, 2025 14:04
@codenamev
Copy link
Contributor

I really need this! Looking forward to seeing this.

Copy link
Contributor

@topherbullock topherbullock left a comment

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!

Co-authored-by: Ateş Göral <[email protected]>
Co-authored-by: Ateş Göral <[email protected]>
@atesgoral atesgoral merged commit 73cec83 into modelcontextprotocol:main Oct 1, 2025
5 checks passed
@topherbullock topherbullock mentioned this pull request Oct 15, 2025
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.

5 participants