: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
docs(mcp-analytics): canonical $mcp_tool_call event and $session_id key (#64597)
Georgis Andonisb7fb61841b6f
diff --git a/products/mcp_analytics/skills/exploring-mcp-intent-clusters/SKILL.md b/products/mcp_analytics/skills/exploring-mcp-intent-clusters/SKILL.mdindex b1391dcefc6c..42bc09d18994 100644--- a/products/mcp_analytics/skills/exploring-mcp-intent-clusters/SKILL.md+++ b/products/mcp_analytics/skills/exploring-mcp-intent-clusters/SKILL.md@@ -16,7 +16,7 @@ clusters. Each cluster carries its tool distribution, call counts, and errorrates — answering "what are people _trying_ to do, and does it work?" ratherthan "which tool was called".-Unlike tool quality and sessions (which are plain HogQL over `mcp_tool_call`),+Unlike tool quality and sessions (which are plain HogQL over `$mcp_tool_call`),clustering needs embeddings and is **not expressible in SQL**. It is served bytwo typed tools backed by a stored snapshot.@@ -74,7 +74,7 @@ background. Poll `...-retrieve` until `status` returns to `idle` (done) or- Clusters are only as good as the `$mcp_intent` coverage — if few calls carryan intent, clusters will be sparse; cross-check intent coverage with a quick- `countIf(toString(properties.$mcp_intent) != '')` over `mcp_tool_call`+ `countIf(toString(properties.$mcp_intent) != '')` over `$mcp_tool_call`- A cluster with high `error_rate_pct` plus high `routing_entropy` is thestrongest "the tools don't serve this goal well" signal — worth a closer lookat its `sample_intents` and `tool_distribution`diff --git a/products/mcp_analytics/skills/exploring-mcp-sessions/SKILL.md b/products/mcp_analytics/skills/exploring-mcp-sessions/SKILL.mdindex f72f681b5e75..fcaf04e22ad0 100644--- a/products/mcp_analytics/skills/exploring-mcp-sessions/SKILL.md+++ b/products/mcp_analytics/skills/exploring-mcp-sessions/SKILL.md@@ -10,9 +10,9 @@ description: ># Exploring MCP sessions-An MCP session is one agent run, identified by `$mcp_session_id` on the-`mcp_tool_call` event. A session is just the set of `mcp_tool_call` events that-share a `$mcp_session_id`, ordered by `timestamp`. Listing sessions and reading+An MCP session is one agent run, identified by `$session_id` on the+`$mcp_tool_call` event. A session is just the set of `$mcp_tool_call` events that+share a `$session_id`, ordered by `timestamp`. Listing sessions and readinga session's tool calls are both plain HogQL over `events`; the full propertyschema and recipes are in the shared reference:[`products/posthog_ai/skills/querying-posthog-data/references/models-mcp.md`](../../../posthog_ai/skills/querying-posthog-data/references/models-mcp.md).@@ -29,13 +29,13 @@ the typed tool `posthog:mcp-analytics-sessions-generate-intent`.## Workflow: list recent sessions-Group `mcp_tool_call` by `$mcp_session_id`, deriving start/end, duration, call+Group `$mcp_tool_call` by `$session_id`, deriving start/end, duration, callcount, error count, and the harness:```sqlposthog:execute-sqlSELECT- toString(properties.$mcp_session_id) AS session_id,+ $session_id AS session_id,min(timestamp) AS session_start,max(timestamp) AS session_end,dateDiff('second', min(timestamp), max(timestamp)) AS duration_seconds,@@ -43,8 +43,8 @@ SELECTcountIf(toBool(properties.$mcp_is_error)) AS errors,any(properties.$mcp_client_name) AS clientFROM events-WHERE event = 'mcp_tool_call'- AND toString(properties.$mcp_session_id) != ''+WHERE event = '$mcp_tool_call'+ AND $session_id != ''AND timestamp >= now() - INTERVAL 7 DAYGROUP BY session_idORDER BY session_start DESC@@ -67,8 +67,8 @@ SELECTround(toFloat(properties.$mcp_duration_ms)) AS duration_ms,toString(properties.$mcp_intent) AS intentFROM events-WHERE event = 'mcp_tool_call'- AND toString(properties.$mcp_session_id) = '<session_id>'+WHERE event = '$mcp_tool_call'+ AND $session_id = '<session_id>'ORDER BY timestamp ASC```diff --git a/products/mcp_analytics/skills/exploring-mcp-tool-quality/SKILL.md b/products/mcp_analytics/skills/exploring-mcp-tool-quality/SKILL.mdindex b1a405078bf9..56bd518ade3d 100644--- a/products/mcp_analytics/skills/exploring-mcp-tool-quality/SKILL.md+++ b/products/mcp_analytics/skills/exploring-mcp-tool-quality/SKILL.md@@ -12,7 +12,7 @@ description: ># Exploring MCP tool qualityAny MCP server instrumented with PostHog's MCP analytics SDK emits a-`mcp_tool_call` event on the shared `events` table every time an agent invokes a+`$mcp_tool_call` event on the shared `events` table every time an agent invokes atool. There is **no dedicated ClickHouse table** — every field lives as a`$mcp_*` property on `events`, and every tool-quality metric (error rate, latencypercentiles, reach) is an aggregation over this one event. This is the data@@ -56,7 +56,7 @@ SELECTcountIf(toBool(properties.$mcp_is_error)) AS errors,round(countIf(toBool(properties.$mcp_is_error)) * 100.0 / count(), 1) AS error_rate_pctFROM events-WHERE event = 'mcp_tool_call'+WHERE event = '$mcp_tool_call'AND coalesce(nullIf(toString(properties.$mcp_exec_tool_call_name), ''), toString(properties.$mcp_tool_name)) != ''AND timestamp >= now() - INTERVAL 30 DAYGROUP BY tool@@ -80,13 +80,13 @@ under "Tool-quality matrix".Pull the most common error messages for a tool, then correlate to richerexception detail (`$exception` events carry `$exception_message`, joined by-`$mcp_session_id` / `$session_id` and timestamp):+`$session_id` and timestamp):```sqlposthog:execute-sqlSELECT toString(properties.$mcp_error_message) AS error, count() AS nFROM events-WHERE event = 'mcp_tool_call'+WHERE event = '$mcp_tool_call'AND toBool(properties.$mcp_is_error)AND coalesce(nullIf(toString(properties.$mcp_exec_tool_call_name), ''), toString(properties.$mcp_tool_name)) = '<tool>'AND timestamp >= now() - INTERVAL 30 DAYdiff --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 96562bbf6b9e..f45d5577bd4d 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@@ -1,6 +1,6 @@-# MCP analytics (`mcp_tool_call` events)+# MCP analytics (`$mcp_tool_call` events)-PostHog's own MCP server emits a `mcp_tool_call` event on the shared `events` table every time an agent invokes a tool. There is **no dedicated ClickHouse table** — all fields live as `$mcp_*` properties on `events`, queried directly with `posthog:execute-sql`. This is the data behind the MCP analytics dashboard, tool-quality, and tool-detail screens; every metric on those screens is reproducible as HogQL over this event.+Any MCP server instrumented with the `@posthog/mcp` SDK — and PostHog's own MCP server — emits a `$mcp_tool_call` event on the shared `events` table every time an agent invokes a tool. There is **no dedicated ClickHouse table** — all fields live as `$mcp_*` properties on `events`, queried directly with `posthog:execute-sql`. This is the data behind the MCP analytics dashboard, tool-quality, and tool-detail screens; every metric on those screens is reproducible as HogQL over this event.**HogQL is the primary path here.** Session listing, per-session tool calls, tool-level metrics (error rate, latency, adoption), harness breakdowns, time series, and co-occurrence are all just aggregations over this event — query them with `execute-sql`. The only typed tools are for things SQL can't express: `posthog:mcp-analytics-intent-clusters-retrieve` / `...-recompute` (embedding-based intent clustering) and `posthog:mcp-analytics-sessions-generate-intent` (LLM session summary).@@ -13,7 +13,7 @@ PostHog's own MCP server emits a `mcp_tool_call` event on the shared `events` ta| `$mcp_is_error` | Whether the call failed. Always read via `toBool(properties.$mcp_is_error)`. || `$mcp_error_message` | Error text when `$mcp_is_error` is true. || `$mcp_duration_ms` | Wall-clock duration; cast with `toFloat(...)`. |-| `$mcp_session_id` | Session/conversation id — the grouping key for a single agent run. |+| `$session_id` | Session/conversation id — the grouping key for a single agent run. Use the bare `$session_id` field, not `properties.$session_id`. || `$mcp_intent` | The agent's stated intent for the call, when supplied. || `$mcp_client_name` | Raw client string (e.g. `claude-code/1.2.3`). The dashboard buckets these into harnesses in the frontend; there is no `category` column. || `$mcp_tool_category` | Tool category, when tagged. |@@ -25,7 +25,7 @@ PostHog's own MCP server emits a `mcp_tool_call` event on the shared `events` tacoalesce(nullIf(toString(properties.$mcp_exec_tool_call_name), ''), toString(properties.$mcp_tool_name))```-**Failures with detail.** `mcp_tool_call` carries `$mcp_is_error` + `$mcp_error_message`; richer stack/exception data is on `$exception` events (`$exception_message`), correlated by `$mcp_session_id` / `$session_id` and timestamp.+**Failures with detail.** `$mcp_tool_call` carries `$mcp_is_error` + `$mcp_error_message`; richer stack/exception data is on `$exception` events (`$exception_message`), correlated by `$session_id` and timestamp.## Example queries@@ -37,7 +37,7 @@ SELECTcountIf(toBool(properties.$mcp_is_error)) AS errors,round(countIf(toBool(properties.$mcp_is_error)) * 100.0 / count(), 1) AS error_rate_pctFROM events-WHERE event = 'mcp_tool_call'+WHERE event = '$mcp_tool_call'-- effective tool name: new-SDK events put the real tool in $mcp_exec_tool_call_nameAND coalesce(nullIf(toString(properties.$mcp_exec_tool_call_name), ''), toString(properties.$mcp_tool_name)) = '<tool-name>'AND timestamp >= now() - INTERVAL 7 DAY@@ -55,9 +55,9 @@ SELECTround(quantile(0.5)(toFloat(properties.$mcp_duration_ms))) AS p50_ms,round(quantile(0.95)(toFloat(properties.$mcp_duration_ms))) AS p95_ms,uniq(distinct_id) AS users,- countDistinctIf(toString(properties.$mcp_session_id), toString(properties.$mcp_session_id) != '') AS sessions+ countDistinctIf($session_id, $session_id != '') AS sessionsFROM events-WHERE event = 'mcp_tool_call'+WHERE event = '$mcp_tool_call'AND coalesce(nullIf(toString(properties.$mcp_exec_tool_call_name), ''), toString(properties.$mcp_tool_name)) != ''AND timestamp >= now() - INTERVAL 30 DAYGROUP BY tool@@ -71,7 +71,7 @@ SELECT toDate(timestamp) AS day,countIf(NOT toBool(properties.$mcp_is_error)) AS successes,countIf(toBool(properties.$mcp_is_error)) AS errorsFROM events-WHERE event = 'mcp_tool_call' AND timestamp >= now() - INTERVAL 30 DAY+WHERE event = '$mcp_tool_call' AND timestamp >= now() - INTERVAL 30 DAYGROUP BY day ORDER BY day```@@ -87,7 +87,7 @@ SELECTuniq(distinct_id) AS users,round(uniq(distinct_id) * 100.0 / (SELECT uniq(distinct_id) FROM events- WHERE event = 'mcp_tool_call' AND timestamp >= now() - INTERVAL 30 DAY+ WHERE event = '$mcp_tool_call' AND timestamp >= now() - INTERVAL 30 DAY), 1) AS pct_of_usersFROM (SELECT@@ -116,7 +116,7 @@ FROM (distinct_id,lower(trim(replaceRegexpOne(toString(properties.$mcp_client_name), '\\s*\\(via mcp-remote[^)]*\\)\\s*', ''))) AS hFROM events- WHERE event = 'mcp_tool_call' AND timestamp >= now() - INTERVAL 30 DAY+ WHERE event = '$mcp_tool_call' AND timestamp >= now() - INTERVAL 30 DAY))GROUP BY harness@@ -130,13 +130,13 @@ The `multiIf` above is the canonical bucket list. The denominator is total disti```sqlSELECT prev_tool AS tool, count() AS co_occurrencesFROM (- SELECT properties.$mcp_session_id AS conv_id,+ SELECT $session_id AS conv_id,coalesce(nullIf(toString(properties.$mcp_exec_tool_call_name), ''), toString(properties.$mcp_tool_name)) AS tool,lagInFrame(coalesce(nullIf(toString(properties.$mcp_exec_tool_call_name), ''), toString(properties.$mcp_tool_name)))- OVER (PARTITION BY properties.$mcp_session_id ORDER BY timestamp+ OVER (PARTITION BY $session_id ORDER BY timestampROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS prev_toolFROM events- WHERE event = 'mcp_tool_call' AND timestamp >= now() - INTERVAL 7 DAY+ WHERE event = '$mcp_tool_call' AND timestamp >= now() - INTERVAL 7 DAY)WHERE tool = '<tool-name>' AND prev_tool != '' AND prev_tool != toolGROUP BY prev_tool ORDER BY co_occurrences DESC LIMIT 5