Class: Whoosh::MCP::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(stdin:, stdout:) ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
16
17
# File 'lib/whoosh/mcp/client.rb', line 11

def initialize(stdin:, stdout:)
  @stdin = stdin
  @stdout = stdout
  @id_counter = 0
  @mutex = Mutex.new
  @closed = false
end

Instance Method Details

#call(method, **params) ⇒ Object



19
20
21
22
# File 'lib/whoosh/mcp/client.rb', line 19

def call(method, **params)
  result = send_request("tools/call", { name: method, arguments: params.transform_keys(&:to_s) })
  symbolize_result(result)
end

#closeObject



31
32
33
34
35
36
# File 'lib/whoosh/mcp/client.rb', line 31

def close
  @closed = true
  @stdin.close unless @stdin.closed?
  @stdout.close unless @stdout.closed?
rescue IOError
end

#closed?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/whoosh/mcp/client.rb', line 38

def closed?
  @closed
end

#pingObject



24
25
26
27
28
29
# File 'lib/whoosh/mcp/client.rb', line 24

def ping
  send_request("ping")
  true
rescue
  false
end