: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
chore(mcp-analytics): point MCP skills at the typed tool-detail tools (#66513)
Paul D'Ambra93ad29a76b79
diff --git a/products/mcp_analytics/skills/exploring-mcp-tool-quality/SKILL.md b/products/mcp_analytics/skills/exploring-mcp-tool-quality/SKILL.mdindex 56bd518ade3d..bd9f789a43b9 100644--- a/products/mcp_analytics/skills/exploring-mcp-tool-quality/SKILL.md+++ b/products/mcp_analytics/skills/exploring-mcp-tool-quality/SKILL.md@@ -18,9 +18,17 @@ tool. There is **no dedicated ClickHouse table** — every field lives as apercentiles, reach) is an aggregation over this one event. This is the databehind the MCP analytics dashboard and tool-quality screens.-**HogQL via `posthog:execute-sql` is the primary path.** There are no typed-tools for tool quality — it is all SQL. The full property schema and the-canonical query recipes live in the shared MCP data reference:+**For a single tool, prefer the typed tools** — `posthog:query-mcp-tool-stats` (calls,+errors, p50/p95, users, sessions, intents), `posthog:query-mcp-tool-failures` (top error+messages by harness), and `posthog:query-mcp-tool-daily-stats` (day-by-day trend). Each+takes a `toolName` + `dateRange`, runs the same query runner as the tool-detail+UI, and is gated behind the `mcp-analytics` flag — no hand-written SQL needed.++**HogQL via `posthog:execute-sql` is the path for cross-tool questions** — the+"which tool errors most" ranking below has no typed tool, so rank with SQL, then+drill into the worst tool with `posthog:query-mcp-tool-stats` / `-failures`. The full+property schema and the canonical query recipes live in the shared MCP data+reference:[`products/posthog_ai/skills/querying-posthog-data/references/models-mcp.md`](../../../posthog_ai/skills/querying-posthog-data/references/models-mcp.md).That reference is the single source of truth for the `$mcp_*` schema and theeffective-tool-name idiom used below — this skill inlines only the headline@@ -78,9 +86,15 @@ under "Tool-quality matrix".## Workflow: why is a tool failing-Pull the most common error messages for a tool, then correlate to richer+For one tool's top error messages (grouped by harness), call+`posthog:query-mcp-tool-failures` with the `toolName` — it's the typed equivalent of the+query below. Pass the **raw** `$mcp_tool_name` (the registered tool name), not+the effective inner tool: failures match `$exception` events, which don't carry+the new-SDK effective-tool markers. Drop to SQL only to correlate to richerexception detail (`$exception` events carry `$exception_message`, joined by-`$session_id` and timestamp):+`$session_id` and timestamp) — that session join is approximate: it surfaces+every exception in the session, not only this tool's, so treat it as a lead, not+exact attribution:```sqlposthog:execute-sqldiff --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 c95175f46e71..e70615632234 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@@ -4,7 +4,21 @@ Any MCP server instrumented with the `@posthog/mcp` SDK — and PostHog's own MCQuery the canonical `$`-prefixed event name. Servers instrumented with the `@posthog/mcp` SDK emit only `$mcp_tool_call` / `$mcp_initialize`; PostHog's own hosted server additionally dual-emits legacy un-prefixed `mcp_tool_call` / `mcp_initialize` aliases through a transition shim. Match the canonical name only — an `event IN ('mcp_tool_call', '$mcp_tool_call')` would double-count PostHog's own server.-**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).+**For a single tool, prefer the typed tools.** Each takes a `toolName` plus a `dateRange`, runs the same query runner the tool-detail UI uses, and is gated behind the `mcp-analytics` flag, so results match the UI exactly and you don't re-derive the SQL below. For all of them **except `posthog:query-mcp-tool-failures`**, `toolName` is the effective name (resolved server-side — the inner tool of a single-exec wrapper call). `posthog:query-mcp-tool-failures` is the exception: it matches `$exception` events, which don't carry the new-SDK effective-tool markers, so it takes the **raw** `$mcp_tool_name` (the registered tool name):++| question about one tool | tool |+| ------------------------------------------------------------------- | -------------------------------------------------------- |+| headline numbers (calls, errors, p50/p95, users, sessions, intents) | `posthog:query-mcp-tool-stats` |+| day-by-day trend | `posthog:query-mcp-tool-daily-stats` |+| top error messages, by harness | `posthog:query-mcp-tool-failures` (raw `$mcp_tool_name`) |+| top callers (incl. person email/name) | `posthog:query-mcp-tool-top-users` |+| tools called before/after it (`neighborDirection: before`/`after`) | `posthog:query-mcp-tool-neighbors` |+| recent agent intents | `posthog:query-mcp-tool-sample-intents` |+| distinct descriptions seen | `posthog:query-mcp-tool-descriptions` |++And `posthog:query-mcp-harness-breakdown` for the cross-tool harness cut (see below).++**HogQL is the path for everything else** — cross-tool rankings (the tool-quality matrix), custom breakdowns, session listing, per-session tool calls — query them with `execute-sql`. Two more typed tools cover what 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).## Key properties@@ -31,7 +45,9 @@ coalesce(nullIf(toString(properties.$mcp_exec_tool_call_name), ''), toString(pro## Example queries-**Error rate of one tool:**+The SQL below is the fallback for cross-tool rankings and custom cuts. For a single tool's numbers, call the typed tool from the table above instead of re-deriving these.++**Error rate of one tool** (single-tool headline numbers are `posthog:query-mcp-tool-stats`; use this for a custom predicate):```sqlSELECT@@ -45,7 +61,7 @@ WHERE event = '$mcp_tool_call'AND timestamp >= now() - INTERVAL 7 DAY```-**Tool-quality matrix** (error rate + latency percentiles + reach, one row per tool):+**Tool-quality matrix** (error rate + latency percentiles + reach, one row per tool) — this cross-tool ranking has no typed tool; once you've picked a tool, drill into it with `posthog:query-mcp-tool-stats` / `-failures` / `-daily-stats`:```sqlSELECT@@ -66,7 +82,7 @@ GROUP BY toolORDER BY total_calls DESC```-**Daily activity** (success/error split for a time series):+**Daily activity** (success/error split for a time series) — for one tool's daily series prefer `posthog:query-mcp-tool-daily-stats`; this all-tools version is the custom cut:```sqlSELECT toDate(timestamp) AS day,@@ -81,7 +97,7 @@ GROUP BY day ORDER BY dayA "harness" is the friendly product label for the MCP client that made a call — "Claude Agent SDK", "OpenAI Codex", "Cursor", … It is resolved **server-side** by `MCPHarnessBreakdownQueryRunner`, the single source of truth (`products/mcp_analytics/backend/mcp_harness.py`).-**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.)+**Prefer the typed tool.** For "which harnesses use our MCP, and how reliably?", call the `posthog: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 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.)@@ -166,7 +182,7 @@ ORDER BY users DESCThe `multiIf` above is the canonical bucket list. The denominator is total distinct users, so per-harness shares can sum past 100% (one user may use several harnesses). Swap the outer aggregate for other harness cuts — `count()` for call volume, `quantile(0.95)(toFloat(properties.$mcp_duration_ms))` for latency. For `query-trends`, pass the inner `multiIf(...)` over the normalized client name as a **HogQL breakdown** to get the same buckets in a trends series.-**Tool co-occurrence** (which tool tends to run right before a given tool, within a session):+**Tool co-occurrence** (which tool tends to run right before a given tool, within a session) — prefer `posthog:query-mcp-tool-neighbors` (`neighborDirection: before`/`after`); this SQL is the recipe behind it, for custom window logic:```sqlSELECT prev_tool AS tool, count() AS co_occurrences