Module: RailsAiContext::Instrumentation

Defined in:
lib/rails_ai_context/instrumentation.rb

Overview

Bridges MCP gem instrumentation to ActiveSupport::Notifications. Enables Rails apps to subscribe to MCP events (tool calls, resource reads, etc.).

Constant Summary collapse

EVENT_PREFIX =
"rails_ai_context"

Class Method Summary collapse

Class Method Details

.callbackObject

Returns a lambda for MCP::Configuration#instrumentation_callback. Instruments each MCP method call as an ActiveSupport::Notifications event.



11
12
13
14
15
16
17
18
19
20
# File 'lib/rails_ai_context/instrumentation.rb', line 11

def self.callback
  ->(data) {
    return unless defined?(ActiveSupport::Notifications)

    method = data[:method] || "unknown"
    event_name = "#{EVENT_PREFIX}.#{method.tr("/", ".")}"

    ActiveSupport::Notifications.instrument(event_name, data)
  }
end