Class: RailsAiBridge::ToolResultCache::CachedTool

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/rails_ai_bridge/tool_result_cache.rb

Overview

Wraps a tool class so that calls are routed through the cache.

Instance Method Summary collapse

Constructor Details

#initialize(tool_class) ⇒ CachedTool

Returns a new instance of CachedTool.



21
22
23
24
25
# File 'lib/rails_ai_bridge/tool_result_cache.rb', line 21

def initialize(tool_class)
  super
  @tool_class = tool_class
  @server_context_param = detect_server_context_param(tool_class.method(:call))
end

Instance Method Details

#call(server_context: nil, **arguments) ⇒ MCP::Tool::Response

Parameters:

  • server_context (Object, nil) (defaults to: nil)

    passed by the MCP transport (ignored for cache keys)

  • arguments (Hash)

    tool arguments from the client

Returns:

  • (MCP::Tool::Response)


30
31
32
33
34
# File 'lib/rails_ai_bridge/tool_result_cache.rb', line 30

def call(server_context: nil, **arguments)
  ToolResultCache.fetch_response(@tool_class.tool_name, arguments) do
    invoke_tool(arguments, server_context)
  end
end