ruby-sdk/lib/model_context_protocol/instrumentation.rb
Topher Bullock 7175d49108 Internal Release 0.5.0
Bump protocol version to 2025-03-26
Provide fallback value for tool_name
Make configuration per server
Add support for tool annotations
document tool annotations
2025-05-08 17:38:02 -04:00

24 lines
623 B
Ruby

# frozen_string_literal: true
module ModelContextProtocol
module Instrumentation
def instrument_call(method, &block)
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
@instrumentation_data = {}
add_instrumentation_data(method:)
result = yield block
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
add_instrumentation_data(duration: end_time - start_time)
configuration.instrumentation_callback.call(@instrumentation_data)
result
end
def add_instrumentation_data(**kwargs)
@instrumentation_data.merge!(kwargs)
end
end
end