Support Sorbet typed tools
This commit is contained in:
parent
87cd467c58
commit
84e83841b0
1 changed files with 92 additions and 1 deletions
|
|
@ -197,7 +197,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
|
||||
|
|
@ -258,5 +259,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
|
||||
|
|
|
|||
Loading…
Reference in a new issue