> AI agents: this is one page from PostHog's docs. Full index of Markdown docs for LLMs: https://posthog.com/llms.txt # Sample queries Canonical URL: https://posthog.com/docs/mcp-analytics/queries ## On this page - [Top tools per server](#top-tools-per-server) - [Error rate per tool](#error-rate-per-tool) - [P95 latency per tool](#p95-latency-per-tool) - [Intent samples split by source](#intent-samples-split-by-source) - [Active sessions per client](#active-sessions-per-client) - [Advertised tools that never get called](#advertised-tools-that-never-get-called) - [Unmet user requests (requires reportMissing: true)](#unmet-user-requests-requires-reportmissing-true) - [Tool call volume by client and tool, daily](#tool-call-volume-by-client-and-tool-daily) Use these HogQL queries after you install the SDK and capture `$mcp_tool_call` events. See the [event reference](https://posthog.com/docs/mcp-analytics/events.md) for property definitions. For a live example, the [MCP leaderboard](https://posthog.com/mcp/leaderboard.md) runs queries like these over PostHog's own MCP server – shares by client and model, plus error rate and p95 latency per tool – and serves the results through [Endpoints](https://posthog.com/docs/endpoints.md). ![PostHog SQL editor running the top tools per server query against $mcp_tool_call events, with results grouped by server and tool](https://res.cloudinary.com/dmukukwp6/image/upload/q_auto,f_auto/mcp_sql_editor_light_94f83dc27e.png) ## Top tools per server ```sql SELECT properties.$mcp_server_name AS server, properties.$mcp_tool_name AS tool, count() AS calls FROM events WHERE event = '$mcp_tool_call' AND timestamp > now() - INTERVAL 7 DAY GROUP BY server, tool ORDER BY calls DESC LIMIT 50 ``` ## Error rate per tool ```sql SELECT properties.$mcp_tool_name AS tool, countIf(properties.$mcp_is_error) AS errors, count() AS total, countIf(properties.$mcp_is_error) / count() AS error_rate FROM events WHERE event = '$mcp_tool_call' AND timestamp > now() - INTERVAL 7 DAY GROUP BY tool ORDER BY total DESC ``` ## P95 latency per tool ```sql SELECT properties.$mcp_tool_name AS tool, quantile(0.95)(toFloat(properties.$mcp_duration_ms)) AS p95_ms FROM events WHERE event = '$mcp_tool_call' AND timestamp > now() - INTERVAL 7 DAY GROUP BY tool ORDER BY p95_ms DESC ``` ## Intent samples split by source How much of your traffic is supplying explicit context vs falling back to your `intentFallback` callback? ```sql SELECT properties.$mcp_intent_source AS source, properties.$mcp_tool_name AS tool, any(properties.$mcp_intent) AS sample_intent, count() AS calls FROM events WHERE event = '$mcp_tool_call' AND timestamp > now() - INTERVAL 24 HOUR GROUP BY source, tool ORDER BY calls DESC ``` ## Active sessions per client [Conversation IDs](https://posthog.com/docs/mcp-analytics/conversation-id.md) are on by default, but clients must echo the handle to group calls across requests. Clients that ignore it can inflate the session count. The Go SDK sends no `$mcp_initialize`, so only its tool calls count. ```sql SELECT properties.$mcp_client_name AS client, uniq(properties.$session_id) AS sessions FROM events WHERE event IN ('$mcp_initialize', '$mcp_tool_call') AND timestamp > now() - INTERVAL 7 DAY GROUP BY client ORDER BY sessions DESC ``` ## Advertised tools that never get called This query finds tools in `tools/list` responses that agents never called. The Go SDK sends no `$mcp_tools_list`, so this query returns nothing for Go servers. ```sql WITH listed AS ( SELECT DISTINCT arrayJoin(properties.$mcp_listed_tool_names) AS tool_name FROM events WHERE event = '$mcp_tools_list' AND timestamp > now() - INTERVAL 30 DAY ), called AS ( SELECT DISTINCT properties.$mcp_tool_name AS tool_name FROM events WHERE event = '$mcp_tool_call' AND timestamp > now() - INTERVAL 30 DAY ) SELECT tool_name AS zombie_tool FROM listed WHERE tool_name NOT IN (SELECT tool_name FROM called) ORDER BY tool_name ``` ## Unmet user requests (requires `reportMissing: true`) What were users trying to do that your tools couldn't satisfy? ```sql SELECT properties.$mcp_intent AS unmet_request, properties.$mcp_client_name AS client, count() AS times_asked FROM events WHERE event = '$mcp_missing_capability' AND timestamp > now() - INTERVAL 30 DAY GROUP BY unmet_request, client ORDER BY times_asked DESC LIMIT 50 ``` ## Tool call volume by client and tool, daily Use this query to show daily call volume on a dashboard. ```sql SELECT toDate(timestamp) AS day, properties.$mcp_client_name AS client, properties.$mcp_tool_name AS tool, count() AS calls FROM events WHERE event = '$mcp_tool_call' AND timestamp > now() - INTERVAL 30 DAY GROUP BY day, client, tool ORDER BY day DESC, calls DESC ```