Skip to content

feat: typed Metrics interface and auto-detected client version#6

Merged
inhuman merged 1 commit into
mainfrom
007-metrics-version
May 11, 2026
Merged

feat: typed Metrics interface and auto-detected client version#6
inhuman merged 1 commit into
mainfrom
007-metrics-version

Conversation

@inhuman
Copy link
Copy Markdown
Owner

@inhuman inhuman commented May 11, 2026

Summary

  • Metrics interfaceRecordCall(server, tool string, dur time.Duration, err error) and RecordToolList(server string, count int). Register via WithMetrics(m Metrics); passing nil is a no-op. Panics inside any method are recovered by the library. Works alongside existing AfterCallHook.
  • RecordCall is invoked after every CallTool invocation including pre-RPC failures (ErrToolNotFound, etc.). dur measures the upstream MCP call wall-clock time; near-zero for pre-RPC failures.
  • RecordToolList is invoked after every successful tool-list fetch (initial connect + live refresh).
  • Auto-detected clientInfo.version — reads the consuming module's version via runtime/debug.ReadBuildInfo(); falls back to "dev" for go run / untagged builds. WithClientIdentity continues to override.
  • Zero new external dependencies (runtime/debug is stdlib).

Test plan

  • TestMetrics_RecordCall_Success — RecordCall fires with nil err and dur > 0
  • TestMetrics_RecordCall_Error — RecordCall fires with non-nil err for ErrToolNotFound
  • TestMetrics_RecordToolList — RecordToolList fires on connect with correct count
  • TestMetrics_PanicRecovered — panic in Metrics doesn't propagate to caller
  • TestMetrics_NilNoOp — WithMetrics(nil) is safe
  • TestMetrics_WithAfterCallCoexists — both Metrics and AfterCallHook fire
  • TestVersion_DefaultIsDev — defaultClientVersion returns "dev" in test env
  • TestVersion_WithClientIdentityOverrides — explicit override takes precedence
  • CI: go test -race ./..., golangci-lint run — all green

🤖 Generated with Claude Code

@inhuman inhuman merged commit 682a09e into main May 11, 2026
3 checks passed
@inhuman inhuman deleted the 007-metrics-version branch May 11, 2026 14:33
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