Skip to content

Commit 3591acd

Browse files
Expose server tool annotations on MCP::Client::Tool
Client#tools/#list_tools built Tool objects without an annotations field even though the server includes annotations in every tools/list response. Add the reader and pass the raw hash through, mirroring how output_schema is already handled.
1 parent 61233ed commit 3591acd

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
@@ -131,6 +131,7 @@ def list_tools(cursor: nil, meta: nil, cancellation: nil)
131131
description: tool["description"],
132132
input_schema: tool["inputSchema"],
133133
output_schema: tool["outputSchema"],
134+
annotations: tool["annotations"],
134135
)
135136
end
136137

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
@@ -86,6 +86,7 @@ def test_tools_sends_request_to_transport_and_returns_tools_array
8686
"description" => "tool1",
8787
"inputSchema" => {},
8888
"outputSchema" => { "type" => "object", "properties" => { "result" => { "type" => "string" } } },
89+
"annotations" => { "readOnlyHint" => true, "title" => "Tool One" },
8990
},
9091
{ "name" => "tool2", "description" => "tool2", "inputSchema" => {} },
9192
],
@@ -103,8 +104,10 @@ def test_tools_sends_request_to_transport_and_returns_tools_array
103104
assert_equal(2, tools.size)
104105
assert_equal("tool1", tools.first.name)
105106
assert_equal({ "type" => "object", "properties" => { "result" => { "type" => "string" } } }, tools.first.output_schema)
107+
assert_equal({ "readOnlyHint" => true, "title" => "Tool One" }, tools.first.annotations)
106108
assert_equal("tool2", tools.last.name)
107109
assert_nil(tools.last.output_schema)
110+
assert_nil(tools.last.annotations)
108111
end
109112

110113
def test_tools_returns_empty_array_when_no_tools

0 commit comments

Comments
 (0)