Merge pull request #10 from chrisbutcher/fix-sorbet-runtime-compatibility

Support Sorbet typed tools
This commit is contained in:
Ateş Göral 2025-05-26 20:01:05 -04:00 • committed by GitHub
commit 34fa53c305
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -213,7 +213,8 @@ module ModelContextProtocol
end
begin
call_params = tool.method(:call).parameters.flatten
call_params = tool_call_parameters(tool)
if call_params.include?(:server_context)
tool.call(**arguments.transform_keys(&:to_sym), server_context:).to_h
else
@ -274,5 +275,24 @@ module ModelContextProtocol
hash[resource.uri] = resource
end
end
def tool_call_parameters(tool)
method_def = tool_call_method_def(tool)
method_def.parameters.flatten
end
def tool_call_method_def(tool)
method = tool.method(:call)
if defined?(T::Utils) && T::Utils.respond_to?(:signature_for_method)
sorbet_typed_method_definition = T::Utils.signature_for_method(method)&.method
# Return the Sorbet typed method definition if it exists, otherwise fallback to original method
# definition if Sorbet is defined but not used by this tool.
sorbet_typed_method_definition || method
else
method
end
end
end
end