File tree 5 files changed +59
-1
lines changed
lib/model_context_protocol
5 files changed +59
-1
lines changed Original file line number Diff line number Diff line change 91
91
ruby-progressbar (1.13.0 )
92
92
ruby2_keywords (0.0.5 )
93
93
securerandom (0.4.1 )
94
+ sorbet (0.5.11495 )
95
+ sorbet-static (= 0.5.11495 )
96
+ sorbet-runtime (0.5.11495 )
97
+ sorbet-static (0.5.11495-universal-darwin )
98
+ sorbet-static-and-runtime (0.5.11495 )
99
+ sorbet (= 0.5.11495 )
100
+ sorbet-runtime (= 0.5.11495 )
94
101
stringio (3.1.7 )
95
102
tzinfo (2.0.6 )
96
103
concurrent-ruby (~> 1.0 )
@@ -112,6 +119,7 @@ DEPENDENCIES
112
119
model_context_protocol !
113
120
rake (~> 13.0 )
114
121
rubocop-shopify
122
+ sorbet-static-and-runtime
115
123
116
124
BUNDLED WITH
117
125
2.5.9
Original file line number Diff line number Diff line change @@ -193,7 +193,8 @@ def call_tool(request)
193
193
end
194
194
195
195
begin
196
- call_params = tool . method ( :call ) . parameters . flatten
196
+ call_params = method_parameters ( tool . method ( :call ) )
197
+
197
198
if call_params . include? ( :server_context )
198
199
tool . call ( **arguments . transform_keys ( &:to_sym ) , server_context :) . to_h
199
200
else
@@ -254,5 +255,21 @@ def index_resources_by_uri(resources)
254
255
hash [ resource . uri ] = resource
255
256
end
256
257
end
258
+
259
+ def method_parameters ( method )
260
+ default_value = method . parameters . flatten
261
+
262
+ if defined? ( T ::Utils ) && T ::Utils . respond_to? ( :signature_for_method )
263
+ method_sig = T ::Utils . signature_for_method ( method )
264
+
265
+ if method_sig
266
+ method_sig . parameters . flatten
267
+ else
268
+ default_value
269
+ end
270
+ else
271
+ default_value
272
+ end
273
+ end
257
274
end
258
275
end
Original file line number Diff line number Diff line change @@ -29,4 +29,5 @@ Gem::Specification.new do |spec|
29
29
30
30
spec . add_dependency ( "json_rpc_handler" , "~> 0.1" )
31
31
spec . add_development_dependency ( "activesupport" )
32
+ spec . add_development_dependency ( "sorbet-static-and-runtime" )
32
33
end
Original file line number Diff line number Diff line change
1
+ # typed: true
1
2
# frozen_string_literal: true
2
3
3
4
require "test_helper"
@@ -203,5 +204,34 @@ class UpdatableAnnotationsTool < Tool
203
204
tool . annotations ( title : "Updated" )
204
205
assert_equal tool . annotations_value . title , "Updated"
205
206
end
207
+
208
+ test "#call with Sorbet typed tools invokes the tool block and returns the response" do
209
+ class TypedTestTool < Tool
210
+ tool_name "test_tool"
211
+ description "a test tool for testing"
212
+ input_schema ( { properties : { message : { type : "string" } } , required : [ "message" ] } )
213
+ annotations (
214
+ title : "Test Tool" ,
215
+ read_only_hint : true ,
216
+ destructive_hint : false ,
217
+ idempotent_hint : true ,
218
+ open_world_hint : false ,
219
+ )
220
+
221
+ class << self
222
+ extend T ::Sig
223
+
224
+ sig { params ( message : String , server_context : T . nilable ( T . untyped ) ) . returns ( Tool ::Response ) }
225
+ def call ( message , server_context : nil )
226
+ Tool ::Response . new ( [ { type : "text" , content : "OK" } ] )
227
+ end
228
+ end
229
+ end
230
+
231
+ tool = TypedTestTool
232
+ response = tool . call ( "test" )
233
+ assert_equal response . content , [ { type : "text" , content : "OK" } ]
234
+ assert_equal response . is_error , false
235
+ end
206
236
end
207
237
end
Original file line number Diff line number Diff line change 13
13
require "active_support"
14
14
require "active_support/test_case"
15
15
16
+ require "sorbet-runtime"
17
+
16
18
require_relative "instrumentation_test_helper"
17
19
18
20
Minitest ::Reporters . use! ( Minitest ::Reporters ::ProgressReporter . new )
You can’t perform that action at this time.
0 commit comments