Skip to content

Extend McpMetricsObserver with completion, error, and tools/list callbacks#1142

Open
psp65 wants to merge 1 commit intosmithy-lang:mainfrom
psp65:mcp-metrics-observer-extensions
Open

Extend McpMetricsObserver with completion, error, and tools/list callbacks#1142
psp65 wants to merge 1 commit intosmithy-lang:mainfrom
psp65:mcp-metrics-observer-extensions

Conversation

@psp65
Copy link
Copy Markdown

@psp65 psp65 commented Apr 6, 2026

Summary

  • Add three new default methods to McpMetricsObserver: onToolCallComplete, onToolCallError, and onToolsList
  • Instrument McpService.handleToolsCall() with System.nanoTime() latency tracking on both local and proxy code paths
  • Instrument McpService.handleToolsList() with tool count callback
  • Every onToolCall is now guaranteed a matching onToolCallComplete, including the "tool not found" error path

Motivation

The existing McpMetricsObserver only tracks tool call initiation (onToolCall) and initialization (onInitialize). There is no visibility into:

  • Whether tool calls succeed or fail
  • How long tool calls take (latency)
  • Which server handled the call
  • Whether the call was proxied or handled locally
  • How often clients request the tool list

These callbacks enable downstream consumers (e.g., CLI telemetry) to emit per-tool counters, per-server breakdowns, latency timings, and error rates.

…/list callbacks

Add three new default methods to McpMetricsObserver:
- onToolCallComplete: fires after tool execution with latency, server ID, success/failure, and proxy flag
- onToolCallError: fires on tool call errors with error message
- onToolsList: fires on tools/list requests with tool count

Instrument McpService.handleToolsCall() with System.nanoTime() latency tracking
on both local and proxy code paths, and add error tracking for failed calls
and unknown tools. Instrument handleToolsList() with tool count callback.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant