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):
-
RobotLab.config (global)
-
Network.new (network scope)
-
Robot.new (robot definition scope)
-
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
Constant Summary collapse
- NONE_VALUES =
[nil, [].freeze, :none].freeze
Class Method Summary collapse
-
.filter_tools(tools, allowed_names:) ⇒ Array
Filter tools based on allowed tool names.
-
.inherit_value?(value) ⇒ Boolean
Check if value represents “inherit from parent”.
-
.none_value?(value) ⇒ Boolean
Check if value represents “no items”.
-
.resolve(value, parent_value:) ⇒ Array
Resolve a configuration value against its parent.
-
.resolve_mcp(value, parent_value:) ⇒ Array
Resolve MCP servers configuration.
-
.resolve_tools(value, parent_value:) ⇒ Array<String>
Resolve tools configuration.
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.
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”
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”
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
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
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
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 |