Class: Rasti::AI::MCP::Client
- Inherits:
-
Object
- Object
- Rasti::AI::MCP::Client
- Defined in:
- lib/rasti/ai/mcp/client.rb
Instance Method Summary collapse
- #call_tool(name, arguments = {}) ⇒ Object
-
#initialize(url:, allowed_tools: nil, logger: nil) ⇒ Client
constructor
A new instance of Client.
- #list_tools ⇒ Object
Constructor Details
#initialize(url:, allowed_tools: nil, logger: nil) ⇒ Client
Returns a new instance of Client.
6 7 8 9 10 11 |
# File 'lib/rasti/ai/mcp/client.rb', line 6 def initialize(url:, allowed_tools:nil, logger:nil) @url = url @allowed_tools = allowed_tools @logger = logger || Rasti::AI.logger @session_id = nil end |
Instance Method Details
#call_tool(name, arguments = {}) ⇒ Object
23 24 25 26 27 |
# File 'lib/rasti/ai/mcp/client.rb', line 23 def call_tool(name, arguments={}) raise "Invalid tool: #{name}" if allowed_tools && !allowed_tools.include?(name) result = request_with_session 'tools/call', name: name, arguments: arguments JSON.dump result['content'][0] end |
#list_tools ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/rasti/ai/mcp/client.rb', line 13 def list_tools result = request_with_session 'tools/list' tools = result['tools'] if allowed_tools tools.select { |tool| allowed_tools.include? tool['name'] } else tools end end |