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, register, size, unregister

Class Method Details

.item_klassObject



33
34
35
# File 'lib/action_mcp/tools_registry.rb', line 33

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
# 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
  # FIXME, we should maybe not return the error message to the user
  error_response(:invalid_params, message: "Tool execution failed: #{e.message}")
end