#4563·umami

MCP: `filters.event` on the stats, traffic and metrics tools returns zeros

Author: LudwigJMarxCreated Sep 23, 2026Updated Sep 29, 2026
Labelsbugfixed in dev

Describe the Bug

The MCP tools get_website_stats, get_website_traffic and get_website_metrics accept filters.event, described as "Custom event name." With this filter set, they return zeros or empty lists with HTTP 200. get_session_stats, get_sessions and get_event_stats accept the same filter and find the matching visitors.

These three tools call /stats, /pageviews and /metrics. Their queries keep only pageview rows (event_type NOT IN (2, 5)), and the filter adds event_name = '<name>'. A row cannot match both conditions.

The query behavior follows the decision in #3886: "Event name filter is only applicable to events and not pageviews." The dashboard applies it, because FilterEditForm.tsx hides event outside /events, /replays and /heatmaps. The MCP package came later with 65bf19e06. It shares one filtersSchema across all tools, so these three tools also offer event.

For an MCP client, the result looks like a valid answer. A question such as "how many visitors fired signup" can get 0 from get_website_stats and 2 from get_event_stats. The unit tests in packages/mcp/src/server.test.ts use a fake API with fixed responses, so they cannot show the empty query result.

Reproduction with one website, four sessions and five pageviews. Two visits fire the custom event signup, and one of these visits also has a pageview. The MCP tools call the HTTP routes in the first table.

HTTP request no filter event=signup
GET /api/websites/<id>/stats pageviews 5, visitors 3, visits 4 0, 0, 0
GET /api/websites/<id>/pageviews 3 points []
GET /api/websites/<id>/metrics?type=path 3 rows []
GET /api/websites/<id>/sessions/stats visitors 4 visitors 2
GET /api/websites/<id>/sessions 4 sessions 2 sessions
MCP tool (/mcp, MCP_ENABLED=1, API key) filters: { event: "signup" }
get_website_stats pageviews 0, visitors 0, visits 0
get_website_traffic pageviews: [], visits: []
get_website_metrics (type: "path") data: []
get_session_stats visitors 2, visits 2, events 2
get_event_stats events 2, visitors 2, visits 2

I got the same results on PostgreSQL alone and with CLICKHOUSE_URL set. For the ClickHouse run, I first removed the events from PostgreSQL, so the numbers come from ClickHouse. I measured get_website_metrics only with type: "path". get_goals and get_performance also offer filters.event, but I did not measure them.

I see three possible fixes:

  1. Remove event from the filter schema of the three tools, and point to get_event_stats in their descriptions. Because filtersSchema is .strict(), a client that still sends event then gets a validation error instead of a zero. I checked this with filtersSchema.omit({ event: true }), which rejects { event: "signup" } with Unrecognized key: "event".
  2. Keep the field and return a tool error when it is set. This gives the same result as option 1, but needs extra code in each tool.
  3. Make the stats queries filter by visits that contain the event. This changes the rule from #3886, so I do not suggest it.

I prefer option 1, because it applies the dashboard rule to MCP with the smallest change. Is this the direction you want? If yes, I can open a PR against dev.

Database

PostgreSQL

Relevant log output

bash
No errors in the server log.

Which Umami version are you using?

dev at 12ad773d (2026-09-23). master at ec0ff503 has the same MCP filter schema.

How are you deploying your application?

Local next dev on macOS 26.6.2 with Node 24.14.1, PostgreSQL 17.10 and ClickHouse 25.8.33.6.

Which browser are you using?

Not applicable. I used only MCP and the HTTP API.