Class: LLM::Tool::DirTree

Inherits:
LLM::Tool show all
Defined in:
lib/llm/tools/dir_tree.rb

Overview

The DirTree class implements a tool that returns the contents of a directory and its children.

Instance Method Summary collapse

Methods inherited from LLM::Tool

NotFound, a2a, a2a?, #a2a?, abstract!, abstract?, clear_registry!, description, find_by_name!, #function, function, inherited, mcp, #mcp?, mcp?, name, #on_cancel, #on_interrupt, params, register, registry, set, subclasses, unregister

Methods included from Param

#defaults, #param, #required

Methods included from Function::Registry

#clear_registry!, #find_by_name, #lock, #register, #registry, #registry_key, #tool_name, #unregister

Instance Method Details

#call(path:, depth: 5) ⇒ Hash

Parameters:

  • path (String) —

    The directory to walk

  • depth (Integer) (defaults to: 5) —

    How many levels to descend

Returns:

  • (Hash)

Raises:

  • (RuntimeError) —

    When the path does not exist



24
25
26
27
# File 'lib/llm/tools/dir_tree.rb', line 24

def call(path:, depth: 5)
  raise "path does not exist: #{path}" unless Dir.exist?(path)
  {ok: true, tree: walk(path:, depth:)}
end