Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(mcp-analytics): classify SDK-reported $mcp_client_name harness (#66084)

Paul D'Ambrad25bee13d4ff
diff --git a/products/mcp_analytics/backend/mcp_harness.py b/products/mcp_analytics/backend/mcp_harness.py
index a0ea050f2dda..5ef2a791dc91 100644
--- a/products/mcp_analytics/backend/mcp_harness.py
+++ b/products/mcp_analytics/backend/mcp_harness.py
@@ -7,8 +7,10 @@ query-time computation:
1. Resolve a normalized token from the strongest available signal (the
x-anthropic-client vendor header, then Claude Code's User-Agent surface,
- then the session-pinned clientInfo.name, then the User-Agent product token,
- then the OAuth client name) — `HARNESS_TOKEN_SQL`.
+ then the clientInfo.name — `$mcp_client_name` as reported by the posthog-node
+ MCP analytics SDK, or `mcp_session_client_name` as reported by PostHog's hosted
+ MCP server — then the User-Agent product token, then the OAuth client name) —
+ `HARNESS_TOKEN_SQL`.
2. Bucket that token into a customer label — `harness_label_sql`.
This module is being established as the single source of truth. Today the same
@@ -45,6 +47,7 @@ _RAW_TOKEN = f"""coalesce(
NULL
),
if(lower({_UA_PRODUCT}) = 'claude-code', {_UA_TOKEN}, NULL),
+ nullIf(nullIf(toString(properties.$mcp_client_name), ''), 'mcp'),
nullIf(nullIf(toString(properties.mcp_session_client_name), ''), 'mcp'),
nullIf({_UA_TOKEN}, ''),
nullIf(toString(properties.$mcp_oauth_client_name), ''),
diff --git a/products/mcp_analytics/backend/tests/test_harness_breakdown.py b/products/mcp_analytics/backend/tests/test_harness_breakdown.py
index 613d2807c604..59ee4cfe9929 100644
--- a/products/mcp_analytics/backend/tests/test_harness_breakdown.py
+++ b/products/mcp_analytics/backend/tests/test_harness_breakdown.py
@@ -66,6 +66,14 @@ class TestMCPHarnessBreakdownQueryRunner(_MCPAnalyticsTeamScopedTestMixin, Click
("vendor_claudecode", {"mcp_vendor_client": "ClaudeCode"}, "Claude Code"),
("session_codex", {"mcp_session_client_name": "codex-mcp-client"}, "OpenAI Codex"),
("session_cursor", {"mcp_session_client_name": "cursor-vscode"}, "Cursor"),
+ # The posthog-node MCP analytics SDK reports clientInfo.name as $mcp_client_name,
+ # not the hosted server's mcp_session_client_name. Both must classify.
+ ("sdk_client_name_claudeai", {"$mcp_client_name": "claude-ai"}, "Claude.ai"),
+ (
+ "sdk_client_name_mcp_remote_stripped",
+ {"$mcp_client_name": "claude-ai (via mcp-remote 0.1.37)"},
+ "Claude.ai",
+ ),
("ua_claude_cli", {"$mcp_client_user_agent": "claude-code/2.1.0 (cli)"}, "Claude Code"),
(
"ua_claude_sdk",
diff --git a/products/posthog_ai/skills/querying-posthog-data/references/models-mcp.md b/products/posthog_ai/skills/querying-posthog-data/references/models-mcp.md
index 1535b594512a..c95175f46e71 100644
--- a/products/posthog_ai/skills/querying-posthog-data/references/models-mcp.md
+++ b/products/posthog_ai/skills/querying-posthog-data/references/models-mcp.md
@@ -83,7 +83,7 @@ A "harness" is the friendly product label for the MCP client that made a call
**Prefer the typed tool.** For "which harnesses use our MCP, and how reliably?", call the `query-mcp-harness-breakdown` tool (gated behind the `mcp-analytics` flag). It returns calls / errors / error-rate / sessions per harness and accepts the same `dateRange` / `properties` / `filterTestAccounts` filters as the dashboard, so results match the UI exactly — no hand-written bucketing needed. (The session/feedback REST tools — `mcp-analytics-sessions-list` etc. — are disabled, so anything the typed tool doesn't express drops to `execute-sql` below.)
-**Use `execute-sql` for custom cuts** the typed tool doesn't cover (share-of-users, latency percentiles, per-tool, a trends breakdown). Resolution is two steps: resolve a normalized token from the strongest signal available, then bucket it. An event carries only raw signals — the `x-anthropic-client` header (`mcp_vendor_client`) is the only thing separating Anthropic's pooled surfaces (Cowork / Claude.ai / Claude Design); Claude Code's build (cli / sdk / vscode / desktop) rides in the User-Agent; the session-pinned `mcp_session_client_name` covers everyone else; `$mcp_client_user_agent` and `$mcp_oauth_client_name` are last fallbacks. (`$mcp_client_name` is stamped only on `$mcp_initialize`, never `$mcp_tool_call`, so it is **not** used here.) The SQL below mirrors `harness_label_sql` / `HARNESS_TOKEN_SQL` in `mcp_harness.py`; keep them in step until a materialized `$mcp_harness` property exists. (HogQL has no `WITH <expr> AS alias`, so the normalized name `h` is computed in a subquery, not a CTE.)
+**Use `execute-sql` for custom cuts** the typed tool doesn't cover (share-of-users, latency percentiles, per-tool, a trends breakdown). Resolution is two steps: resolve a normalized token from the strongest signal available, then bucket it. An event carries only raw signals — the `x-anthropic-client` header (`mcp_vendor_client`) is the only thing separating Anthropic's pooled surfaces (Cowork / Claude.ai / Claude Design); Claude Code's build (cli / sdk / vscode / desktop) rides in the User-Agent; the posthog-node MCP analytics SDK reports its `clientInfo.name` as `$mcp_client_name`, and the hosted server's session-pinned `mcp_session_client_name` covers everyone else; `$mcp_client_user_agent` and `$mcp_oauth_client_name` are last fallbacks. The SQL below mirrors `harness_label_sql` / `HARNESS_TOKEN_SQL` in `mcp_harness.py`; keep them in step until a materialized `$mcp_harness` property exists. (HogQL has no `WITH <expr> AS alias`, so the normalized name `h` is computed in a subquery, not a CTE.)
**Share of users by harness** (answers "what % of my users are on Claude Code"):
@@ -145,6 +145,7 @@ FROM (
if(lower(extract(toString(properties.$mcp_client_user_agent), '^([^/]+)')) = 'claude-code',
trim(concat(extract(toString(properties.$mcp_client_user_agent), '^([^/]+)'), ' ', extract(toString(properties.$mcp_client_user_agent), '[(]([^,)]+)'))),
NULL),
+ nullIf(nullIf(toString(properties.$mcp_client_name), ''), 'mcp'),
nullIf(nullIf(toString(properties.mcp_session_client_name), ''), 'mcp'),
nullIf(trim(concat(
extract(toString(properties.$mcp_client_user_agent), '^([^/]+)'),