feat(mcp): emit $mcp_protocol_version on events - #795
Open
gesh wants to merge 1 commit into
Open
Conversation
The MCP protocol (spec) version was carried in the session token but never stamped on events (JS emits it). Thread it through: - constants: add $mcp_protocol_version; _posthog_events emits it on the primary event and the $exception sibling. - _capture: the event normalizer now keeps protocol_version (it was silently dropped by the fixed key list -- the reason nothing surfaced before). - instrument() adapters read the live protocol version off client_params and backfill from the token on stateless pods (via resolve_session_and_client), threading it to prepare_request / record_*. - PostHogMCP capture_* methods gain a protocol_version argument. Verified on the 2-pod stateless cluster: $mcp_protocol_version lands on $mcp_initialize and every $mcp_tool_call across both pods. Generated-By: PostHog Code Task-Id: f44ec5e0-b836-4d13-98c4-c26887dd7ec2
gesh
marked this pull request as draft
July 28, 2026 10:03
Contributor
|
Reviews (1): Last reviewed commit: "feat(mcp): emit $mcp_protocol_version on..." | Re-trigger Greptile |
gesh
marked this pull request as ready for review
July 28, 2026 10:06
Contributor
posthog-python Compliance ReportDate: 2026-07-28 10:08:51 UTC ✅ All Tests Passed!111/111 tests passed Capture_V1 Tests✅ 94/94 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
Contributor
|
Reviews (2): Last reviewed commit: "feat(mcp): emit $mcp_protocol_version on..." | Re-trigger Greptile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Emit
$mcp_protocol_version(the MCP spec version, e.g.2025-06-18) on MCP analytics events — closing a parity gap with the TypeScript SDK, which already emits it.Why it was missing
The session token already carried the protocol version (
pv), but it never reached events. Root cause:capture_event's normalizer rebuilds the event from a fixed key list that omittedprotocol_version, so it was silently dropped before reaching the property builder.Changes
_posthog_events: add$mcp_protocol_version, emitted on the primary$mcp_*event and the$exceptionsibling._capture: the event normalizer now keepsprotocol_version(the missing link).instrument()adapters: read the live protocol version offclient_params, and backfill from the replayed token on stateless pods (viaresolve_session_and_client), threading it throughprepare_request/record_*.PostHogMCP:capture_tool_call/capture_initialize/capture_tools_list/capture_missing_capabilitygain aprotocol_versionargument.Validation
141 unit tests (incl. new primary+
$exceptionemission tests), mypy + ruff clean, public-API snapshot updated. Verified on the 2-pod stateless cluster:$mcp_protocol_version=2025-06-18lands on$mcp_initializeand every$mcp_tool_callacross both pods (recovered from the token on the pod that never sawinitialize).Created with PostHog Code