Merge pull request #445 from rickreyhsig-wealthbox/client-tool-annotations

Expose server tool annotations on MCP::Client::Tool
This commit is contained in:
Koichi ITO 2026-07-28 01:21:53 +09:00 • committed by GitHub
commit 5a879b3678
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 27 additions and 2 deletions

View file

@ -166,6 +166,7 @@ module MCP
description: tool["description"],
input_schema: tool["inputSchema"],
output_schema: tool["outputSchema"],
annotations: tool["annotations"],
)
end

View file

@ -3,13 +3,14 @@
module MCP
class Client
class Tool
attr_reader :name, :description, :input_schema, :output_schema
attr_reader :name, :description, :input_schema, :output_schema, :annotations
def initialize(name:, description:, input_schema:, output_schema: nil)
def initialize(name:, description:, input_schema:, output_schema: nil, annotations: nil)
@name = name
@description = description
@input_schema = input_schema
@output_schema = output_schema
@annotations = annotations
end
end
end

View file

@ -33,6 +33,24 @@ module MCP
assert_nil(@tool.output_schema)
end
def test_annotations_returns_nil_when_not_provided
assert_nil(@tool.annotations)
end
def test_annotations_returns_annotations_when_provided
tool_with_annotations = Tool.new(
name: "test_tool_with_annotations",
description: "A test tool with annotations",
input_schema: { "type" => "object" },
annotations: { "readOnlyHint" => true, "title" => "Test Tool" },
)
assert_equal(
{ "readOnlyHint" => true, "title" => "Test Tool" },
tool_with_annotations.annotations,
)
end
def test_output_schema_returns_output_schema_when_provided
tool_with_output = Tool.new(
name: "test_tool_with_output",
@ -53,12 +71,14 @@ module MCP
description: "A tool with all parameters",
input_schema: { "type" => "object" },
output_schema: { "type" => "object", "properties" => { "status" => { "type" => "boolean" } } },
annotations: { "readOnlyHint" => true },
)
assert_equal("full_tool", tool.name)
assert_equal("A tool with all parameters", tool.description)
assert_equal({ "type" => "object" }, tool.input_schema)
assert_equal({ "type" => "object", "properties" => { "status" => { "type" => "boolean" } } }, tool.output_schema)
assert_equal({ "readOnlyHint" => true }, tool.annotations)
end
end
end

View file

@ -124,6 +124,7 @@ module MCP
"description" => "tool1",
"inputSchema" => {},
"outputSchema" => { "type" => "object", "properties" => { "result" => { "type" => "string" } } },
"annotations" => { "readOnlyHint" => true, "title" => "Tool One" },
},
{ "name" => "tool2", "description" => "tool2", "inputSchema" => {} },
],
@ -141,8 +142,10 @@ module MCP
assert_equal(2, tools.size)
assert_equal("tool1", tools.first.name)
assert_equal({ "type" => "object", "properties" => { "result" => { "type" => "string" } } }, tools.first.output_schema)
assert_equal({ "readOnlyHint" => true, "title" => "Tool One" }, tools.first.annotations)
assert_equal("tool2", tools.last.name)
assert_nil(tools.last.output_schema)
assert_nil(tools.last.annotations)
end
def test_tools_returns_empty_array_when_no_tools