Module: Legion::MCP::Client::Pool
- Extended by:
- Logging::Helper
- Defined in:
- lib/legion/mcp/client/pool.rb
Class Method Summary collapse
Class Method Details
.all_tools ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/legion/mcp/client/pool.rb', line 26 def all_tools ServerRegistry.healthy_servers.flat_map do |name, _config| conn = connection_for(name) next [] unless conn conn.tools.map do |tool| tool.merge(source: { type: :mcp, server: name }) end rescue StandardError => e handle_exception(e, level: :warn, operation: 'legion.mcp.client.pool.all_tools') log.warn("MCP tool discovery failed for #{name}: #{e.}") ServerRegistry.mark_unhealthy(name) [] end end |
.connection_for(server_name) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/legion/mcp/client/pool.rb', line 14 def connection_for(server_name) @mutex.synchronize do return @connections[server_name] if @connections.key?(server_name) config = ServerRegistry.servers[server_name] return nil unless config conn = Connection.new(name: server_name, **config.except(:registered_at, :source)) @connections[server_name] = conn end end |
.reset! ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/legion/mcp/client/pool.rb', line 42 def reset! @mutex.synchronize do @connections.each_value do |connection| connection.disconnect rescue StandardError => e handle_exception(e, level: :debug, operation: 'legion.mcp.client.pool.reset!') end @connections.clear end end |