Class: ActionMCP::ToolsRegistry

Inherits:
RegistryBase show all
Defined in:
lib/action_mcp/tools_registry.rb

Overview

Registry for managing tools.

Class Method Summary collapse

Methods inherited from RegistryBase

clear!, find, items, non_abstract, re_register, register, size, unregister

Class Method Details

.item_klassObject



38
39
40
# File 'lib/action_mcp/tools_registry.rb', line 38

def item_klass
  Tool
end

.tool_call(tool_name, arguments, _metadata = {}) ⇒ Hash

Calls a tool with the given name and arguments.

Parameters:

  • tool_name (String)

    The name of the tool to call.

  • arguments (Hash)

    The arguments to pass to the tool.

  • _metadata (Hash) (defaults to: {})

    Optional metadata.

Returns:

  • (Hash)

    A hash containing the tool’s response.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/action_mcp/tools_registry.rb', line 18

def tool_call(tool_name, arguments,  = {})
  tool_class = find(tool_name)
  tool = tool_class.new(arguments)

  tool.call
rescue RegistryBase::NotFound
  error_response(:invalid_params, message: "Tool not found: #{tool_name}")
rescue ArgumentError => e
  # Handle parameter validation errors
  error_response(:invalid_params, message: e.message)
rescue StandardError => e
  # Hide error details in production to prevent information disclosure
  message = if Rails.env.production?
    "Tool execution failed"
  else
    "Tool execution failed: #{e.message}"
  end
  error_response(:invalid_params, message: message)
end