Class: Elelem::MCP::Client
- Inherits:
-
Object
- Object
- Elelem::MCP::Client
- Defined in:
- lib/elelem/mcp/client.rb
Overview
Constant Summary collapse
- CONFIG_PATHS =
[ "~/.agents/mcp.json", ".agents/mcp.json" ].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(configurations = CONFIG_PATHS) ⇒ Client
constructor
A new instance of Client.
- #tools ⇒ Object
Constructor Details
#initialize(configurations = CONFIG_PATHS) ⇒ Client
Returns a new instance of Client.
16 17 18 19 |
# File 'lib/elelem/mcp/client.rb', line 16 def initialize(configurations = CONFIG_PATHS) @config = load_config(configurations) @servers = {} end |
Class Method Details
.memoized ⇒ Object
12 13 14 |
# File 'lib/elelem/mcp/client.rb', line 12 def self.memoized @memoized ||= new.tap { |client| at_exit { client.close } } end |
Instance Method Details
#close ⇒ Object
37 38 39 |
# File 'lib/elelem/mcp/client.rb', line 37 def close @servers.each_value(&:close) end |
#tools ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/elelem/mcp/client.rb', line 21 def tools @config.fetch("mcpServers", {}).flat_map do |name, _| server(name).tools.map do |tool| [ "#{name}_#{tool["name"]}", { description: tool["description"], params: symbolize(tool.dig("inputSchema", "properties") || {}), required: tool.dig("inputSchema", "required") || [], fn: ->(a) { server(name).call(tool["name"], a) } } ] end end.to_h end |