feat(mcp): add a typed posthog telemetry wrapper for the remote server - #6355
Conversation
Introduce src/mcp/telemetry.ts, a thin typed wrapper around the PostHog Node SDK that is the single seam for recording an MCP tool call. The tracked-field allowlist from the telemetry spec (tool name, caller type, success, coarse duration -- nothing else) is enforced at the type level, so no caller outside this module constructs a raw PostHog event. Telemetry is opt-in: with no POSTHOG_API_KEY configured, recordMcpToolCall is a safe no-op that records nothing and behaves byte-identically to before this module existed, and it never throws a PostHog init/capture failure into the tool caller. Not yet wired into the dispatch path. Closes JSONbored#6235
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
|
Tip ✅ LoopOver review result - approve/merge recommendedReview updated: 2026-07-16 03:55:22 UTC
Review summary Nits — 5 non-blocking
Decision drivers
Context & advisory signals — never blocks the verdict
Linked issue satisfactionAddressed Review context
Contributor next steps
Signal definitions
🧪 Chat with LoopOverAsk LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.
Full command reference: https://gittensory.aethereal.dev/docs/loopover-commands 🧪 Experimental — new and may change. 🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed 💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6355 +/- ##
=======================================
Coverage 95.60% 95.60%
=======================================
Files 597 598 +1
Lines 47191 47202 +11
Branches 15019 15022 +3
=======================================
+ Hits 45117 45128 +11
Misses 1290 1290
Partials 784 784
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Summary
src/mcp/telemetry.ts— a thin, typed wrapper around the PostHog Node SDK, the foundation the rest of the MCP-telemetry work (Spec: usage-telemetry instrumentation strategy for MCP (PostHog) #6228) builds on. It exposes a single entry point,recordMcpToolCall(env, { tool, callerType, ok, durationMs }), and no other module ever constructs a raw PostHog event.McpToolCallEvent; the built PostHogpropertiesare exactly those four fields, asserted in the tests.POSTHOG_API_KEY(every self-hoster who doesn't opt in) it records nothing and behaves byte-identically to before this module existed. It also never throws — a PostHog init/capture failure degrades to recording nothing, so it can never surface an error into the MCP tool caller.POSTHOG_API_KEY,POSTHOG_HOST) insrc/env.d.ts, mirroring the existing opt-in-secret pattern (e.g. the Orb App credentials), and addsposthog-nodeto the root package.Scope
type(scope): short summaryConventional Commit format, for examplefix(api): restore profile access checks.CONTRIBUTING.mdand does not reintroduce GitHub Pages, VitePress,site/, orCNAME.Closes #123) — a linked open issue is required for every contributor PR.Validation
git diff --checknpm run actionlintnpm run typechecknpm run test:coveragelocally;codecov/patchrequires ≥99% coverage of the lines AND branches you changed —src/mcp/telemetry.tsis at 100% statements/branches/functions/lines (8 tests);src/env.d.tsis Codecov-ignored.npm run build:mcpnpm run test:mcp-packnpm audit --audit-level=moderate(0 vulnerabilities)If any required check was skipped, explain why:
test:workers,ui:openapi:check,ui:lint,ui:typecheck,ui:build: no UI, OpenAPI, or Worker-pool surface is touched — the change is a single unimported backend module (src/mcp/telemetry.tsis not yet referenced by any entrypoint), a Codecov-ignoredenv.d.tsdeclaration, and a dependency addition.test/unit/selfhost-*reporting*/grafanasuites fail locally withspawnSync sqlite3 ENOENT(thesqlite3CLI is absent from this sandbox); they are unrelated to this change and pass on CI where the binary is installed.Safety
UI Evidencesection. — N/A: no visible UI/frontend/docs change.Notes
disableGeoip: trueand a single constant, anonymousdistinctId— the fleet telemetry carries no per-actor identity by design (Spec: usage-telemetry instrumentation strategy for MCP (PostHog) #6228).Closes #6235