Class: SwarmCLI::Commands::McpServe
- Inherits:
-
Object
- Object
- SwarmCLI::Commands::McpServe
- Defined in:
- lib/swarm_cli/commands/mcp_serve.rb
Overview
McpServe command starts an MCP server that exposes the swarm's lead agent as a tool.
Usage:
swarm mcp serve config.yml
The server uses stdio transport and exposes a "swarm" tool that executes tasks through the configured lead agent.
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(options) ⇒ McpServe
constructor
A new instance of McpServe.
Constructor Details
#initialize(options) ⇒ McpServe
Returns a new instance of McpServe.
15 16 17 |
# File 'lib/swarm_cli/commands/mcp_serve.rb', line 15 def initialize() @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/swarm_cli/commands/mcp_serve.rb', line 13 def @options end |
Instance Method Details
#execute ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/swarm_cli/commands/mcp_serve.rb', line 19 def execute # Validate options .validate! # Load swarm configuration to validate it config_path = .config_file unless File.exist?(config_path) $stderr.puts "Error: Configuration file not found: #{config_path}" exit(1) end # Validate the swarm configuration begin SwarmSDK.load_file(config_path) rescue SwarmSDK::ConfigurationError => e $stderr.puts "Error: Invalid swarm configuration: #{e.}" exit(1) end # MCP servers should be quiet - stdout is reserved for MCP protocol # Errors will still be logged to stderr # Start the MCP server start_mcp_server(config_path) rescue Interrupt # User cancelled (Ctrl+C) - silent exit exit(130) rescue StandardError => e # Unexpected errors - always log to stderr $stderr.puts "Fatal error: #{e.}" $stderr.puts e.backtrace.first(5).join("\n") if ENV["DEBUG"] exit(1) end |