: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(mcp-analytics): attribute grok clients to a grok harness (#69746)
Chris Volzerca963399b6c1
diff --git a/products/mcp_analytics/backend/mcp_harness.py b/products/mcp_analytics/backend/mcp_harness.pyindex 19fbdeb159eb..1fc56bbe12a2 100644--- a/products/mcp_analytics/backend/mcp_harness.py+++ b/products/mcp_analytics/backend/mcp_harness.py@@ -7,6 +7,7 @@ query-time computation:1. Resolve a normalized token from the strongest available signal (thex-anthropic-client vendor header, then Claude Code's User-Agent surface,+ then the Grok User-Agent surface,then the clientInfo.name — `$mcp_client_name` as reported by the posthog-nodeMCP analytics SDK, or `mcp_session_client_name` as reported by PostHog's hostedMCP server — then the User-Agent product token, then the OAuth client name) —@@ -35,7 +36,7 @@ _UA_PRODUCT = "extract(toString(properties.$mcp_client_user_agent), '^([^/]+)')"# (step 2, to keep the CLI/SDK/IDE split) and as the generic fallback (step 4)._UA_TOKEN = f"trim(concat({_UA_PRODUCT}, ' ', extract(toString(properties.$mcp_client_user_agent), '[(]([^,)]+)')))"-# Step 1-5 of the resolution, mirroring HARNESS_ROWS_QUERY in the frontend.+# The ordered resolution steps, mirroring HARNESS_ROWS_QUERY in the frontend._RAW_TOKEN = f"""coalesce(multiIf(lower(toString(properties.mcp_vendor_client)) = 'claudecode', 'claude-code',@@ -45,6 +46,12 @@ _RAW_TOKEN = f"""coalesce(NULL),if(lower({_UA_PRODUCT}) = 'claude-code', {_UA_TOKEN}, NULL),+ -- grok.com Connectors self-identifies as grok only in the User-Agent+ -- (`grok-connectors-manager/…`); its clientInfo.name is the generic+ -- "connectors-manager", which would otherwise win below and drop the vendor.+ -- Promote the grok UA above it. (grok-shell keeps its `grok-`-prefixed+ -- clientInfo.name and buckets to Grok without help.)+ if(startsWith(lower({_UA_PRODUCT}), 'grok'), {_UA_TOKEN}, NULL),nullIf(nullIf(toString(properties.$mcp_client_name), ''), 'mcp'),nullIf(nullIf(toString(properties.mcp_session_client_name), ''), 'mcp'),nullIf({_UA_TOKEN}, ''),@@ -87,6 +94,7 @@ def harness_label_sql(token_col: str = "h") -> str:{token_col} = 'openai-mcp responses api', 'OpenAI Responses API',startsWith({token_col}, 'openai-mcp'), 'OpenAI',startsWith({token_col}, 'codex'), 'OpenAI Codex',+ startsWith({token_col}, 'grok'), 'Grok',startsWith({token_col}, 'cursor'), 'Cursor',startsWith({token_col}, 'visual studio code'), 'VS Code',{token_col} = 'windsurf', 'Windsurf',@@ -124,6 +132,7 @@ HARNESS_LABELS: tuple[str, ...] = ("OpenAI Responses API","OpenAI","OpenAI Codex",+ "Grok","Cursor","VS Code","Windsurf",diff --git a/products/mcp_analytics/backend/tests/test_harness_breakdown.py b/products/mcp_analytics/backend/tests/test_harness_breakdown.pyindex c6ca900c6679..18f044807314 100644--- a/products/mcp_analytics/backend/tests/test_harness_breakdown.py+++ b/products/mcp_analytics/backend/tests/test_harness_breakdown.py@@ -121,6 +121,18 @@ class TestMCPHarnessBreakdownQueryRunner(_MCPAnalyticsTeamScopedTestMixin, Click"Claude Desktop",),("ua_openai", {"$mcp_client_user_agent": "openai-mcp/1.0.0"}, "OpenAI"),+ # grok.com Connectors: the grok- UA must beat the generic "connectors-manager"+ # clientInfo.name it also reports, or the vendor is lost to 'Other'.+ (+ "grok_connectors_ua_beats_generic_name",+ {+ "$mcp_client_user_agent": "grok-connectors-manager/0.1.0",+ "$mcp_client_name": "connectors-manager",+ },+ "Grok",+ ),+ # xAI API surface: no grok UA, buckets via its grok- clientInfo.name.+ ("grok_shell_client_name", {"$mcp_client_name": "grok-shell-posthog"}, "Grok"),("session_librechat", {"mcp_session_client_name": "@librechat/api-client"}, "LibreChat"),("mcp_remote_suffix_stripped",diff --git a/products/mcp_analytics/frontend/dashboard/harnessRegistry.ts b/products/mcp_analytics/frontend/dashboard/harnessRegistry.tsindex f31b9863ff4c..53b3c823e387 100644--- a/products/mcp_analytics/frontend/dashboard/harnessRegistry.ts+++ b/products/mcp_analytics/frontend/dashboard/harnessRegistry.ts@@ -47,6 +47,7 @@ export const HARNESS_BY_LABEL: Record<string, HarnessDescriptor> = {'OpenAI Responses API': { logo: { src: openaiLogo, alt: 'OpenAI Responses API logo' }, colorIndex: 10 },OpenAI: { logo: { src: openaiLogo, alt: 'OpenAI logo' }, colorIndex: 1 },'OpenAI Codex': { logo: { src: openaiLogo, alt: 'OpenAI Codex logo' }, colorIndex: 13 },+ Grok: { colorIndex: 14 },Cursor: { logo: { src: cursorLogo, alt: 'Cursor logo' }, colorIndex: 12 },'VS Code': { logo: { src: vscodeLogo, alt: 'VS Code logo' }, colorIndex: 11 },Windsurf: { logo: { src: windsurfLogo, alt: 'Windsurf logo' } },diff --git a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.ts b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.tsindex 3d520617ad72..6c2644c55b45 100644--- a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.ts+++ b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.ts@@ -67,6 +67,7 @@ describe('mcpDashboardOverviewLogic', () => {'OpenAI Responses API','OpenAI','OpenAI Codex',+ 'Grok','Cursor','VS Code','Windsurf',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.mdindex e70615632234..8e1916af5943 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@@ -128,6 +128,7 @@ FROM (h = 'openai-mcp responses api', 'OpenAI Responses API',startsWith(h, 'openai-mcp'), 'OpenAI',startsWith(h, 'codex'), 'OpenAI Codex',+ startsWith(h, 'grok'), 'Grok',startsWith(h, 'cursor'), 'Cursor',startsWith(h, 'visual studio code'), 'VS Code',h = 'windsurf', 'Windsurf',@@ -161,6 +162,11 @@ 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),+ -- grok.com Connectors carries `grok-` only in the UA; its clientInfo.name+ -- is the generic "connectors-manager", so promote the grok UA above it.+ if(startsWith(lower(extract(toString(properties.$mcp_client_user_agent), '^([^/]+)')), 'grok'),+ 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(