Class: RailsAiBridge::Instrumentation::InstrumentedTool
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- RailsAiBridge::Instrumentation::InstrumentedTool
- Defined in:
- lib/rails_ai_bridge/instrumentation.rb
Overview
Wraps an MCP tool class so every call emits a rails_ai_bridge.tool.call
event. Caching, when enabled, is handled by the inner wrapper so cache
hit/miss events stay separate from the invocation event.
Instance Method Summary collapse
-
#call(server_context: nil, **arguments) ⇒ MCP::Tool::Response
:reek:TooManyStatements -- outcomes must be recorded before the notification completes.
-
#initialize(tool_class) ⇒ InstrumentedTool
constructor
A new instance of InstrumentedTool.
Constructor Details
#initialize(tool_class) ⇒ InstrumentedTool
Returns a new instance of InstrumentedTool.
32 33 34 35 36 |
# File 'lib/rails_ai_bridge/instrumentation.rb', line 32 def initialize(tool_class) super @tool_class = tool_class @server_context_param = detect_server_context_param(tool_class) end |
Instance Method Details
#call(server_context: nil, **arguments) ⇒ MCP::Tool::Response
:reek:TooManyStatements -- outcomes must be recorded before the notification completes.
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rails_ai_bridge/instrumentation.rb', line 42 def call(server_context: nil, **arguments) payload = { tool_name: @tool_class.tool_name, arguments: arguments, success: false, error_class: nil } Instrumentation.instrument('tool.call', payload) do Registry.with_request_resolver do invoke_tool(arguments, server_context).tap { |response| payload[:success] = !response.error? } end rescue StandardError => error payload[:error_class] = error.class.name raise end end |