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
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/legion/mcp/client/pool.rb', line 33 def all_tools healthy = ServerRegistry.healthy_servers log.debug("[mcp][pool] action=all_tools healthy_servers=#{healthy.size}") healthy.flat_map do |name, _config| conn = connection_for(name) next [] unless conn conn.tools.map do |tool| tool_entry = { name: tool[:name], description: tool[:description], input_schema: tool[:input_schema], tool_class: nil, dispatch_type: :mcp_remote, extension: "mcp:#{name}", source: :mcp_remote, mcp_server: name } # Register into the central registry so LLM pipeline sees these too if Legion::Settings::Extensions.respond_to?(:register_tool) Legion::Settings::Extensions.register_tool(tool[:name], tool_entry) end tool_entry end rescue StandardError => e handle_exception(e, level: :warn, operation: 'legion.mcp.client.pool.all_tools') ServerRegistry.mark_unhealthy(name) [] end end |
.connection_for(server_name) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/legion/mcp/client/pool.rb', line 14 def connection_for(server_name) @mutex.synchronize do if @connections.key?(server_name) log.debug("[mcp][pool] action=connection_for server=#{server_name} cached=true") return @connections[server_name] end config = ServerRegistry.servers[server_name] unless config log.debug("[mcp][pool] action=connection_for server=#{server_name} found=false") return nil end log.debug("[mcp][pool] action=connection_for server=#{server_name} creating=true") conn = Connection.new(name: server_name, **config.except(:registered_at, :source)) @connections[server_name] = conn end end |
.refresh_tools! ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/legion/mcp/client/pool.rb', line 64 def refresh_tools! log.debug("[mcp][pool] action=refresh_tools connections=#{@connections.size}") @mutex.synchronize do @connections.each_value do |conn| conn.tools(force_refresh: true) rescue StandardError => e handle_exception(e, level: :debug, operation: 'legion.mcp.client.pool.refresh_tools!') end end all_tools end |
.reset! ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/legion/mcp/client/pool.rb', line 76 def reset! log.debug("[mcp][pool] action=reset connections=#{@connections.size}") @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 |