28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/action_mcp/server/tools.rb', line 28
def send_tools_call(request_id, tool_name, arguments, _meta = {}, task_params = nil)
tool_class = session.registered_tools.find { |t| t.tool_name == tool_name }
unless tool_class
Rails.logger.error "Tool not found: #{tool_name}. Registered tools: #{session.registered_tools.map(&:tool_name).join(', ')}"
send_jsonrpc_error(request_id, :method_not_found,
"Tool '#{tool_name}' not found or not registered for this session")
return
end
if tool_class.respond_to?(:requires_consent?) && tool_class.requires_consent? && !session.consent_granted_for?(tool_name)
error = {
code: -32_002,
message: "Consent required for tool '#{tool_name}'"
}
send_jsonrpc_response(request_id, error: error)
return
end
task_support = tool_task_support(tool_class)
task_requested = !task_params.nil?
if task_requested && !tasks_enabled?
send_jsonrpc_error(request_id, :method_not_found,
"Task-augmented execution is not available for this session")
return
end
if task_requested
unless task_params.respond_to?(:to_h)
send_jsonrpc_error(request_id, :invalid_params, "Task parameters must be an object")
return
end
task_params = task_params.to_h
if task_support == :forbidden
send_jsonrpc_error(request_id, :method_not_found,
"Tool '#{tool_name}' does not support task-augmented execution")
return
end
handle_task_augmented_tool_call(request_id, tool_name, arguments, _meta, task_params)
return
end
if !task_requested && task_support == :required
send_jsonrpc_error(request_id, :method_not_found,
"Tool '#{tool_name}' requires task-augmented execution")
return
end
execute_tool_synchronously(request_id, tool_class, tool_name, arguments, _meta)
end
|