Class: Rasti::AI::MCP::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rasti/ai/mcp/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(url:, allowed_tools: nil, logger: nil) ⇒ Client

Returns a new instance of Client.



6
7
8
9
10
# 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
end

Instance Method Details

#call_tool(name, arguments = {}) ⇒ Object



22
23
24
25
26
# File 'lib/rasti/ai/mcp/client.rb', line 22

def call_tool(name, arguments={})
  raise "Invalid tool: #{name}" if allowed_tools && !allowed_tools.include?(name)
  result = request_mcp 'tools/call', name: name, arguments: arguments
  JSON.dump result['content'][0]
end

#list_toolsObject



12
13
14
15
16
17
18
19
20
# File 'lib/rasti/ai/mcp/client.rb', line 12

def list_tools
  result = request_mcp 'tools/list'
  tools = result['tools']
  if allowed_tools
    tools.select { |tool| allowed_tools.include? tool['name'] }
  else
    tools
  end
end