Class: Legion::MCP::Tools::RoutingStats

Inherits:
MCP::Tool
  • Object
show all
Extended by:
Logging::Helper
Defined in:
lib/legion/mcp/tools/routing_stats.rb

Class Method Summary collapse

Class Method Details

.call(worker_id: nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/legion/mcp/tools/routing_stats.rb', line 19

def call(worker_id: nil)
  log.info('Starting legion.mcp.tools.routing_stats.call')
  return error_response('legion-data is not connected') unless data_connected?
  return error_response('lex-metering is not loaded') unless metering_available?

  runner = Object.new.extend(Legion::Extensions::Metering::Runners::Metering)
  stats = runner.routing_stats(worker_id: worker_id)
  text_response(stats)
rescue StandardError => e
  handle_exception(e, level: :warn, operation: 'legion.mcp.tools.routing_stats.call')
  log.warn("RoutingStats#call failed: #{e.message}")
  error_response("Failed to fetch routing stats: #{e.message}")
end