Module: RobotLab::ToolConfig

Defined in:
lib/robot_lab/tool_config.rb

Overview

Handles hierarchical MCP and tools configuration resolution

Configuration hierarchy (each level overrides the previous):

  1. RobotLab.config (global)

  2. Network.new (network scope)

  3. Robot.new (robot definition scope)

  4. robot.run (runtime scope)

Value semantics:

  • :inherit -> Use parent level’s configuration

  • nil -> No items allowed

  • -> No items allowed

  • :none -> No items allowed

  • item1, …

    -> Only these specific items allowed

Examples:

ToolConfig.resolve(:inherit, parent_value: %w[tool1 tool2])
# => ["tool1", "tool2"]

ToolConfig.resolve(nil, parent_value: %w[tool1 tool2])
# => []

ToolConfig.resolve(%w[tool3], parent_value: %w[tool1 tool2])
# => ["tool3"]

Constant Summary collapse

NONE_VALUES =
[nil, [].freeze, :none].freeze

Class Method Summary collapse

Class Method Details

.filter_tools(tools, allowed_names:) ⇒ Array

Filter tools based on allowed tool names

Given a list of tool objects and a whitelist of tool names, returns only the tools whose names are in the whitelist.

Parameters:

  • tools (Array)

    Tool objects (must respond to :name)

  • allowed_names (Array<String>)

    Whitelist of tool names

Returns:

  • (Array)

    Filtered tools



94
95
96
97
98
99
# File 'lib/robot_lab/tool_config.rb', line 94

def filter_tools(tools, allowed_names:)
  return [] if allowed_names.empty?

  allowed_set = allowed_names.map(&:to_s).to_set
  tools.select { |tool| allowed_set.include?(tool_name(tool)) }
end

.inherit_value?(value) ⇒ Boolean

Check if value represents “inherit from parent”

Parameters:

  • value (Object)

    Value to check

Returns:

  • (Boolean)


81
82
83
# File 'lib/robot_lab/tool_config.rb', line 81

def inherit_value?(value)
  value == :inherit
end

.none_value?(value) ⇒ Boolean

Check if value represents “no items”

Parameters:

  • value (Object)

    Value to check

Returns:

  • (Boolean)


72
73
74
# File 'lib/robot_lab/tool_config.rb', line 72

def none_value?(value)
  NONE_VALUES.include?(value)
end

.resolve(value, parent_value:) ⇒ Array

Resolve a configuration value against its parent

Parameters:

  • value (Symbol, Array, nil)

    The current level’s value

  • parent_value (Array)

    The parent level’s resolved value

Returns:

  • (Array)

    The resolved configuration



39
40
41
42
43
44
# File 'lib/robot_lab/tool_config.rb', line 39

def resolve(value, parent_value:)
  return Array(parent_value) if value == :inherit
  return [] if none_value?(value)

  Array(value)
end

.resolve_mcp(value, parent_value:) ⇒ Array

Resolve MCP servers configuration

Parameters:

  • value (Symbol, Array, nil)

    MCP configuration

  • parent_value (Array)

    Parent’s MCP servers

Returns:

  • (Array)

    Resolved MCP server configurations



52
53
54
# File 'lib/robot_lab/tool_config.rb', line 52

def resolve_mcp(value, parent_value:)
  resolve(value, parent_value: parent_value)
end

.resolve_tools(value, parent_value:) ⇒ Array<String>

Resolve tools configuration

Parameters:

  • value (Symbol, Array, nil)

    Tools configuration (tool names as strings)

  • parent_value (Array)

    Parent’s tools

Returns:

  • (Array<String>)

    Resolved tool names



62
63
64
65
# File 'lib/robot_lab/tool_config.rb', line 62

def resolve_tools(value, parent_value:)
  resolved = resolve(value, parent_value: parent_value)
  resolved.map(&:to_s)
end