@@ -16,6 +16,9 @@ class TestTool < Tool
1616 read_only_hint : true ,
1717 title : "Test Tool" ,
1818 )
19+ metadata (
20+ foo : "bar" ,
21+ )
1922
2023 class << self
2124 def call ( message :, server_context : nil )
@@ -45,6 +48,14 @@ def call(message:, server_context: nil)
4548 assert_equal expected_annotations , tool . to_h [ :annotations ]
4649 end
4750
51+ test "#to_h includes metadata when present" do
52+ tool = TestTool
53+ expected_metadata = {
54+ foo : "bar" ,
55+ }
56+ assert_equal expected_metadata , tool . to_h [ :_meta ]
57+ end
58+
4859 test "#call invokes the tool block and returns the response" do
4960 tool = TestTool
5061 response = tool . call ( message : "test" )
@@ -145,6 +156,23 @@ class InputSchemaTool < Tool
145156 assert_equal ( { destructiveHint : true , idempotentHint : false , openWorldHint : true , readOnlyHint : true , title : "Mock Tool" } , tool . annotations_value . to_h )
146157 end
147158
159+ test ".define allows definition of tools with metadata" do
160+ tool = Tool . define (
161+ name : "mock_tool" ,
162+ title : "Mock Tool" ,
163+ description : "a mock tool for testing" ,
164+ metadata : { foo : "bar" } ,
165+ ) do |_ |
166+ Tool ::Response . new ( [ { type : "text" , content : "OK" } ] )
167+ end
168+
169+ assert_equal "mock_tool" , tool . name_value
170+ assert_equal "Mock Tool" , tool . title
171+ assert_equal "a mock tool for testing" , tool . description
172+ assert_equal tool . input_schema , Tool ::InputSchema . new
173+ assert_equal ( { foo : "bar" } , tool . metadata_value )
174+ end
175+
148176 test "Tool class method annotations can be set and retrieved" do
149177 class AnnotationsTestTool < Tool
150178 tool_name "annotations_test"
@@ -173,6 +201,30 @@ class UpdatableAnnotationsTool < Tool
173201 assert_equal "Updated" , tool . annotations_value . title
174202 end
175203
204+ test "Tool class method metadata can be set and retrieved" do
205+ class MetadataTestTool < Tool
206+ tool_name "annotations_test"
207+ metadata ( foo : "bar" )
208+ end
209+
210+ tool = MetadataTestTool
211+ assert_instance_of Hash , tool . metadata_value
212+ assert_equal "bar" , tool . metadata_value [ :foo ]
213+ end
214+
215+ test "Tool class method metadata can be updated" do
216+ class UpdatableMetadataTool < Tool
217+ tool_name "updatable_metadata"
218+ end
219+
220+ tool = UpdatableMetadataTool
221+ tool . metadata ( foo : "baz" )
222+ assert_equal ( { foo : "baz" } , tool . metadata_value )
223+
224+ tool . metadata ( foo : "qux" )
225+ assert_equal ( { foo : "qux" } , tool . metadata_value )
226+ end
227+
176228 test "#call with Sorbet typed tools invokes the tool block and returns the response" do
177229 class TypedTestTool < Tool
178230 tool_name "test_tool"
0 commit comments