Class: Kward::MCP::Client
- Inherits:
-
Object
- Object
- Kward::MCP::Client
- Defined in:
- lib/kward/mcp/client.rb
Overview
Minimal MCP client for discovering and invoking server tools.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #call_tool(name, arguments = {}) ⇒ Object
- #close ⇒ Object
-
#initialize(name:, transport:) ⇒ Client
constructor
A new instance of Client.
- #initialize! ⇒ Object
- #list_tools ⇒ Object
Constructor Details
#initialize(name:, transport:) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 |
# File 'lib/kward/mcp/client.rb', line 13 def initialize(name:, transport:) @name = name.to_s @transport = transport @initialized = false end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/kward/mcp/client.rb', line 11 def name @name end |
Instance Method Details
#call_tool(name, arguments = {}) ⇒ Object
33 34 35 36 |
# File 'lib/kward/mcp/client.rb', line 33 def call_tool(name, arguments = {}) initialize! @transport.request("tools/call", { name: name, arguments: arguments || {} }) end |
#close ⇒ Object
38 39 40 |
# File 'lib/kward/mcp/client.rb', line 38 def close @transport.close end |
#initialize! ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/kward/mcp/client.rb', line 19 def initialize! return if @initialized @transport.request("initialize", initialize_params) @transport.notify("notifications/initialized") @initialized = true end |
#list_tools ⇒ Object
27 28 29 30 31 |
# File 'lib/kward/mcp/client.rb', line 27 def list_tools initialize! result = @transport.request("tools/list", {}) Array(result["tools"] || result[:tools]) end |