Class: Silas::Mcp::Client
- Inherits:
-
Object
- Object
- Silas::Mcp::Client
- Defined in:
- lib/silas/mcp/client.rb
Overview
JSON-RPC 2.0 over MCP Streamable HTTP — the CLIENT half of Handler/Server, used by connections to call remote MCP servers. Stateless per operation (fresh initialize each call) so it's replay-safe. Net::HTTP only.
Constant Summary collapse
- PROTOCOL_VERSION =
"2025-06-18".freeze
Instance Method Summary collapse
-
#call_tool(name, arguments) ⇒ Object
An MCP application error comes back as a normal result with isError=true (the remote tool ran and errored) — returned so the model can react.
-
#initialize(url:, headers: {}, open_timeout: 5, read_timeout: 30) ⇒ Client
constructor
A new instance of Client.
- #list_tools ⇒ Object
Constructor Details
#initialize(url:, headers: {}, open_timeout: 5, read_timeout: 30) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 |
# File 'lib/silas/mcp/client.rb', line 13 def initialize(url:, headers: {}, open_timeout: 5, read_timeout: 30) @uri = URI(url) @headers = headers @open_timeout = open_timeout @read_timeout = read_timeout end |
Instance Method Details
#call_tool(name, arguments) ⇒ Object
An MCP application error comes back as a normal result with isError=true (the remote tool ran and errored) — returned so the model can react. Only JSON-RPC/transport failures raise.
27 28 29 |
# File 'lib/silas/mcp/client.rb', line 27 def call_tool(name, arguments) with_session { |sid| rpc("tools/call", { "name" => name, "arguments" => arguments }, session: sid) } end |
#list_tools ⇒ Object
20 21 22 |
# File 'lib/silas/mcp/client.rb', line 20 def list_tools with_session { |sid| rpc("tools/list", {}, session: sid).fetch("tools") } end |