Class: Insika::McpLiveTool
- Inherits:
-
RubyLLM::Tool
- Object
- RubyLLM::Tool
- Insika::McpLiveTool
- Defined in:
- lib/insika/mcp_live_tool.rb
Overview
One live MCP tool. name/description/params_schema
come from the CACHED descriptor (McpStore#tools_cache — no I/O to build
this instance, same cost as any other tool the registry hands out).
#execute is the only thing that touches the network, calling through
client_for (Insika::McpToolRegistry's memoized, started client — this
class never builds or starts one itself) into the gem's own
RubyLLM::MCP::Tool#execute, which already unwraps content[].text and
turns isError into {error:}.
Like every tool in this codebase, #execute NEVER raises: a connection
or protocol failure becomes {error:}, the model's normal failure path
(see Tools::DataDefinedTool's own rule).
Instance Method Summary collapse
- #description ⇒ Object
- #execute(**params) ⇒ Object
-
#initialize(instance_name:, tool:, client_for:) ⇒ McpLiveTool
constructor
A new instance of McpLiveTool.
- #name ⇒ Object
- #params_schema ⇒ Object
Constructor Details
#initialize(instance_name:, tool:, client_for:) ⇒ McpLiveTool
Returns a new instance of McpLiveTool.
19 20 21 22 23 24 |
# File 'lib/insika/mcp_live_tool.rb', line 19 def initialize(instance_name:, tool:, client_for:) @instance_name = instance_name @tool = tool @client_for = client_for super() end |
Instance Method Details
#description ⇒ Object
27 |
# File 'lib/insika/mcp_live_tool.rb', line 27 def description = @tool["description"].to_s |
#execute(**params) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/insika/mcp_live_tool.rb', line 34 def execute(**params) live = @client_for.call.tool(@tool["name"]) raise Insika::NotFoundError, "tool '#{@tool["name"]}' no longer offered" if live.nil? live.execute(**params) rescue StandardError => e { error: "MCP instance '#{@instance_name}' tool '#{@tool["name"]}' failed: #{e.}" } end |
#name ⇒ Object
26 |
# File 'lib/insika/mcp_live_tool.rb', line 26 def name = @tool["name"] |
#params_schema ⇒ Object
29 30 31 32 |
# File 'lib/insika/mcp_live_tool.rb', line 29 def params_schema schema = @tool["inputSchema"] schema.nil? || schema.empty? ? { "type" => "object", "properties" => {} } : schema end |