Module: ToolForge

Defined in:
lib/tool_forge.rb,
lib/tool_forge/version.rb,
lib/tool_forge/tool_definition.rb

Overview

ToolForge provides a unified DSL for defining tools that can be converted to both RubyLLM and Model Context Protocol (MCP) formats.

Examples:

Basic usage

tool = ToolForge.define(:greet_user) do
  description 'Greets a user by name'
  param :name, type: :string, description: 'User name'
  execute { |name:| "Hello, #{name}!" }
end

# Convert to RubyLLM format
ruby_llm_tool = tool.to_ruby_llm_tool

# Convert to MCP format
mcp_tool = tool.to_mcp_tool

Defined Under Namespace

Classes: Error, ToolDefinition

Constant Summary collapse

VERSION =

The current version of the ToolForge gem

'0.2.0'

Class Method Summary collapse

Class Method Details

.define(name) { ... } ⇒ ToolDefinition

Creates a new tool definition with the given name and configuration block.

Examples:

Define a simple tool

tool = ToolForge.define(:calculator) do
  description 'Performs basic arithmetic'
  param :operation, type: :string, description: 'Operation to perform'
  param :a, type: :number, description: 'First number'
  param :b, type: :number, description: 'Second number'

  execute do |operation:, a:, b:|
    case operation
    when 'add' then a + b
    when 'subtract' then a - b
    when 'multiply' then a * b
    when 'divide' then b != 0 ? a / b : 'Cannot divide by zero'
    else 'Unknown operation'
    end
  end
end

Parameters:

  • name (Symbol)

    the name of the tool

Yields:

  • block for configuring the tool using the DSL

Returns:



53
54
55
# File 'lib/tool_forge.rb', line 53

def self.define(name, &)
  ToolDefinition.new(name, &)
end