Skip to content

Commit 5a879b3

Browse files
authored
Merge pull request #445 from rickreyhsig-wealthbox/client-tool-annotations
Expose server tool annotations on MCP::Client::Tool
2 parents 565f4de + 3591acd commit 5a879b3

4 files changed

Lines changed: 27 additions & 2 deletions

File tree

lib/mcp/client.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ def list_tools(cursor: nil, meta: nil, cancellation: nil)
166166
description: tool["description"],
167167
input_schema: tool["inputSchema"],
168168
output_schema: tool["outputSchema"],
169+
annotations: tool["annotations"],
169170
)
170171
end
171172

lib/mcp/client/tool.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
module MCP
44
class Client
55
class Tool
6-
attr_reader :name, :description, :input_schema, :output_schema
6+
attr_reader :name, :description, :input_schema, :output_schema, :annotations
77

8-
def initialize(name:, description:, input_schema:, output_schema: nil)
8+
def initialize(name:, description:, input_schema:, output_schema: nil, annotations: nil)
99
@name = name
1010
@description = description
1111
@input_schema = input_schema
1212
@output_schema = output_schema
13+
@annotations = annotations
1314
end
1415
end
1516
end

test/mcp/client/tool_test.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@ def test_output_schema_returns_nil_when_not_provided
3333
assert_nil(@tool.output_schema)
3434
end
3535

36+
def test_annotations_returns_nil_when_not_provided
37+
assert_nil(@tool.annotations)
38+
end
39+
40+
def test_annotations_returns_annotations_when_provided
41+
tool_with_annotations = Tool.new(
42+
name: "test_tool_with_annotations",
43+
description: "A test tool with annotations",
44+
input_schema: { "type" => "object" },
45+
annotations: { "readOnlyHint" => true, "title" => "Test Tool" },
46+
)
47+
48+
assert_equal(
49+
{ "readOnlyHint" => true, "title" => "Test Tool" },
50+
tool_with_annotations.annotations,
51+
)
52+
end
53+
3654
def test_output_schema_returns_output_schema_when_provided
3755
tool_with_output = Tool.new(
3856
name: "test_tool_with_output",
@@ -53,12 +71,14 @@ def test_initialization_with_all_parameters
5371
description: "A tool with all parameters",
5472
input_schema: { "type" => "object" },
5573
output_schema: { "type" => "object", "properties" => { "status" => { "type" => "boolean" } } },
74+
annotations: { "readOnlyHint" => true },
5675
)
5776

5877
assert_equal("full_tool", tool.name)
5978
assert_equal("A tool with all parameters", tool.description)
6079
assert_equal({ "type" => "object" }, tool.input_schema)
6180
assert_equal({ "type" => "object", "properties" => { "status" => { "type" => "boolean" } } }, tool.output_schema)
81+
assert_equal({ "readOnlyHint" => true }, tool.annotations)
6282
end
6383
end
6484
end

test/mcp/client_test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ def test_tools_sends_request_to_transport_and_returns_tools_array
124124
"description" => "tool1",
125125
"inputSchema" => {},
126126
"outputSchema" => { "type" => "object", "properties" => { "result" => { "type" => "string" } } },
127+
"annotations" => { "readOnlyHint" => true, "title" => "Tool One" },
127128
},
128129
{ "name" => "tool2", "description" => "tool2", "inputSchema" => {} },
129130
],
@@ -141,8 +142,10 @@ def test_tools_sends_request_to_transport_and_returns_tools_array
141142
assert_equal(2, tools.size)
142143
assert_equal("tool1", tools.first.name)
143144
assert_equal({ "type" => "object", "properties" => { "result" => { "type" => "string" } } }, tools.first.output_schema)
145+
assert_equal({ "readOnlyHint" => true, "title" => "Tool One" }, tools.first.annotations)
144146
assert_equal("tool2", tools.last.name)
145147
assert_nil(tools.last.output_schema)
148+
assert_nil(tools.last.annotations)
146149
end
147150

148151
def test_tools_returns_empty_array_when_no_tools

0 commit comments

Comments
 (0)