@@ -75,6 +75,7 @@ def initialize(
7575 @resource_index = index_resources_by_uri ( resources )
7676 @server_context = server_context
7777 @configuration = MCP . configuration . merge ( configuration )
78+ @client = nil
7879
7980 validate!
8081
@@ -258,15 +259,17 @@ def validate_tool_name!
258259 def handle_request ( request , method )
259260 handler = @handlers [ method ]
260261 unless handler
261- instrument_call ( "unsupported_method" ) { }
262+ instrument_call ( "unsupported_method" ) do
263+ add_instrumentation_data ( client : @client ) if @client
264+ end
262265 return
263266 end
264267
265268 Methods . ensure_capability! ( method , capabilities )
266269
267270 -> ( params ) {
268271 instrument_call ( method ) do
269- case method
272+ result = case method
270273 when Methods ::TOOLS_LIST
271274 { tools : @handlers [ Methods ::TOOLS_LIST ] . call ( params ) }
272275 when Methods ::PROMPTS_LIST
@@ -280,6 +283,9 @@ def handle_request(request, method)
280283 else
281284 @handlers [ method ] . call ( params )
282285 end
286+ add_instrumentation_data ( client : @client ) if @client
287+
288+ result
283289 rescue => e
284290 report_exception ( e , { request : request } )
285291 if e . is_a? ( RequestHandlerError )
@@ -314,6 +320,7 @@ def server_info
314320 end
315321
316322 def init ( request )
323+ @client = request [ :clientInfo ] if request
317324 {
318325 protocolVersion : configuration . protocol_version ,
319326 capabilities : capabilities ,
0 commit comments