This directory contains practical examples of ToolForge usage, demonstrating various features and patterns.
Demonstrates:
- Class helper methods for utility functions (
add_to_tar,validate_container_id) - Instance helper methods for result formatting
- Parameter validation and error handling
- Complex return values with structured data
Key Features:
- Container ID validation
- Tar archive operations simulation
- File existence checking
- Comprehensive error handling
Demonstrates:
- Multiple instance helper methods for different concerns
- Array parameters for multiple operations
- Complex text processing with various transformations
- Multiple output formats (JSON, YAML, text)
- Preserve original data option
Key Features:
- Text analysis (word count, line count, etc.)
- Text transformations (case changes, reversals, etc.)
- Flexible output formatting
- Operation chaining
To run these examples:
# From the project root
ruby examples/docker_copy_tool.rb
ruby examples/file_processor_tool.rbUse these examples as templates for your own tools:
- Start with a clear purpose - what does your tool do?
- Define parameters - what inputs does it need?
- Break down complex logic into helper methods
- Choose the right helper type:
- Use
helperfor instance methods that work with tool data - Use
class_helperfor utility functions and static operations
- Use
- Handle errors gracefully - return structured error information
- Consider output format - how will users consume the results?
require 'ruby_llm'
require_relative 'docker_copy_tool'
# Convert to RubyLLM format
ruby_llm_tool = docker_copy_tool.to_ruby_llm_tool
# Use with RubyLLM framework
llm = RubyLLM::Client.new
llm.add_tool(ruby_llm_tool)require 'mcp'
require_relative 'file_processor_tool'
# Convert to MCP format
mcp_tool = file_processor_tool.to_mcp_tool
# Use with MCP server
server = MCP::Server.new
server.add_tool(mcp_tool)- Clear parameter documentation - each parameter has a description
- Sensible defaults - optional parameters have reasonable defaults
- Input validation - check inputs before processing
- Error handling - graceful failure with informative messages
- Structured outputs - consistent, parseable return values
- Helper method organization - logical separation of concerns
- Type safety - appropriate parameter types for inputs