# Sample queries - Docs

A starter set of HogQL queries for the most common MCP analytics questions. All of them assume the SDK is installed and at least a few `$mcp_tool_call` events have landed. See the [event reference](/docs/mcp-analytics/events.md) for the full property list.

{/ *TODO: ProductScreenshot of the SQL editor showing one of these queries running with real MCP data* /}

## Top tools per server

SQL

[Run in PostHog](https://us.posthog.com/sql?open_query=SELECT%0A++properties.%24mcp_server_name+AS+server%2C%0A++properties.%24mcp_tool_name+++AS+tool%2C%0A++count%28%29+AS+calls%0AFROM+events%0AWHERE+event+%3D+'%24mcp_tool_call'%0A++AND+timestamp+%3E+now%28%29+-+INTERVAL+7+DAY%0AGROUP+BY+server%2C+tool%0AORDER+BY+calls+DESC%0ALIMIT+50)

PostHog AI

```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

[Run in PostHog](https://us.posthog.com/sql?open_query=SELECT%0A++properties.%24mcp_tool_name+AS+tool%2C%0A++countIf%28properties.%24mcp_is_error%29++++++++AS+errors%2C%0A++count%28%29++++++++++++++++++++++++++++++++++AS+total%2C%0A++countIf%28properties.%24mcp_is_error%29+%2F+count%28%29+AS+error_rate%0AFROM+events%0AWHERE+event+%3D+'%24mcp_tool_call'%0A++AND+timestamp+%3E+now%28%29+-+INTERVAL+7+DAY%0AGROUP+BY+tool%0AORDER+BY+total+DESC)

PostHog AI

```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

[Run in PostHog](https://us.posthog.com/sql?open_query=SELECT%0A++properties.%24mcp_tool_name+AS+tool%2C%0A++quantile%280.95%29%28toFloat%28properties.%24mcp_duration_ms%29%29+AS+p95_ms%0AFROM+events%0AWHERE+event+%3D+'%24mcp_tool_call'%0A++AND+timestamp+%3E+now%28%29+-+INTERVAL+7+DAY%0AGROUP+BY+tool%0AORDER+BY+p95_ms+DESC)

PostHog AI

```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

[Run in PostHog](https://us.posthog.com/sql?open_query=SELECT%0A++properties.%24mcp_intent_source+AS+source%2C%0A++properties.%24mcp_tool_name+++++AS+tool%2C%0A++any%28properties.%24mcp_intent%29+++AS+sample_intent%2C%0A++count%28%29+++++++++++++++++++++++AS+calls%0AFROM+events%0AWHERE+event+%3D+'%24mcp_tool_call'%0A++AND+timestamp+%3E+now%28%29+-+INTERVAL+24+HOUR%0AGROUP+BY+source%2C+tool%0AORDER+BY+calls+DESC)

PostHog AI

```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

SQL

[Run in PostHog](https://us.posthog.com/sql?open_query=SELECT%0A++properties.%24mcp_client_name+AS+client%2C%0A++uniq%28properties.%24session_id%29+AS+sessions%0AFROM+events%0AWHERE+event+IN+%28'%24mcp_initialize'%2C+'%24mcp_tool_call'%29%0A++AND+timestamp+%3E+now%28%29+-+INTERVAL+7+DAY%0AGROUP+BY+client%0AORDER+BY+sessions+DESC)

PostHog AI

```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

Tools listed in `tools/list` responses but never invoked. Useful to find dead surface area.

SQL

[Run in PostHog](https://us.posthog.com/sql?open_query=WITH+listed+AS+%28%0A++SELECT+DISTINCT+arrayJoin%28properties.%24mcp_listed_tool_names%29+AS+tool_name%0A++FROM+events%0A++WHERE+event+%3D+'%24mcp_tools_list'%0A++++AND+timestamp+%3E+now%28%29+-+INTERVAL+30+DAY%0A%29%2C%0Acalled+AS+%28%0A++SELECT+DISTINCT+properties.%24mcp_tool_name+AS+tool_name%0A++FROM+events%0A++WHERE+event+%3D+'%24mcp_tool_call'%0A++++AND+timestamp+%3E+now%28%29+-+INTERVAL+30+DAY%0A%29%0ASELECT+tool_name+AS+zombie_tool%0AFROM+listed%0AWHERE+tool_name+NOT+IN+%28SELECT+tool_name+FROM+called%29%0AORDER+BY+tool_name)

PostHog AI

```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

[Run in PostHog](https://us.posthog.com/sql?open_query=SELECT%0A++properties.%24mcp_intent+++++++AS+unmet_request%2C%0A++properties.%24mcp_client_name++AS+client%2C%0A++count%28%29++++++++++++++++++++++AS+times_asked%0AFROM+events%0AWHERE+event+%3D+'%24mcp_missing_capability'%0A++AND+timestamp+%3E+now%28%29+-+INTERVAL+30+DAY%0AGROUP+BY+unmet_request%2C+client%0AORDER+BY+times_asked+DESC%0ALIMIT+50)

PostHog AI

```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

Good as a baseline trend for a dashboard.

SQL

[Run in PostHog](https://us.posthog.com/sql?open_query=SELECT%0A++toDate%28timestamp%29+++++++++++++++AS+day%2C%0A++properties.%24mcp_client_name+++++AS+client%2C%0A++properties.%24mcp_tool_name+++++++AS+tool%2C%0A++count%28%29+++++++++++++++++++++++++AS+calls%0AFROM+events%0AWHERE+event+%3D+'%24mcp_tool_call'%0A++AND+timestamp+%3E+now%28%29+-+INTERVAL+30+DAY%0AGROUP+BY+day%2C+client%2C+tool%0AORDER+BY+day+DESC%2C+calls+DESC)

PostHog AI

```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
```

### Community questions

Ask a question

### Was this page useful?

HelpfulCould be better