Class: Mcp::ClientManager
- Inherits:
-
Object
- Object
- Mcp::ClientManager
- Defined in:
- lib/mcp/client_manager.rb
Overview
Manages MCP client connections and registers their tools with Tools::Registry. Each configured server (HTTP or stdio) gets a dedicated MCP::Client instance. Tool lists are fetched once during registration and cached in the registry — subsequent LLM turns reuse the same tool set without re-querying servers.
Connection failures are logged and skipped — a misconfigured or unavailable server does not prevent other servers or built-in tools from working.
Instance Method Summary collapse
-
#initialize(config: Config.new(logger: Rails.logger)) ⇒ ClientManager
constructor
A new instance of ClientManager.
-
#register_tools(registry) ⇒ Array<String>
Connects to all configured MCP servers and registers their tools in the given registry.
Constructor Details
#initialize(config: Config.new(logger: Rails.logger)) ⇒ ClientManager
Returns a new instance of ClientManager.
21 22 23 |
# File 'lib/mcp/client_manager.rb', line 21 def initialize(config: Config.new(logger: Rails.logger)) @config = config end |
Instance Method Details
#register_tools(registry) ⇒ Array<String>
Connects to all configured MCP servers and registers their tools in the given registry. Returns warnings for servers that failed to load so the caller can surface them to the user.
31 32 33 34 35 36 |
# File 'lib/mcp/client_manager.rb', line 31 def register_tools(registry) warnings = [] register_transport_tools(@config.http_servers, registry, warnings) { |server| build_http_client(server) } register_transport_tools(@config.stdio_servers, registry, warnings) { |server| build_stdio_client(server) } @config.warnings + warnings end |