Class: SwarmCLI::McpToolsOptions

Inherits:
Object
  • Object
show all
Includes:
TTY::Option
Defined in:
lib/swarm_cli/mcp_tools_options.rb

Overview

Options for the swarm mcp tools command

Instance Method Summary collapse

Instance Method Details

#tool_namesObject

Convenience accessor



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/swarm_cli/mcp_tools_options.rb', line 47

def tool_names
  names = params[:tool_names]
  return [] if names.nil? || names.empty?

  # TTY::Option might return a string or array
  names_array = names.is_a?(Array) ? names : [names]

  # Support comma-separated tool names in addition to space-separated
  # e.g., both "swarm mcp tools Read Write" and "swarm mcp tools Read,Write" work
  names_array.flat_map { |name| name.to_s.split(",") }.map(&:strip).reject(&:empty?)
end

#validate!Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/swarm_cli/mcp_tools_options.rb', line 29

def validate!
  errors = []

  # Validate tool names if provided
  if tool_names&.any?
    invalid_tools = SwarmSDK::Tools::Registry.validate(tool_names)
    if invalid_tools.any?
      available = SwarmSDK::Tools::Registry.available_names.join(", ")
      errors << "Invalid tool names: #{invalid_tools.join(", ")}. Available: #{available}"
    end
  end

  unless errors.empty?
    raise SwarmCLI::ExecutionError, errors.join("\n")
  end
end