: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
feat(mcp): add query-retention-actors tool (#64205)
Georgis Andonis0993250d4749
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex a7c244ec0b78..524229d0793b 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -4000,6 +4000,8 @@ snapshots:hash: v1.k794b7964.fa32f317c7015ae73b5b5c38e11209e6a51967de4e0457ae29f7eedb8ea8fce8._OUjY62EdIDs4LQbOyr1ORBmTYMn9AZ5BHWC9e4Bx5cmcp-apps-lifecycle--stacked--light:hash: v1.k794b7964.9ae65eadce145d0cbade09760b4d774eab2861bf0bf9bd0bdf36f1dd1389a620.qYdACXQ2q-w43FAjwS-g7JDwiZiGs6-Mc5lsUs79byA+ mcp-apps-retention-actors--daily--light:+ hash: v1.k794b7964.0a701acbd2d9dac54c345d22841a6d92b6c2b3728421e8fa5fd574a769514e04.Rhb4Qb0bfRbA3ZB2_4f4WM5507JnwCgoox1RbE9y8Ksmcp-apps-surveys--active-popover--light:hash: v1.k794b7964.c47633461e9a437f0761e09f795eb793b02ed0bac4489ce757a5837dbaa3f847.wclUgXFjBkoHXJLNP2R3ncawfRArgVyVEUWbIiQve0omcp-apps-surveys--completed--light:diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.jsonindex 74e96a08a146..07ff5614f7bf 100644--- a/frontend/src/queries/schema.json+++ b/frontend/src/queries/schema.json@@ -3372,6 +3372,26 @@"required": ["type", "id"],"type": "object"},+ "AssistantRetentionActorsQuery": {+ "additionalProperties": false,+ "description": "Drills into a retention insight to list the persons in one acquisition cohort and show, for each, which subsequent intervals they came back in. Returned rows are `distinct_id`, `email`, `name`, followed by one column per retention interval (`<period>_0` … `<period>_N`, e.g. `day_0`, `day_1`, … for a daily insight). Each interval column is `1` when the actor was active in that interval and `0` otherwise; `<period>_0` is the acquisition interval and is always `1`. Rows are ordered by how many intervals each actor returned in (most-retained first).\n\nThe number and name of the interval columns are derived from the source — `retentionFilter.period` sets the prefix and `retentionFilter.totalIntervals` (or `retentionCustomBrackets.length + 1` when custom brackets are set) sets the count.\n\nRetention drilldown has no per-cell `day` / `series` / `compare` selectors and no matched-recordings column — its persons output is appearance-based.",+ "properties": {+ "interval": {+ "$ref": "#/definitions/integer",+ "description": "Which acquisition cohort to drill into, 0-based. `0` is the acquisition interval itself (every actor who entered the cohort); `1` is the cohort that entered one interval later, and so on. Defaults to `0` when omitted."+ },+ "kind": {+ "const": "InsightActorsQuery",+ "type": "string"+ },+ "source": {+ "$ref": "#/definitions/AssistantRetentionQuery",+ "description": "The source retention insight query whose cohort we are drilling into."+ }+ },+ "required": ["kind", "source"],+ "type": "object"+ },"AssistantRetentionEntity": {"anyOf": [{@@ -3454,6 +3474,7 @@"items": {"type": "number"},+ "maxItems": 31,"type": "array"},"retentionReference": {diff --git a/frontend/src/queries/schema/schema-assistant-queries.ts b/frontend/src/queries/schema/schema-assistant-queries.tsindex 677917756159..e9ea4c490afb 100644--- a/frontend/src/queries/schema/schema-assistant-queries.ts+++ b/frontend/src/queries/schema/schema-assistant-queries.ts@@ -876,7 +876,10 @@ export interface AssistantRetentionFilter {* The time window mode to use for retention calculations.*/timeWindowMode?: 'strict_calendar_dates' | '24_hour_windows'- /** Custom brackets for retention calculations. */+ /**+ * Custom brackets for retention calculations.+ * @maxItems 31+ */retentionCustomBrackets?: number[]/*** The aggregation type to use for retention.@@ -1342,6 +1345,35 @@ export interface AssistantPathsActorsQuery {includeRecordings?: boolean}+/**+ * Drills into a retention insight to list the persons in one acquisition cohort and show, for each,+ * which subsequent intervals they came back in. Returned rows are `distinct_id`, `email`, `name`,+ * followed by one column per retention interval (`<period>_0` … `<period>_N`, e.g. `day_0`, `day_1`,+ * … for a daily insight). Each interval column is `1` when the actor was active in that interval and+ * `0` otherwise; `<period>_0` is the acquisition interval and is always `1`. Rows are ordered by how+ * many intervals each actor returned in (most-retained first).+ *+ * The number and name of the interval columns are derived from the source — `retentionFilter.period`+ * sets the prefix and `retentionFilter.totalIntervals` (or `retentionCustomBrackets.length + 1` when+ * custom brackets are set) sets the count.+ *+ * Retention drilldown has no per-cell `day` / `series` / `compare` selectors and no matched-recordings+ * column — its persons output is appearance-based.+ */+export interface AssistantRetentionActorsQuery {+ kind: NodeKind.InsightActorsQuery++ /** The source retention insight query whose cohort we are drilling into. */+ source: AssistantRetentionQuery++ /**+ * Which acquisition cohort to drill into, 0-based. `0` is the acquisition interval itself (every+ * actor who entered the cohort); `1` is the cohort that entered one interval later, and so on.+ * Defaults to `0` when omitted.+ */+ interval?: integer+}+/*** Query LLM traces to inspect AI/LLM usage. Returns a list of traces with latency,* token usage, costs, errors, and other metadata. Use for AI observability — debuggingdiff --git a/posthog/schema.py b/posthog/schema.pyindex 5541250ea7f0..1975f95adec8 100644--- a/posthog/schema.py+++ b/posthog/schema.py@@ -8909,7 +8909,9 @@ class AssistantRetentionFilter(BaseModel):description="Retention period, the interval to track cohorts by.",)retentionCustomBrackets: list[float] | None = Field(- default=None, description="Custom brackets for retention calculations."+ default=None,+ description="Custom brackets for retention calculations.",+ max_length=31,)retentionReference: RetentionReference | None = Field(default=None,@@ -21104,6 +21106,25 @@ class AssistantPathsActorsQuery(BaseModel):source: AssistantPathsQuery = Field(..., description="The source paths insight query whose actors we are listing.")+class AssistantRetentionActorsQuery(BaseModel):+ model_config = ConfigDict(+ extra="forbid",+ )+ interval: int | None = Field(+ default=None,+ description=(+ "Which acquisition cohort to drill into, 0-based. `0` is the acquisition"+ " interval itself (every actor who entered the cohort); `1` is the cohort"+ " that entered one interval later, and so on. Defaults to `0` when omitted."+ ),+ )+ kind: Literal["InsightActorsQuery"] = "InsightActorsQuery"+ source: AssistantRetentionQuery = Field(+ ...,+ description=("The source retention insight query whose cohort we are drilling into."),+ )++class AssistantTrendsActorsQuery(BaseModel):model_config = ConfigDict(extra="forbid",diff --git a/products/product_analytics/mcp/apps/InsightActorsView.tsx b/products/product_analytics/mcp/apps/InsightActorsView.tsxindex 993406b66e81..b5a11789d7db 100644--- a/products/product_analytics/mcp/apps/InsightActorsView.tsx+++ b/products/product_analytics/mcp/apps/InsightActorsView.tsx@@ -3,7 +3,8 @@ import { type ReactElement, type ReactNode, useMemo } from 'react'import { DataTable, type DataTableColumn } from '@posthog/mcp-ui'import { Badge, Button } from '@posthog/quill'-import { type ActorRow, type InsightActorsData, toActorRows } from './insightActorsTransforms'+import { type ActorRow, type InsightActorsData, isRetentionActorsData, toActorRows } from './insightActorsTransforms'+import { RetentionActorsView } from './RetentionActorsView'export type { InsightActorsData }@@ -13,6 +14,14 @@ interface InsightActorsViewProps {}export function InsightActorsView({ data, openLink }: InsightActorsViewProps): ReactElement {+ // Retention actors have a per-interval grid shape (no event_count) — render the cohort table instead.+ if (isRetentionActorsData(data)) {+ return <RetentionActorsView data={data} />+ }+ return <EventCountActorsView data={data} openLink={openLink} />+}++function EventCountActorsView({ data, openLink }: InsightActorsViewProps): ReactElement {const rows = useMemo(() => toActorRows(data), [data])const hasRecordings = data.results.columns.includes('recordings')diff --git a/products/product_analytics/mcp/apps/RetentionActorsView.stories.tsx b/products/product_analytics/mcp/apps/RetentionActorsView.stories.tsxnew file mode 100644index 000000000000..fc48b200bea8--- /dev/null+++ b/products/product_analytics/mcp/apps/RetentionActorsView.stories.tsx@@ -0,0 +1,64 @@+import type { Meta, StoryObj } from '@storybook/react'++import { McpThemeDecorator } from '@posthog/mcp-ui/storybook/decorator'++import { type InsightActorsData } from './insightActorsTransforms'+import { RetentionActorsView } from './RetentionActorsView'++const meta: Meta = {+ title: 'MCP Apps/Retention Actors',+ decorators: [McpThemeDecorator],+ parameters: {+ testOptions: {+ // McpThemeDecorator has no dark mode, so skip it to avoid duplicated snapshots.+ skipDarkMode: true,+ },+ },+}+export default meta++type Story = StoryObj<{}>++// `results` is the flattened actors table: `[distinct_id, email, name, <period>_0 … <period>_N]`,+// where each interval cell is 1 (returned) or 0 (did not).+const dailyCohort: InsightActorsData = {+ query: {+ kind: 'ActorsQuery',+ source: {+ kind: 'InsightActorsQuery',+ interval: 0,+ source: { kind: 'RetentionQuery', retentionFilter: { period: 'Day', totalIntervals: 8 } },+ },+ },+ results: {+ columns: [+ 'distinct_id',+ 'email',+ 'name',+ 'day_0',+ 'day_1',+ 'day_2',+ 'day_3',+ 'day_4',+ 'day_5',+ 'day_6',+ 'day_7',+ ],+ results: [+ ['0a1b2c3d', '[email protected]', 'Alice Adams', 1, 1, 1, 1, 1, 0, 1, 0],+ ['1c2d3e4f', '[email protected]', 'Ben Brown', 1, 1, 1, 0, 1, 0, 0, 0],+ ['2e3f4a5b', '[email protected]', 'Cara Cohen', 1, 1, 0, 1, 0, 0, 0, 0],+ ['3f4a5b6c', null, null, 1, 1, 0, 0, 0, 0, 0, 0],+ ['4a5b6c7d', '[email protected]', 'Dan Diaz', 1, 0, 1, 0, 0, 0, 0, 0],+ ['5b6c7d8e', '[email protected]', null, 1, 0, 0, 0, 0, 0, 0, 0],+ ['6c7d8e9f', null, null, 1, 0, 0, 0, 0, 0, 0, 0],+ ],+ },+ hasMore: false,+ offset: 0,+}++export const Daily: Story = {+ render: () => <RetentionActorsView data={dailyCohort} />,+ name: 'Daily cohort',+}diff --git a/products/product_analytics/mcp/apps/RetentionActorsView.tsx b/products/product_analytics/mcp/apps/RetentionActorsView.tsxnew file mode 100644index 000000000000..4282a8f48097--- /dev/null+++ b/products/product_analytics/mcp/apps/RetentionActorsView.tsx@@ -0,0 +1,82 @@+import { type ReactElement, type ReactNode, useMemo } from 'react'++import { DataTable, type DataTableColumn } from '@posthog/mcp-ui'++import {+ type InsightActorsData,+ type RetentionActorRow,+ retentionPeriodColumns,+ summarizeRetentionIntervals,+ toRetentionActorRows,+} from './insightActorsTransforms'++// Renders the retention persons table — one row per cohort member, one column per return interval,+// each cell marking whether the person returned. Column headers carry the per-interval retained count+// and percentage (relative to the cohort), mirroring the app's retention persons modal.+export function RetentionActorsView({ data }: { data: InsightActorsData }): ReactElement {+ const periodCols = useMemo(() => retentionPeriodColumns(data), [data])+ const rows = useMemo(() => toRetentionActorRows(data, periodCols), [data, periodCols])+ const summary = useMemo(() => summarizeRetentionIntervals(rows, periodCols), [rows, periodCols])++ const columns = useMemo((): DataTableColumn<RetentionActorRow>[] => {+ const cols: DataTableColumn<RetentionActorRow>[] = [+ {+ key: 'actor',+ header: 'Person',+ render: (row): ReactNode => {+ const displayName = row.email || row.name || row.distinct_id || 'Anonymous'+ return (+ <div className="flex flex-col">+ <span className="font-medium">{displayName}</span>+ {row.distinct_id && row.distinct_id !== displayName && (+ <span className="text-xs text-muted-foreground">{row.distinct_id}</span>+ )}+ </div>+ )+ },+ },+ ]++ summary.forEach((col, i) => {+ cols.push({+ key: `interval_${col.interval}`,+ align: 'center',+ header: (+ <div className="flex flex-col items-center leading-tight">+ <span>{col.label}</span>+ <span className="text-xs font-normal text-muted-foreground">+ {col.count} ({col.percentage}%)+ </span>+ </div>+ ),+ render: (row): ReactNode => {+ const returned = row.appearances[i]+ return (+ <div+ className={`mx-auto h-4 w-4 rounded-sm bg-[#1d4aff] ${returned ? '' : 'opacity-20'}`}+ title={returned ? 'Returned' : 'Did not return'}+ />+ )+ },+ })+ })++ return cols+ }, [summary])++ return (+ <div className="p-4">+ <div className="flex flex-col gap-2">+ <span className="text-sm text-muted-foreground">+ {rows.length} person{rows.length === 1 ? '' : 's'}+ {data.hasMore ? '+' : ''} in this cohort+ </span>+ <DataTable<RetentionActorRow>+ columns={columns}+ data={rows}+ emptyMessage="No persons found for this cohort"+ />+ </div>+ </div>+ )+}diff --git a/products/product_analytics/mcp/apps/insightActorsTransforms.ts b/products/product_analytics/mcp/apps/insightActorsTransforms.tsindex 8d761765c303..44dd0357a15e 100644--- a/products/product_analytics/mcp/apps/insightActorsTransforms.ts+++ b/products/product_analytics/mcp/apps/insightActorsTransforms.ts@@ -17,13 +17,18 @@ export interface ActorRow {recordings: string[]}+function rowToObject(columns: string[], row: (string | number | null | string[])[]): Record<string, unknown> {+ const obj: Record<string, unknown> = {}+ columns.forEach((col, i) => {+ obj[col] = row[i]+ })+ return obj+}+export function toActorRows(data: InsightActorsData): ActorRow[] {const { columns, results } = data.resultsreturn results.map((row) => {- const obj: Record<string, unknown> = {}- columns.forEach((col, i) => {- obj[col] = row[i]- })+ const obj = rowToObject(columns, row)return {distinct_id: (obj.distinct_id as string) ?? null,email: (obj.email as string) ?? null,@@ -33,3 +38,75 @@ export function toActorRows(data: InsightActorsData): ActorRow[] {}})}++// Retention actors project one `<period>_N` column per return interval (e.g. `day_0`, `week_1`),+// each cell 1/0 — a fundamentally different shape from the event-count actor table.+const RETENTION_COLUMN_RE = /^(day|week|month|hour)_(\d+)$/++export function isRetentionActorsData(data: InsightActorsData): boolean {+ return data.results.columns.some((col) => RETENTION_COLUMN_RE.test(col))+}++export interface RetentionPeriodColumn {+ interval: number+ label: string+ index: number+}++/** The `<period>_N` columns, ordered by interval, with display labels (`Day 0`, `Week 1`, …). */+export function retentionPeriodColumns(data: InsightActorsData): RetentionPeriodColumn[] {+ const cols: RetentionPeriodColumn[] = []+ data.results.columns.forEach((name, index) => {+ const match = RETENTION_COLUMN_RE.exec(name)+ if (match) {+ const period = match[1] ?? 'day'+ const interval = Number(match[2])+ cols.push({ interval, label: `${period.charAt(0).toUpperCase()}${period.slice(1)} ${interval}`, index })+ }+ })+ return cols.sort((a, b) => a.interval - b.interval)+}++export interface RetentionActorRow {+ distinct_id: string | null+ email: string | null+ name: string | null+ /** Whether the actor returned in each interval, aligned to `retentionPeriodColumns` order. */+ appearances: boolean[]+}++export function toRetentionActorRows(+ data: InsightActorsData,+ periodCols: RetentionPeriodColumn[]+): RetentionActorRow[] {+ const { columns, results } = data.results+ return results.map((row) => {+ const obj = rowToObject(columns, row)+ return {+ distinct_id: (obj.distinct_id as string) ?? null,+ email: (obj.email as string) ?? null,+ name: (obj.name as string) ?? null,+ appearances: periodCols.map((pc) => !!row[pc.index]),+ }+ })+}++export interface RetentionIntervalSummary extends RetentionPeriodColumn {+ count: number+ percentage: number+}++// Per-interval retained count + percentage for the column headers, computed over the returned rows.+// Percentage is relative to interval 0 (the cohort baseline), matching the app's persons-modal header.+export function summarizeRetentionIntervals(+ rows: RetentionActorRow[],+ periodCols: RetentionPeriodColumn[]+): RetentionIntervalSummary[] {+ const countAt = (i: number): number => rows.reduce((acc, row) => acc + (row.appearances[i] ? 1 : 0), 0)+ const baseCount = periodCols.length > 0 ? countAt(0) : 0+ return periodCols.map((pc, i) => {+ const count = countAt(i)+ const percentage = baseCount > 0 ? Math.round((count / baseCount) * 10000) / 100 : 0+ return { ...pc, count, percentage }+ })+}diff --git a/services/mcp/definitions/prompts/query-retention-actors.md b/services/mcp/definitions/prompts/query-retention-actors.mdnew file mode 100644index 000000000000..aef0a781dbb6--- /dev/null+++ b/services/mcp/definitions/prompts/query-retention-actors.md@@ -0,0 +1,23 @@+List the persons in one retention acquisition cohort and show, for each, which subsequent intervals they came back in.++Pair this with `query-retention`: first run the retention query to see the cohort table (rows are acquisition cohorts, columns are intervals after acquisition), then call this tool with the **same** retention query as `source` to drill into one cohort.++Selectors:++- `interval`: which acquisition cohort to list, 0-based. `0` is the acquisition interval itself (every actor who entered the cohort), `1` is the cohort that entered one interval later, and so on. Defaults to `0`. This selects a **row** of the retention table; the returned columns then cover every interval for that cohort.++Response:++`results` is the per-person grid. Each row contains `distinct_id`, `email`, `name`, followed by one column per retention interval — `<period>_0` … `<period>_N`, where `<period>` is the retention period (`day` / `week` / `month` / `hour`). Each interval column is `1` if the actor was active in that interval and `0` if not. `<period>_0` is the acquisition interval and is always `1`. Rows are ordered by how many intervals the actor returned in (most-retained first). Results are limited to the top 100 actors.++For the per-interval retention **counts and percentages** (the `Day N — count (pct%)` curve), run `query-retention` on the same `source` — those are computed over the full, un-capped cohort. Don't sum these (capped) rows to get cohort retention numbers.++The number and names of the interval columns come from the source: `retentionFilter.period` sets the prefix, and `retentionFilter.totalIntervals` (or `retentionCustomBrackets.length + 1` when custom brackets are set) sets how many columns there are.++There is no `includeRecordings` selector — retention's persons output is appearance-based and does not surface matched session recordings.++Guidance:++- Keep the `source` retention query identical to the one whose cohort the user is asking about — the cohort definition (target/returning events, period, type, brackets) determines who is in each cohort.+- `interval` picks the cohort (a **row** of the retention table), not a single cell. The response always spans every return interval as `<period>_N` columns. To get who returned in a specific interval, filter the rows where that column is `1` — the query returns the cohort's whole trajectory, not a single cell.+- To narrow large result sets, tighten the source (date range, filters) rather than expecting more than 100 rows.diff --git a/services/mcp/definitions/query-wrappers.yaml b/services/mcp/definitions/query-wrappers.yamlindex 1148371a674f..7b6441301042 100644--- a/services/mcp/definitions/query-wrappers.yaml+++ b/services/mcp/definitions/query-wrappers.yaml@@ -210,3 +210,22 @@ wrappers:exclude_properties:- response- modifiers++ query-retention-actors:+ schema_ref: AssistantRetentionActorsQuery+ enabled: true+ scopes:+ - query:read+ - person:read+ annotations:+ readOnly: true+ destructive: false+ idempotent: true+ title: List persons in a retention cohort+ description_file: ./prompts/query-retention-actors.md+ system_prompt_hint: List persons in a retention acquisition cohort and which intervals they returned in+ ui_resource_uri: ui://posthog/insight-actors.html+ use_optimized_output: true+ exclude_properties:+ - response+ - modifiersdiff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.jsonindex e7c2fc92a841..180d5c80fb57 100644--- a/services/mcp/schema/generated-tool-definitions.json+++ b/services/mcp/schema/generated-tool-definitions.json@@ -5550,6 +5550,21 @@},"system_prompt_hint": "User return patterns over time"},+ "query-retention-actors": {+ "description": "List the persons in one retention acquisition cohort and show, for each, which subsequent intervals they came back in.\n\nPair this with `query-retention`: first run the retention query to see the cohort table (rows are acquisition cohorts, columns are intervals after acquisition), then call this tool with the **same** retention query as `source` to drill into one cohort.\n\nSelectors:\n\n- `interval`: which acquisition cohort to list, 0-based. `0` is the acquisition interval itself (every actor who entered the cohort), `1` is the cohort that entered one interval later, and so on. Defaults to `0`. This selects a **row** of the retention table; the returned columns then cover every interval for that cohort.\n\nResponse:\n\n`results` is the per-person grid. Each row contains `distinct_id`, `email`, `name`, followed by one column per retention interval — `<period>_0` … `<period>_N`, where `<period>` is the retention period (`day` / `week` / `month` / `hour`). Each interval column is `1` if the actor was active in that interval and `0` if not. `<period>_0` is the acquisition interval and is always `1`. Rows are ordered by how many intervals the actor returned in (most-retained first). Results are limited to the top 100 actors.\n\nFor the per-interval retention **counts and percentages** (the `Day N — count (pct%)` curve), run `query-retention` on the same `source` — those are computed over the full, un-capped cohort. Don't sum these (capped) rows to get cohort retention numbers.\n\nThe number and names of the interval columns come from the source: `retentionFilter.period` sets the prefix, and `retentionFilter.totalIntervals` (or `retentionCustomBrackets.length + 1` when custom brackets are set) sets how many columns there are.\n\nThere is no `includeRecordings` selector — retention's persons output is appearance-based and does not surface matched session recordings.\n\nGuidance:\n\n- Keep the `source` retention query identical to the one whose cohort the user is asking about — the cohort definition (target/returning events, period, type, brackets) determines who is in each cohort.\n- `interval` picks the cohort (a **row** of the retention table), not a single cell. The response always spans every return interval as `<period>_N` columns. To get who returned in a specific interval, filter the rows where that column is `1` — the query returns the cohort's whole trajectory, not a single cell.\n- To narrow large result sets, tighten the source (date range, filters) rather than expecting more than 100 rows.",+ "category": "Query wrappers",+ "feature": "insights",+ "summary": "List persons in a retention cohort",+ "title": "List persons in a retention cohort",+ "required_scopes": ["query:read", "person:read"],+ "annotations": {+ "destructiveHint": false,+ "idempotentHint": true,+ "openWorldHint": true,+ "readOnlyHint": true+ },+ "system_prompt_hint": "List persons in a retention acquisition cohort and which intervals they returned in"+ },"query-session-recordings-list": {"description": "List session recordings in the project. Returns recording metadata including duration, activity counts, console errors, start URL, and interaction metrics. Use this tool to find, filter, and explore session recordings.\n\nUse 'read-data-schema' to discover available person, session, and event properties for filtering.\n\nExamples of use cases include:\n\n- Find recordings with console errors in the last week\n- Show me recordings from users in a specific country\n- List the longest recordings from today\n- Find recordings where users visited a specific page\n- Show recordings with high activity scores\n- Find recordings for a specific person\n\nCRITICAL: Be minimalist. Only include filters and settings essential to answer the user's question. Default settings are usually sufficient.\n\n# Property filters\n\nUse property filters to narrow results. Only include filters directly relevant to the user's question.\n\nWhen using a property filter, you should:\n\n- **Prioritize properties directly related to the user's query.**\n- **Ensure the correct filter type.** Types: `person`, `session`, `event`, `recording`, `cohort`.\n- **Use `read-data-schema` to discover property names and values** before creating filters.\n\n## Common properties\n\n**Recording** (type: `recording`): `console_error_count`, `click_count`, `keypress_count`, `mouse_activity_count`, `activity_score`. These are built-in metrics, not events.\n\n**Session** (type: `session`): `$session_duration`, `$channel_type`, `$entry_current_url`, `$entry_pathname`, `$is_bounce`, `$pageview_count`.\n\n**Person** (type: `person`): `$geoip_country_code`, `$geoip_city_name`, `email`, and custom person properties.\n\n**Event** (type: `event`): `$current_url`, `$pathname`, `$browser`, `$os`, `$device_type`, `$screen_width`.\n\n**Cohort** (type: `cohort`): scope recordings to persons belonging to a cohort. `key` is always `\"id\"`, `value` is the cohort ID, operator is `in` (or `not_in` to exclude). Example: `{ \"type\": \"cohort\", \"key\": \"id\", \"value\": 42, \"operator\": \"in\" }`. Use `cohorts-list` to find cohort IDs.\n\n## Operators\n\n**String**: `exact`, `is_not`, `icontains`, `not_icontains`, `regex`, `not_regex`, `is_set`, `is_not_set`\n**Numeric**: `exact`, `is_not`, `gt`, `gte`, `lt`, `lte`, `is_set`, `is_not_set`\n**DateTime**: `is_date_exact`, `is_date_before`, `is_date_after`, `is_set`, `is_not_set`\n**Boolean**: `exact`, `is_not`, `is_set`, `is_not_set`\n\n`exact` and `is_not` accept arrays of values. Use `icontains` for URLs, `exact` for enumerated values, `gt`/`lt` for counts.\n\n# Ordering\n\nSort recordings by: `start_time` (default), `duration`, `activity_score`, `console_error_count`, `click_count`, `keypress_count`, `mouse_activity_count`, `active_seconds`, `inactive_seconds`.\n\nDefault direction is `DESC` (newest/highest first).\n\n# Date range\n\n- `date_from`: Relative (`-7d`, `-24h`) or absolute (`2025-01-15`). Default: `-3d`.\n- `date_to`: Relative or absolute. Default: now.\n\nDo not use property filters for time-based filtering. Use the `date_from`/`date_to` fields instead.\n\n# Pagination\n\nUse `limit` to control page size and `after` (from the previous response's `next_cursor`) for cursor-based pagination.\n\n# Response shape\n\nEach recording in results contains:\n\n- `id` — session recording ID\n- `distinct_id` — the person's distinct ID\n- `start_time` / `end_time` — recording time range (ISO 8601)\n- `recording_duration` — length in seconds\n- `active_seconds` / `inactive_seconds` — activity breakdown\n- `click_count`, `keypress_count`, `mouse_activity_count` — interaction counts\n- `console_log_count`, `console_warn_count`, `console_error_count` — console output counts\n- `start_url` — first page URL visited\n- `activity_score` — engagement score (higher = more active)\n- `ongoing` — whether the session is still active\n\n# Deep links to specific recordings\n\nTo link a user to a specific recording, build the URL as `{posthog_base_url}/replay/{id}` using the `id` returned in each result row.\n\nDo not use `/replay/home?sessionRecordingId={id}` — that path takes the user to the replay list with the default filter applied and does not open the recording.\n\n# Examples\n\n## Recent recordings with console errors\n\n```json\n{\n \"date_from\": \"-7d\",\n \"filter_test_accounts\": true,\n \"properties\": [{ \"key\": \"console_error_count\", \"operator\": \"gt\", \"type\": \"recording\", \"value\": 0 }],\n \"order\": \"console_error_count\"\n}\n```\n\n## Longest recordings today\n\n```json\n{\n \"date_from\": \"-1d\",\n \"filter_test_accounts\": true,\n \"order\": \"duration\",\n \"limit\": 10\n}\n```\n\n## Recordings for a specific person\n\n```json\n{\n \"date_from\": \"-30d\",\n \"person_uuid\": \"01234567-89ab-cdef-0123-456789abcdef\",\n \"filter_test_accounts\": true\n}\n```\n\n## Recordings from mobile users\n\n```json\n{\n \"date_from\": \"-7d\",\n \"filter_test_accounts\": true,\n \"properties\": [{ \"key\": \"$device_type\", \"operator\": \"exact\", \"type\": \"event\", \"value\": [\"Mobile\"] }]\n}\n```\n\n## Recordings from a cohort of users\n\n```json\n{\n \"date_from\": \"-7d\",\n \"filter_test_accounts\": true,\n \"properties\": [{ \"key\": \"id\", \"operator\": \"in\", \"type\": \"cohort\", \"value\": 42 }]\n}\n```\n\n## Fetch specific recordings by session ID\n\nWhen you have known `$session_id` values (e.g., from `$exception` events or other event data), use the `session_ids` parameter to fetch those recordings directly:\n\n```json\n{\n \"session_ids\": [\"session-id-1\", \"session-id-2\", \"session-id-3\"]\n}\n```\n\n# Reminders\n\n- Use `filter_test_accounts: true` by default to exclude internal users.\n- Only include property filters directly relevant to the user's question.\n- Default time range is last 3 days. Adjust based on the user's needs.\n- Deep-link to a specific recording as `{posthog_base_url}/replay/{id}`, never `/replay/home?sessionRecordingId={id}`.\n- For detailed analysis of a single recording, use `session-recording-get` with the recording's `id`.\n- **If no recordings are found** or the user asks why recordings aren't being captured, diagnose with `execute-sql`: query `$recording_status`, `$session_recording_start_reason`, `$replay_sample_rate`, and `$sdk_debug_recording_script_not_loaded` from recent events (no `$session_id` filter needed for project-wide issues). Common causes: sampling excluded sessions, recording disabled in project settings, ad blocker blocked the recorder script, or SDK misconfigured.","category": "Session replays",diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.jsonindex 3052f3815ec4..ba26980c123a 100644--- a/services/mcp/schema/tool-definitions-all.json+++ b/services/mcp/schema/tool-definitions-all.json@@ -5987,6 +5987,21 @@},"system_prompt_hint": "User return patterns over time"},+ "query-retention-actors": {+ "description": "List the persons in one retention acquisition cohort and show, for each, which subsequent intervals they came back in.\n\nPair this with `query-retention`: first run the retention query to see the cohort table (rows are acquisition cohorts, columns are intervals after acquisition), then call this tool with the **same** retention query as `source` to drill into one cohort.\n\nSelectors:\n\n- `interval`: which acquisition cohort to list, 0-based. `0` is the acquisition interval itself (every actor who entered the cohort), `1` is the cohort that entered one interval later, and so on. Defaults to `0`. This selects a **row** of the retention table; the returned columns then cover every interval for that cohort.\n\nResponse:\n\n`results` is the per-person grid. Each row contains `distinct_id`, `email`, `name`, followed by one column per retention interval — `<period>_0` … `<period>_N`, where `<period>` is the retention period (`day` / `week` / `month` / `hour`). Each interval column is `1` if the actor was active in that interval and `0` if not. `<period>_0` is the acquisition interval and is always `1`. Rows are ordered by how many intervals the actor returned in (most-retained first). Results are limited to the top 100 actors.\n\nFor the per-interval retention **counts and percentages** (the `Day N — count (pct%)` curve), run `query-retention` on the same `source` — those are computed over the full, un-capped cohort. Don't sum these (capped) rows to get cohort retention numbers.\n\nThe number and names of the interval columns come from the source: `retentionFilter.period` sets the prefix, and `retentionFilter.totalIntervals` (or `retentionCustomBrackets.length + 1` when custom brackets are set) sets how many columns there are.\n\nThere is no `includeRecordings` selector — retention's persons output is appearance-based and does not surface matched session recordings.\n\nGuidance:\n\n- Keep the `source` retention query identical to the one whose cohort the user is asking about — the cohort definition (target/returning events, period, type, brackets) determines who is in each cohort.\n- `interval` picks the cohort (a **row** of the retention table), not a single cell. The response always spans every return interval as `<period>_N` columns. To get who returned in a specific interval, filter the rows where that column is `1` — the query returns the cohort's whole trajectory, not a single cell.\n- To narrow large result sets, tighten the source (date range, filters) rather than expecting more than 100 rows.",+ "category": "Query wrappers",+ "feature": "insights",+ "summary": "List persons in a retention cohort",+ "title": "List persons in a retention cohort",+ "required_scopes": ["query:read", "person:read"],+ "annotations": {+ "destructiveHint": false,+ "idempotentHint": true,+ "openWorldHint": true,+ "readOnlyHint": true+ },+ "system_prompt_hint": "List persons in a retention acquisition cohort and which intervals they returned in"+ },"query-session-recordings-list": {"description": "List session recordings in the project. Returns recording metadata including duration, activity counts, console errors, start URL, and interaction metrics. Use this tool to find, filter, and explore session recordings.\n\nUse 'read-data-schema' to discover available person, session, and event properties for filtering.\n\nExamples of use cases include:\n\n- Find recordings with console errors in the last week\n- Show me recordings from users in a specific country\n- List the longest recordings from today\n- Find recordings where users visited a specific page\n- Show recordings with high activity scores\n- Find recordings for a specific person\n\nCRITICAL: Be minimalist. Only include filters and settings essential to answer the user's question. Default settings are usually sufficient.\n\n# Property filters\n\nUse property filters to narrow results. Only include filters directly relevant to the user's question.\n\nWhen using a property filter, you should:\n\n- **Prioritize properties directly related to the user's query.**\n- **Ensure the correct filter type.** Types: `person`, `session`, `event`, `recording`, `cohort`.\n- **Use `read-data-schema` to discover property names and values** before creating filters.\n\n## Common properties\n\n**Recording** (type: `recording`): `console_error_count`, `click_count`, `keypress_count`, `mouse_activity_count`, `activity_score`. These are built-in metrics, not events.\n\n**Session** (type: `session`): `$session_duration`, `$channel_type`, `$entry_current_url`, `$entry_pathname`, `$is_bounce`, `$pageview_count`.\n\n**Person** (type: `person`): `$geoip_country_code`, `$geoip_city_name`, `email`, and custom person properties.\n\n**Event** (type: `event`): `$current_url`, `$pathname`, `$browser`, `$os`, `$device_type`, `$screen_width`.\n\n**Cohort** (type: `cohort`): scope recordings to persons belonging to a cohort. `key` is always `\"id\"`, `value` is the cohort ID, operator is `in` (or `not_in` to exclude). Example: `{ \"type\": \"cohort\", \"key\": \"id\", \"value\": 42, \"operator\": \"in\" }`. Use `cohorts-list` to find cohort IDs.\n\n## Operators\n\n**String**: `exact`, `is_not`, `icontains`, `not_icontains`, `regex`, `not_regex`, `is_set`, `is_not_set`\n**Numeric**: `exact`, `is_not`, `gt`, `gte`, `lt`, `lte`, `is_set`, `is_not_set`\n**DateTime**: `is_date_exact`, `is_date_before`, `is_date_after`, `is_set`, `is_not_set`\n**Boolean**: `exact`, `is_not`, `is_set`, `is_not_set`\n\n`exact` and `is_not` accept arrays of values. Use `icontains` for URLs, `exact` for enumerated values, `gt`/`lt` for counts.\n\n# Ordering\n\nSort recordings by: `start_time` (default), `duration`, `activity_score`, `console_error_count`, `click_count`, `keypress_count`, `mouse_activity_count`, `active_seconds`, `inactive_seconds`.\n\nDefault direction is `DESC` (newest/highest first).\n\n# Date range\n\n- `date_from`: Relative (`-7d`, `-24h`) or absolute (`2025-01-15`). Default: `-3d`.\n- `date_to`: Relative or absolute. Default: now.\n\nDo not use property filters for time-based filtering. Use the `date_from`/`date_to` fields instead.\n\n# Pagination\n\nUse `limit` to control page size and `after` (from the previous response's `next_cursor`) for cursor-based pagination.\n\n# Response shape\n\nEach recording in results contains:\n\n- `id` — session recording ID\n- `distinct_id` — the person's distinct ID\n- `start_time` / `end_time` — recording time range (ISO 8601)\n- `recording_duration` — length in seconds\n- `active_seconds` / `inactive_seconds` — activity breakdown\n- `click_count`, `keypress_count`, `mouse_activity_count` — interaction counts\n- `console_log_count`, `console_warn_count`, `console_error_count` — console output counts\n- `start_url` — first page URL visited\n- `activity_score` — engagement score (higher = more active)\n- `ongoing` — whether the session is still active\n\n# Deep links to specific recordings\n\nTo link a user to a specific recording, build the URL as `{posthog_base_url}/replay/{id}` using the `id` returned in each result row.\n\nDo not use `/replay/home?sessionRecordingId={id}` — that path takes the user to the replay list with the default filter applied and does not open the recording.\n\n# Examples\n\n## Recent recordings with console errors\n\n```json\n{\n \"date_from\": \"-7d\",\n \"filter_test_accounts\": true,\n \"properties\": [{ \"key\": \"console_error_count\", \"operator\": \"gt\", \"type\": \"recording\", \"value\": 0 }],\n \"order\": \"console_error_count\"\n}\n```\n\n## Longest recordings today\n\n```json\n{\n \"date_from\": \"-1d\",\n \"filter_test_accounts\": true,\n \"order\": \"duration\",\n \"limit\": 10\n}\n```\n\n## Recordings for a specific person\n\n```json\n{\n \"date_from\": \"-30d\",\n \"person_uuid\": \"01234567-89ab-cdef-0123-456789abcdef\",\n \"filter_test_accounts\": true\n}\n```\n\n## Recordings from mobile users\n\n```json\n{\n \"date_from\": \"-7d\",\n \"filter_test_accounts\": true,\n \"properties\": [{ \"key\": \"$device_type\", \"operator\": \"exact\", \"type\": \"event\", \"value\": [\"Mobile\"] }]\n}\n```\n\n## Recordings from a cohort of users\n\n```json\n{\n \"date_from\": \"-7d\",\n \"filter_test_accounts\": true,\n \"properties\": [{ \"key\": \"id\", \"operator\": \"in\", \"type\": \"cohort\", \"value\": 42 }]\n}\n```\n\n## Fetch specific recordings by session ID\n\nWhen you have known `$session_id` values (e.g., from `$exception` events or other event data), use the `session_ids` parameter to fetch those recordings directly:\n\n```json\n{\n \"session_ids\": [\"session-id-1\", \"session-id-2\", \"session-id-3\"]\n}\n```\n\n# Reminders\n\n- Use `filter_test_accounts: true` by default to exclude internal users.\n- Only include property filters directly relevant to the user's question.\n- Default time range is last 3 days. Adjust based on the user's needs.\n- Deep-link to a specific recording as `{posthog_base_url}/replay/{id}`, never `/replay/home?sessionRecordingId={id}`.\n- For detailed analysis of a single recording, use `session-recording-get` with the recording's `id`.\n- **If no recordings are found** or the user asks why recordings aren't being captured, diagnose with `execute-sql`: query `$recording_status`, `$session_recording_start_reason`, `$replay_sample_rate`, and `$sdk_debug_recording_script_not_loaded` from recent events (no `$session_id` filter needed for project-wide issues). Common causes: sampling excluded sessions, recording disabled in project settings, ad blocker blocked the recorder script, or SDK misconfigured.","category": "Session replays",diff --git a/services/mcp/src/api/client.ts b/services/mcp/src/api/client.tsindex 38c0dec3bc37..9e0c10fff08d 100644--- a/services/mcp/src/api/client.ts+++ b/services/mcp/src/api/client.ts@@ -1158,10 +1158,11 @@ export class ApiClient {const baseUrl = this.getProjectBaseUrl(projectId)- // `actor` → 3 columns, `matched_recordings` → recordings, everything else passes through.+ // `actor`/`person` → 3 columns, `matched_recordings` → recordings, everything else passes through.+ // Retention projects `person`, which carries the same actor shape as `actor`.const columns: string[] = []for (const field of finalSelect) {- if (field === 'actor') {+ if (field === 'actor' || field === 'person') {columns.push('distinct_id', 'email', 'name')} else if (field === 'matched_recordings') {columns.push('recordings')@@ -1175,7 +1176,7 @@ export class ApiClient {for (let i = 0; i < finalSelect.length; i++) {const field = finalSelect[i]const cell = row[i]- if (field === 'actor') {+ if (field === 'actor' || field === 'person') {const props = cell?.properties ?? {}cells.push(cell?.distinct_ids?.[0] ?? null, props.email, props.name)} else if (field === 'matched_recordings') {@@ -1226,6 +1227,32 @@ export class ApiClient {pathsActors: async ({ query }: { query: Record<string, unknown> }) =>runActorsQuery(query, ['actor', 'event_count'], ['event_count DESC', 'actor_id DESC']),++ retentionActors: async ({ query }: { query: Record<string, unknown> }) => {+ // Columns are `person` + one per return interval: prefix = period (day/week/…), count =+ // custom-bracket count + 1, else totalIntervals. Mirrors the frontend retentionToActorsQuery.+ const filter = ((query.source as Record<string, unknown>)?.retentionFilter ?? {}) as Record<+ string,+ unknown+ >+ const period = typeof filter.period === 'string' ? filter.period.toLowerCase() : 'day'+ const brackets = filter.retentionCustomBrackets as number[] | undefined+ const count = brackets?.length ? brackets.length + 1 : (filter.totalIntervals as number) || 7+ // The schema codegen doesn't propagate `@minimum`/`@maximum` on integer fields (only array+ // `@maxItems`, which already bounds `retentionCustomBrackets`), so `totalIntervals` can't be+ // capped in the generated zod — enforce it here instead. The limit matches the app's+ // retention UI (period count capped at 31; totalIntervals adds the acquisition interval → 32).+ // TODO: drop this guard once the schema generator supports integer min/max.+ const MAX_RETENTION_INTERVALS = 32+ if (count > MAX_RETENTION_INTERVALS) {+ throw new Error(+ `Retention query requests ${count} intervals; the maximum is ${MAX_RETENTION_INTERVALS}.`+ )+ }++ const select = ['person', ...Array.from({ length: count }, (_, i) => `${period}_${i}`)]+ return runActorsQuery(query, select, ['length(appearances) DESC', 'actor_id'])+ },}}diff --git a/services/mcp/src/tools/generated/query-wrappers.ts b/services/mcp/src/tools/generated/query-wrappers.tsindex 2c9b1f1d3b50..f40b1a424c7a 100644--- a/services/mcp/src/tools/generated/query-wrappers.ts+++ b/services/mcp/src/tools/generated/query-wrappers.ts@@ -832,6 +832,7 @@ const AssistantRetentionFilter = z.object({period: RetentionPeriod.describe('Retention period, the interval to track cohorts by.').default('Day').optional(),retentionCustomBrackets: z.array(z.coerce.number())+ .max(31).describe('Custom brackets for retention calculations.').optional(),retentionReference: z@@ -1246,6 +1247,16 @@ const AssistantPathsActorsQuery = z.object({source: AssistantPathsQuery.describe('The source paths insight query whose actors we are listing.'),})+const AssistantRetentionActorsQuery = z.object({+ interval: integer+ .describe(+ 'Which acquisition cohort to drill into, 0-based. `0` is the acquisition interval itself (every actor who entered the cohort); `1` is the cohort that entered one interval later, and so on. Defaults to `0` when omitted.'+ )+ .optional(),+ kind: z.literal('InsightActorsQuery').default('InsightActorsQuery'),+ source: AssistantRetentionQuery.describe('The source retention insight query whose cohort we are drilling into.'),+})+const QueryTrendsSchema = AssistantTrendsQuery.extend({output_format: z.enum(['optimized', 'json'])@@ -1336,6 +1347,16 @@ const QueryPathsActorsSchema = AssistantPathsActorsQuery.extend({),})+const QueryRetentionActorsSchema = AssistantRetentionActorsQuery.extend({+ output_format: z+ .enum(['optimized', 'json'])+ .default('optimized')+ .optional()+ .describe(+ 'Output format. "optimized" returns a human-readable summary from server-side formatters (recommended for analysis). "json" returns the raw query results as JSON.'+ ),+})+// --- Tool registrations ---export const GENERATED_TOOLS: Record<string, ReturnType<typeof createQueryWrapper<ZodObjectAny>>> = {@@ -1414,4 +1435,11 @@ export const GENERATED_TOOLS: Record<string, ReturnType<typeof createQueryWrappeuiResourceUri: 'ui://posthog/insight-actors.html',outputFormat: 'optimized',}),+ 'query-retention-actors': createQueryWrapper({+ name: 'query-retention-actors',+ schema: QueryRetentionActorsSchema,+ kind: 'InsightActorsQuery',+ uiResourceUri: 'ui://posthog/insight-actors.html',+ outputFormat: 'optimized',+ }),}diff --git a/services/mcp/src/tools/query-wrapper-factory.ts b/services/mcp/src/tools/query-wrapper-factory.tsindex ac8ddad81fac..c05c740b049b 100644--- a/services/mcp/src/tools/query-wrapper-factory.ts+++ b/services/mcp/src/tools/query-wrapper-factory.ts@@ -66,6 +66,9 @@ export function createQueryWrapper<T extends ZodObjectAny>(config: QueryWrapperCcase 'PathsQuery':data = await queryClient.pathsActors({ query })break+ case 'RetentionQuery':+ data = await queryClient.retentionActors({ query })+ breakdefault:throw new Error(`Unsupported source kind for actors query: ${sourceKind}`)}diff --git a/services/mcp/tests/tools/query-wrappers.integration.test.ts b/services/mcp/tests/tools/query-wrappers.integration.test.tsindex 88641fecb589..68b91b50320a 100644--- a/services/mcp/tests/tools/query-wrappers.integration.test.ts+++ b/services/mcp/tests/tools/query-wrappers.integration.test.ts@@ -529,4 +529,93 @@ describe('Query Wrapper Integration Tests', { concurrent: false }, () => {expect(sourcePathsFilter.endPoint).toBe('https://us.posthog.com/')})})++ describe('query-retention-actors', () => {+ const pageview = { id: '$pageview', name: 'Pageview', type: 'events' }+ const retentionSource = {+ kind: 'RetentionQuery',+ retentionFilter: {+ period: 'Day',+ totalIntervals: 8,+ targetEntity: pageview,+ returningEntity: pageview,+ retentionType: 'retention_first_time',+ },+ dateRange: { date_from: '-30d' },+ }++ it('returns a flat {columns, rows} table with the actors projection', async () => {+ const tool = getToolByName(GENERATED_TOOLS, 'query-retention-actors')+ const result = (await tool.handler(context, { source: retentionSource, interval: 0 })) as any++ expect(result).toHaveProperty('query')+ expect(result).toHaveProperty('hasMore')+ expect(result).toHaveProperty('offset')+ expect(result).toHaveProperty('results')+ expect(Array.isArray(result.results.results)).toBe(true)+ })++ it('wraps the source in an outer ActorsQuery with the person + per-interval projection', async () => {+ const tool = getToolByName(GENERATED_TOOLS, 'query-retention-actors')+ const result = (await tool.handler(context, { source: retentionSource, interval: 1 })) as any++ expect(result.query.kind).toBe('ActorsQuery')+ expect(result.query.select).toEqual([+ 'person',+ 'day_0',+ 'day_1',+ 'day_2',+ 'day_3',+ 'day_4',+ 'day_5',+ 'day_6',+ 'day_7',+ ])+ expect(result.query.orderBy).toEqual(['length(appearances) DESC', 'actor_id'])+ expect(result.query.source.kind).toBe('InsightActorsQuery')+ expect(result.query.source.interval).toBe(1)+ expect(result.query.source.source.kind).toBe('RetentionQuery')+ expect(result.results.columns).toEqual([+ 'distinct_id',+ 'email',+ 'name',+ 'day_0',+ 'day_1',+ 'day_2',+ 'day_3',+ 'day_4',+ 'day_5',+ 'day_6',+ 'day_7',+ ])+ })++ it('derives the interval column count from custom brackets', async () => {+ const tool = getToolByName(GENERATED_TOOLS, 'query-retention-actors')+ const result = (await tool.handler(context, {+ source: {+ ...retentionSource,+ retentionFilter: { ...retentionSource.retentionFilter, retentionCustomBrackets: [1, 3, 5] },+ },+ interval: 0,+ })) as any++ // 3 custom brackets → 3 + 1 = 4 interval columns.+ expect(result.query.select).toEqual(['person', 'day_0', 'day_1', 'day_2', 'day_3'])+ expect(result.results.columns).toEqual(['distinct_id', 'email', 'name', 'day_0', 'day_1', 'day_2', 'day_3'])+ })++ it('rejects a totalIntervals above the supported maximum', async () => {+ const tool = getToolByName(GENERATED_TOOLS, 'query-retention-actors')+ await expect(+ tool.handler(context, {+ source: {+ ...retentionSource,+ retentionFilter: { ...retentionSource.retentionFilter, totalIntervals: 50 },+ },+ interval: 0,+ })+ ).rejects.toThrow(/maximum is 32/)+ })+ })})diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/query-retention-actors.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/query-retention-actors.jsonnew file mode 100644index 000000000000..264705d05423--- /dev/null+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/query-retention-actors.json@@ -0,0 +1,3087 @@+{+ "$schema": "https://json-schema.org/draft/2020-12/schema",+ "properties": {+ "interval": {+ "description": "Which acquisition cohort to drill into, 0-based. `0` is the acquisition interval itself (every actor who entered the cohort); `1` is the cohort that entered one interval later, and so on. Defaults to `0` when omitted.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ },+ "kind": {+ "const": "InsightActorsQuery",+ "default": "InsightActorsQuery",+ "type": "string"+ },+ "output_format": {+ "default": "optimized",+ "description": "Output format. \"optimized\" returns a human-readable summary from server-side formatters (recommended for analysis). \"json\" returns the raw query results as JSON.",+ "enum": ["optimized", "json"],+ "type": "string"+ },+ "source": {+ "description": "The source retention insight query whose cohort we are drilling into.",+ "properties": {+ "aggregation_group_type_index": {+ "anyOf": [+ {+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ },+ {+ "type": "null"+ }+ ],+ "description": "Groups aggregation"+ },+ "dateRange": {+ "anyOf": [+ {+ "properties": {+ "date_from": {+ "description": "ISO8601 date string.",+ "type": "string"+ },+ "date_to": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "description": "ISO8601 date string."+ }+ },+ "required": ["date_from"],+ "type": "object"+ },+ {+ "properties": {+ "date_from": {+ "description": "Duration in the past. Supported units are: `h` (hour), `d` (day), `w` (week), `m` (month), `y` (year), `all` (all time). Use the `Start` suffix to define the exact left date boundary. Examples: `-1d` last day from now, `-180d` last 180 days from now, `mStart` this month start, `-1dStart` yesterday's start.",+ "type": "string"+ }+ },+ "required": ["date_from"],+ "type": "object"+ }+ ],+ "description": "Date range for the query"+ },+ "filterTestAccounts": {+ "default": false,+ "description": "Exclude internal and test users by applying the respective filters",+ "type": "boolean"+ },+ "kind": {+ "const": "RetentionQuery",+ "default": "RetentionQuery",+ "type": "string"+ },+ "properties": {+ "default": [],+ "description": "Property filters for all series",+ "items": {+ "anyOf": [+ {+ "anyOf": [+ {+ "properties": {+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "description": "`icontains` - case insensitive contains. `not_icontains` - case insensitive does not contain. `regex` - matches the regex pattern. `not_regex` - does not match the regex pattern.",+ "enum": [+ "exact",+ "is_not",+ "icontains",+ "not_icontains",+ "regex",+ "not_regex"+ ],+ "type": "string"+ },+ "type": {+ "enum": ["event", "person", "session", "feature"],+ "type": "string"+ },+ "value": {+ "description": "Only use property values from the plan. If the operator is `regex` or `not_regex`, the value must be a valid ClickHouse regex pattern to match against. Otherwise, the value must be a substring that will be matched against the property value. Use the string values `true` or `false` for boolean properties.",+ "type": "string"+ }+ },+ "required": ["key", "operator", "type", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "enum": ["exact", "gt", "lt"],+ "type": "string"+ },+ "type": {+ "enum": ["event", "person", "session", "feature"],+ "type": "string"+ },+ "value": {+ "type": "number"+ }+ },+ "required": ["key", "operator", "type", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "description": "`exact` - exact match of any of the values. `is_not` - does not match any of the values.",+ "enum": ["exact", "is_not"],+ "type": "string"+ },+ "type": {+ "enum": ["event", "person", "session", "feature"],+ "type": "string"+ },+ "value": {+ "description": "Only use property values from the plan. Always use strings as values. If you have a number, convert it to a string first. If you have a boolean, convert it to a string \"true\" or \"false\".",+ "items": {+ "type": "string"+ },+ "type": "array"+ }+ },+ "required": ["key", "operator", "type", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "enum": ["is_date_exact", "is_date_before", "is_date_after"],+ "type": "string"+ },+ "type": {+ "enum": ["event", "person", "session", "feature"],+ "type": "string"+ },+ "value": {+ "description": "Value must be a date in ISO 8601 format.",+ "type": "string"+ }+ },+ "required": ["key", "operator", "type", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "description": "`is_set` - the property has any value. `is_not_set` - the property doesn't have a value or wasn't collected.",+ "enum": ["is_set", "is_not_set"],+ "type": "string"+ },+ "type": {+ "enum": ["event", "person", "session", "feature"],+ "type": "string"+ }+ },+ "required": ["key", "operator", "type"],+ "type": "object"+ }+ ]+ },+ {+ "anyOf": [+ {+ "properties": {+ "group_type_index": {+ "description": "Index of the group type from the group mapping.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ },+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "description": "`icontains` - case insensitive contains. `not_icontains` - case insensitive does not contain. `regex` - matches the regex pattern. `not_regex` - does not match the regex pattern.",+ "enum": [+ "exact",+ "is_not",+ "icontains",+ "not_icontains",+ "regex",+ "not_regex"+ ],+ "type": "string"+ },+ "type": {+ "const": "group",+ "default": "group",+ "type": "string"+ },+ "value": {+ "description": "Only use property values from the plan. If the operator is `regex` or `not_regex`, the value must be a valid ClickHouse regex pattern to match against. Otherwise, the value must be a substring that will be matched against the property value. Use the string values `true` or `false` for boolean properties.",+ "type": "string"+ }+ },+ "required": ["group_type_index", "key", "operator", "value"],+ "type": "object"+ },+ {+ "properties": {+ "group_type_index": {+ "description": "Index of the group type from the group mapping.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ },+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "enum": ["exact", "gt", "lt"],+ "type": "string"+ },+ "type": {+ "const": "group",+ "default": "group",+ "type": "string"+ },+ "value": {+ "type": "number"+ }+ },+ "required": ["group_type_index", "key", "operator", "value"],+ "type": "object"+ },+ {+ "properties": {+ "group_type_index": {+ "description": "Index of the group type from the group mapping.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ },+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "description": "`exact` - exact match of any of the values. `is_not` - does not match any of the values.",+ "enum": ["exact", "is_not"],+ "type": "string"+ },+ "type": {+ "const": "group",+ "default": "group",+ "type": "string"+ },+ "value": {+ "description": "Only use property values from the plan. Always use strings as values. If you have a number, convert it to a string first. If you have a boolean, convert it to a string \"true\" or \"false\".",+ "items": {+ "type": "string"+ },+ "type": "array"+ }+ },+ "required": ["group_type_index", "key", "operator", "value"],+ "type": "object"+ },+ {+ "properties": {+ "group_type_index": {+ "description": "Index of the group type from the group mapping.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ },+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "enum": ["is_date_exact", "is_date_before", "is_date_after"],+ "type": "string"+ },+ "type": {+ "const": "group",+ "default": "group",+ "type": "string"+ },+ "value": {+ "description": "Value must be a date in ISO 8601 format.",+ "type": "string"+ }+ },+ "required": ["group_type_index", "key", "operator", "value"],+ "type": "object"+ },+ {+ "properties": {+ "group_type_index": {+ "description": "Index of the group type from the group mapping.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ },+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "description": "`is_set` - the property has any value. `is_not_set` - the property doesn't have a value or wasn't collected.",+ "enum": ["is_set", "is_not_set"],+ "type": "string"+ },+ "type": {+ "const": "group",+ "default": "group",+ "type": "string"+ }+ },+ "required": ["group_type_index", "key", "operator"],+ "type": "object"+ }+ ]+ },+ {+ "properties": {+ "key": {+ "const": "id",+ "default": "id",+ "type": "string"+ },+ "operator": {+ "default": "in",+ "enum": ["in", "not_in"],+ "type": "string"+ },+ "type": {+ "const": "cohort",+ "default": "cohort",+ "description": "Filter events by cohort membership. Use this to narrow down results to persons belonging to a specific cohort. Use `operator: \"in\"` to include cohort members, or `operator: \"not_in\"` to exclude them. Examples:\n- Include: `{ type: \"cohort\", key: \"id\", value: 42, operator: \"in\" }`\n- Exclude: `{ type: \"cohort\", key: \"id\", value: 42, operator: \"not_in\" }`",+ "type": "string"+ },+ "value": {+ "description": "The cohort ID to filter by.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ }+ },+ "required": ["value"],+ "type": "object"+ },+ {+ "anyOf": [+ {+ "properties": {+ "key": {+ "description": "The element property to filter on. `tag_name` — HTML tag (e.g., `button`, `a`, `input`). `text` — visible text content of the element. `href` — the `href` attribute for links. `selector` — a CSS selector matching the element (e.g., `div.main > button.cta`).",+ "enum": ["tag_name", "text", "href", "selector"],+ "type": "string"+ },+ "operator": {+ "description": "`icontains` - case insensitive contains. `not_icontains` - case insensitive does not contain. `regex` - matches the regex pattern. `not_regex` - does not match the regex pattern.",+ "enum": [+ "exact",+ "is_not",+ "icontains",+ "not_icontains",+ "regex",+ "not_regex"+ ],+ "type": "string"+ },+ "type": {+ "const": "element",+ "default": "element",+ "description": "Filter by autocaptured HTML element properties (`$autocapture`, `$rageclick`). Example: `{ type: \"element\", key: \"text\", value: \"Sign Up\", operator: \"exact\" }`",+ "type": "string"+ },+ "value": {+ "description": "Only use property values from the plan. If the operator is `regex` or `not_regex`, the value must be a valid ClickHouse regex pattern to match against. Otherwise, the value must be a substring that will be matched against the property value. Use the string values `true` or `false` for boolean properties.",+ "type": "string"+ }+ },+ "required": ["key", "operator", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "The element property to filter on. `tag_name` — HTML tag (e.g., `button`, `a`, `input`). `text` — visible text content of the element. `href` — the `href` attribute for links. `selector` — a CSS selector matching the element (e.g., `div.main > button.cta`).",+ "enum": ["tag_name", "text", "href", "selector"],+ "type": "string"+ },+ "operator": {+ "enum": ["exact", "gt", "lt"],+ "type": "string"+ },+ "type": {+ "const": "element",+ "default": "element",+ "description": "Filter by autocaptured HTML element properties (`$autocapture`, `$rageclick`). Example: `{ type: \"element\", key: \"text\", value: \"Sign Up\", operator: \"exact\" }`",+ "type": "string"+ },+ "value": {+ "type": "number"+ }+ },+ "required": ["key", "operator", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "The element property to filter on. `tag_name` — HTML tag (e.g., `button`, `a`, `input`). `text` — visible text content of the element. `href` — the `href` attribute for links. `selector` — a CSS selector matching the element (e.g., `div.main > button.cta`).",+ "enum": ["tag_name", "text", "href", "selector"],+ "type": "string"+ },+ "operator": {+ "description": "`exact` - exact match of any of the values. `is_not` - does not match any of the values.",+ "enum": ["exact", "is_not"],+ "type": "string"+ },+ "type": {+ "const": "element",+ "default": "element",+ "description": "Filter by autocaptured HTML element properties (`$autocapture`, `$rageclick`). Example: `{ type: \"element\", key: \"text\", value: \"Sign Up\", operator: \"exact\" }`",+ "type": "string"+ },+ "value": {+ "description": "Only use property values from the plan. Always use strings as values. If you have a number, convert it to a string first. If you have a boolean, convert it to a string \"true\" or \"false\".",+ "items": {+ "type": "string"+ },+ "type": "array"+ }+ },+ "required": ["key", "operator", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "The element property to filter on. `tag_name` — HTML tag (e.g., `button`, `a`, `input`). `text` — visible text content of the element. `href` — the `href` attribute for links. `selector` — a CSS selector matching the element (e.g., `div.main > button.cta`).",+ "enum": ["tag_name", "text", "href", "selector"],+ "type": "string"+ },+ "operator": {+ "enum": ["is_date_exact", "is_date_before", "is_date_after"],+ "type": "string"+ },+ "type": {+ "const": "element",+ "default": "element",+ "description": "Filter by autocaptured HTML element properties (`$autocapture`, `$rageclick`). Example: `{ type: \"element\", key: \"text\", value: \"Sign Up\", operator: \"exact\" }`",+ "type": "string"+ },+ "value": {+ "description": "Value must be a date in ISO 8601 format.",+ "type": "string"+ }+ },+ "required": ["key", "operator", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "The element property to filter on. `tag_name` — HTML tag (e.g., `button`, `a`, `input`). `text` — visible text content of the element. `href` — the `href` attribute for links. `selector` — a CSS selector matching the element (e.g., `div.main > button.cta`).",+ "enum": ["tag_name", "text", "href", "selector"],+ "type": "string"+ },+ "operator": {+ "description": "`is_set` - the property has any value. `is_not_set` - the property doesn't have a value or wasn't collected.",+ "enum": ["is_set", "is_not_set"],+ "type": "string"+ },+ "type": {+ "const": "element",+ "default": "element",+ "description": "Filter by autocaptured HTML element properties (`$autocapture`, `$rageclick`). Example: `{ type: \"element\", key: \"text\", value: \"Sign Up\", operator: \"exact\" }`",+ "type": "string"+ }+ },+ "required": ["key", "operator"],+ "type": "object"+ }+ ]+ },+ {+ "properties": {+ "key": {+ "description": "A HogQL boolean expression used as a filter condition.\n\nExamples:\n- Filter where a property exceeds a threshold: `toFloat(properties.load_time) > 5.0`\n- Filter with string matching: `properties.$current_url LIKE '%/pricing%'`\n- Filter with multiple conditions: `properties.$browser = 'Chrome' AND toFloat(properties.duration) > 30`",+ "type": "string"+ },+ "type": {+ "const": "hogql",+ "default": "hogql",+ "description": "Filter by a HogQL boolean expression for advanced filtering that can't be expressed with standard property filters.",+ "type": "string"+ }+ },+ "required": ["key"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "The feature flag key.",+ "type": "string"+ },+ "operator": {+ "const": "flag_evaluates_to",+ "default": "flag_evaluates_to",+ "type": "string"+ },+ "type": {+ "const": "flag",+ "default": "flag",+ "description": "Filter events by feature flag state — only include events where a specific flag evaluated to a given value. Examples:\n- Flag enabled: `{ type: \"flag\", key: \"new-onboarding\", operator: \"flag_evaluates_to\", value: true }`\n- Specific variant: `{ type: \"flag\", key: \"checkout-experiment\", operator: \"flag_evaluates_to\", value: \"variant-a\" }`",+ "type": "string"+ },+ "value": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "string"+ }+ ],+ "description": "`true`/`false` for boolean flags, or a variant name string for multivariate flags."+ }+ },+ "required": ["key", "value"],+ "type": "object"+ }+ ]+ },+ "type": "array"+ },+ "retentionFilter": {+ "description": "Properties specific to the retention insight",+ "properties": {+ "aggregationProperty": {+ "description": "The event or person property to aggregate when aggregationType is sum or avg.",+ "type": "string"+ },+ "aggregationPropertyType": {+ "default": "event",+ "description": "The type of property to aggregate on (event or person). Defaults to event.",+ "enum": ["event", "person", "data_warehouse"],+ "type": "string"+ },+ "aggregationType": {+ "default": "count",+ "description": "The aggregation type to use for retention.",+ "enum": ["count", "sum", "avg"],+ "type": "string"+ },+ "cumulative": {+ "description": "Whether retention should be rolling (aka unbounded, cumulative). Rolling retention means that a user coming back in period 5 makes them count towards all the previous periods.",+ "type": "boolean"+ },+ "meanRetentionCalculation": {+ "description": "Whether an additional series should be shown, showing the mean conversion for each period across cohorts.",+ "enum": ["simple", "weighted", "none"],+ "type": "string"+ },+ "minimumOccurrences": {+ "description": "Minimum number of times an event must occur to count towards retention.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ },+ "period": {+ "default": "Day",+ "description": "Retention period, the interval to track cohorts by.",+ "enum": ["Hour", "Day", "Week", "Month"],+ "type": "string"+ },+ "retentionCustomBrackets": {+ "description": "Custom brackets for retention calculations.",+ "items": {+ "type": "number"+ },+ "maxItems": 31,+ "type": "array"+ },+ "retentionReference": {+ "description": "Whether retention is with regard to initial cohort size, or that of the previous period.",+ "enum": ["total", "previous"],+ "type": "string"+ },+ "retentionType": {+ "description": "Retention type: recurring or first time. Recurring retention counts a user as part of a cohort if they performed the cohort event during that time period, irrespective of it was their first time or not. First time retention only counts a user as part of the cohort if it was their first time performing the cohort event.",+ "enum": ["retention_recurring", "retention_first_time", "retention_first_ever_occurrence"],+ "type": "string"+ },+ "returningEntity": {+ "anyOf": [+ {+ "properties": {+ "custom_name": {+ "description": "Custom name for the event if it is needed to be renamed.",+ "type": "string"+ },+ "id": {+ "description": "The event name from the plan as a string. This is the field the retention query engine uses to match events, so it must be populated exactly as the event appears in the plan. For actions use `AssistantRetentionActionsNode` instead, where `id` is the numeric action ID.",+ "type": "string"+ },+ "name": {+ "description": "Optional human-readable label for the event, used for display only. Defaults to `id` if omitted and is never used for event matching.",+ "type": "string"+ },+ "properties": {+ "description": "Property filters for the event.",+ "items": {+ "anyOf": [+ {+ "anyOf": [+ {+ "properties": {+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "description": "`icontains` - case insensitive contains. `not_icontains` - case insensitive does not contain. `regex` - matches the regex pattern. `not_regex` - does not match the regex pattern.",+ "enum": [+ "exact",+ "is_not",+ "icontains",+ "not_icontains",+ "regex",+ "not_regex"+ ],+ "type": "string"+ },+ "type": {+ "enum": [+ "event",+ "person",+ "session",+ "feature"+ ],+ "type": "string"+ },+ "value": {+ "description": "Only use property values from the plan. If the operator is `regex` or `not_regex`, the value must be a valid ClickHouse regex pattern to match against. Otherwise, the value must be a substring that will be matched against the property value. Use the string values `true` or `false` for boolean properties.",+ "type": "string"+ }+ },+ "required": ["key", "operator", "type", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "enum": ["exact", "gt", "lt"],+ "type": "string"+ },+ "type": {+ "enum": [+ "event",+ "person",+ "session",+ "feature"+ ],+ "type": "string"+ },+ "value": {+ "type": "number"+ }+ },+ "required": ["key", "operator", "type", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "description": "`exact` - exact match of any of the values. `is_not` - does not match any of the values.",+ "enum": ["exact", "is_not"],+ "type": "string"+ },+ "type": {+ "enum": [+ "event",+ "person",+ "session",+ "feature"+ ],+ "type": "string"+ },+ "value": {+ "description": "Only use property values from the plan. Always use strings as values. If you have a number, convert it to a string first. If you have a boolean, convert it to a string \"true\" or \"false\".",+ "items": {+ "type": "string"+ },+ "type": "array"+ }+ },+ "required": ["key", "operator", "type", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "enum": [+ "is_date_exact",+ "is_date_before",+ "is_date_after"+ ],+ "type": "string"+ },+ "type": {+ "enum": [+ "event",+ "person",+ "session",+ "feature"+ ],+ "type": "string"+ },+ "value": {+ "description": "Value must be a date in ISO 8601 format.",+ "type": "string"+ }+ },+ "required": ["key", "operator", "type", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "description": "`is_set` - the property has any value. `is_not_set` - the property doesn't have a value or wasn't collected.",+ "enum": ["is_set", "is_not_set"],+ "type": "string"+ },+ "type": {+ "enum": [+ "event",+ "person",+ "session",+ "feature"+ ],+ "type": "string"+ }+ },+ "required": ["key", "operator", "type"],+ "type": "object"+ }+ ]+ },+ {+ "anyOf": [+ {+ "properties": {+ "group_type_index": {+ "description": "Index of the group type from the group mapping.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ },+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "description": "`icontains` - case insensitive contains. `not_icontains` - case insensitive does not contain. `regex` - matches the regex pattern. `not_regex` - does not match the regex pattern.",+ "enum": [+ "exact",+ "is_not",+ "icontains",+ "not_icontains",+ "regex",+ "not_regex"+ ],+ "type": "string"+ },+ "type": {+ "const": "group",+ "default": "group",+ "type": "string"+ },+ "value": {+ "description": "Only use property values from the plan. If the operator is `regex` or `not_regex`, the value must be a valid ClickHouse regex pattern to match against. Otherwise, the value must be a substring that will be matched against the property value. Use the string values `true` or `false` for boolean properties.",+ "type": "string"+ }+ },+ "required": [+ "group_type_index",+ "key",+ "operator",+ "value"+ ],+ "type": "object"+ },+ {+ "properties": {+ "group_type_index": {+ "description": "Index of the group type from the group mapping.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ },+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "enum": ["exact", "gt", "lt"],+ "type": "string"+ },+ "type": {+ "const": "group",+ "default": "group",+ "type": "string"+ },+ "value": {+ "type": "number"+ }+ },+ "required": [+ "group_type_index",+ "key",+ "operator",+ "value"+ ],+ "type": "object"+ },+ {+ "properties": {+ "group_type_index": {+ "description": "Index of the group type from the group mapping.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ },+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "description": "`exact` - exact match of any of the values. `is_not` - does not match any of the values.",+ "enum": ["exact", "is_not"],+ "type": "string"+ },+ "type": {+ "const": "group",+ "default": "group",+ "type": "string"+ },+ "value": {+ "description": "Only use property values from the plan. Always use strings as values. If you have a number, convert it to a string first. If you have a boolean, convert it to a string \"true\" or \"false\".",+ "items": {+ "type": "string"+ },+ "type": "array"+ }+ },+ "required": [+ "group_type_index",+ "key",+ "operator",+ "value"+ ],+ "type": "object"+ },+ {+ "properties": {+ "group_type_index": {+ "description": "Index of the group type from the group mapping.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ },+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "enum": [+ "is_date_exact",+ "is_date_before",+ "is_date_after"+ ],+ "type": "string"+ },+ "type": {+ "const": "group",+ "default": "group",+ "type": "string"+ },+ "value": {+ "description": "Value must be a date in ISO 8601 format.",+ "type": "string"+ }+ },+ "required": [+ "group_type_index",+ "key",+ "operator",+ "value"+ ],+ "type": "object"+ },+ {+ "properties": {+ "group_type_index": {+ "description": "Index of the group type from the group mapping.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ },+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "description": "`is_set` - the property has any value. `is_not_set` - the property doesn't have a value or wasn't collected.",+ "enum": ["is_set", "is_not_set"],+ "type": "string"+ },+ "type": {+ "const": "group",+ "default": "group",+ "type": "string"+ }+ },+ "required": ["group_type_index", "key", "operator"],+ "type": "object"+ }+ ]+ },+ {+ "properties": {+ "key": {+ "const": "id",+ "default": "id",+ "type": "string"+ },+ "operator": {+ "default": "in",+ "enum": ["in", "not_in"],+ "type": "string"+ },+ "type": {+ "const": "cohort",+ "default": "cohort",+ "description": "Filter events by cohort membership. Use this to narrow down results to persons belonging to a specific cohort. Use `operator: \"in\"` to include cohort members, or `operator: \"not_in\"` to exclude them. Examples:\n- Include: `{ type: \"cohort\", key: \"id\", value: 42, operator: \"in\" }`\n- Exclude: `{ type: \"cohort\", key: \"id\", value: 42, operator: \"not_in\" }`",+ "type": "string"+ },+ "value": {+ "description": "The cohort ID to filter by.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ }+ },+ "required": ["value"],+ "type": "object"+ },+ {+ "anyOf": [+ {+ "properties": {+ "key": {+ "description": "The element property to filter on. `tag_name` — HTML tag (e.g., `button`, `a`, `input`). `text` — visible text content of the element. `href` — the `href` attribute for links. `selector` — a CSS selector matching the element (e.g., `div.main > button.cta`).",+ "enum": [+ "tag_name",+ "text",+ "href",+ "selector"+ ],+ "type": "string"+ },+ "operator": {+ "description": "`icontains` - case insensitive contains. `not_icontains` - case insensitive does not contain. `regex` - matches the regex pattern. `not_regex` - does not match the regex pattern.",+ "enum": [+ "exact",+ "is_not",+ "icontains",+ "not_icontains",+ "regex",+ "not_regex"+ ],+ "type": "string"+ },+ "type": {+ "const": "element",+ "default": "element",+ "description": "Filter by autocaptured HTML element properties (`$autocapture`, `$rageclick`). Example: `{ type: \"element\", key: \"text\", value: \"Sign Up\", operator: \"exact\" }`",+ "type": "string"+ },+ "value": {+ "description": "Only use property values from the plan. If the operator is `regex` or `not_regex`, the value must be a valid ClickHouse regex pattern to match against. Otherwise, the value must be a substring that will be matched against the property value. Use the string values `true` or `false` for boolean properties.",+ "type": "string"+ }+ },+ "required": ["key", "operator", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "The element property to filter on. `tag_name` — HTML tag (e.g., `button`, `a`, `input`). `text` — visible text content of the element. `href` — the `href` attribute for links. `selector` — a CSS selector matching the element (e.g., `div.main > button.cta`).",+ "enum": [+ "tag_name",+ "text",+ "href",+ "selector"+ ],+ "type": "string"+ },+ "operator": {+ "enum": ["exact", "gt", "lt"],+ "type": "string"+ },+ "type": {+ "const": "element",+ "default": "element",+ "description": "Filter by autocaptured HTML element properties (`$autocapture`, `$rageclick`). Example: `{ type: \"element\", key: \"text\", value: \"Sign Up\", operator: \"exact\" }`",+ "type": "string"+ },+ "value": {+ "type": "number"+ }+ },+ "required": ["key", "operator", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "The element property to filter on. `tag_name` — HTML tag (e.g., `button`, `a`, `input`). `text` — visible text content of the element. `href` — the `href` attribute for links. `selector` — a CSS selector matching the element (e.g., `div.main > button.cta`).",+ "enum": [+ "tag_name",+ "text",+ "href",+ "selector"+ ],+ "type": "string"+ },+ "operator": {+ "description": "`exact` - exact match of any of the values. `is_not` - does not match any of the values.",+ "enum": ["exact", "is_not"],+ "type": "string"+ },+ "type": {+ "const": "element",+ "default": "element",+ "description": "Filter by autocaptured HTML element properties (`$autocapture`, `$rageclick`). Example: `{ type: \"element\", key: \"text\", value: \"Sign Up\", operator: \"exact\" }`",+ "type": "string"+ },+ "value": {+ "description": "Only use property values from the plan. Always use strings as values. If you have a number, convert it to a string first. If you have a boolean, convert it to a string \"true\" or \"false\".",+ "items": {+ "type": "string"+ },+ "type": "array"+ }+ },+ "required": ["key", "operator", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "The element property to filter on. `tag_name` — HTML tag (e.g., `button`, `a`, `input`). `text` — visible text content of the element. `href` — the `href` attribute for links. `selector` — a CSS selector matching the element (e.g., `div.main > button.cta`).",+ "enum": [+ "tag_name",+ "text",+ "href",+ "selector"+ ],+ "type": "string"+ },+ "operator": {+ "enum": [+ "is_date_exact",+ "is_date_before",+ "is_date_after"+ ],+ "type": "string"+ },+ "type": {+ "const": "element",+ "default": "element",+ "description": "Filter by autocaptured HTML element properties (`$autocapture`, `$rageclick`). Example: `{ type: \"element\", key: \"text\", value: \"Sign Up\", operator: \"exact\" }`",+ "type": "string"+ },+ "value": {+ "description": "Value must be a date in ISO 8601 format.",+ "type": "string"+ }+ },+ "required": ["key", "operator", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "The element property to filter on. `tag_name` — HTML tag (e.g., `button`, `a`, `input`). `text` — visible text content of the element. `href` — the `href` attribute for links. `selector` — a CSS selector matching the element (e.g., `div.main > button.cta`).",+ "enum": [+ "tag_name",+ "text",+ "href",+ "selector"+ ],+ "type": "string"+ },+ "operator": {+ "description": "`is_set` - the property has any value. `is_not_set` - the property doesn't have a value or wasn't collected.",+ "enum": ["is_set", "is_not_set"],+ "type": "string"+ },+ "type": {+ "const": "element",+ "default": "element",+ "description": "Filter by autocaptured HTML element properties (`$autocapture`, `$rageclick`). Example: `{ type: \"element\", key: \"text\", value: \"Sign Up\", operator: \"exact\" }`",+ "type": "string"+ }+ },+ "required": ["key", "operator"],+ "type": "object"+ }+ ]+ },+ {+ "properties": {+ "key": {+ "description": "A HogQL boolean expression used as a filter condition.\n\nExamples:\n- Filter where a property exceeds a threshold: `toFloat(properties.load_time) > 5.0`\n- Filter with string matching: `properties.$current_url LIKE '%/pricing%'`\n- Filter with multiple conditions: `properties.$browser = 'Chrome' AND toFloat(properties.duration) > 30`",+ "type": "string"+ },+ "type": {+ "const": "hogql",+ "default": "hogql",+ "description": "Filter by a HogQL boolean expression for advanced filtering that can't be expressed with standard property filters.",+ "type": "string"+ }+ },+ "required": ["key"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "The feature flag key.",+ "type": "string"+ },+ "operator": {+ "const": "flag_evaluates_to",+ "default": "flag_evaluates_to",+ "type": "string"+ },+ "type": {+ "const": "flag",+ "default": "flag",+ "description": "Filter events by feature flag state — only include events where a specific flag evaluated to a given value. Examples:\n- Flag enabled: `{ type: \"flag\", key: \"new-onboarding\", operator: \"flag_evaluates_to\", value: true }`\n- Specific variant: `{ type: \"flag\", key: \"checkout-experiment\", operator: \"flag_evaluates_to\", value: \"variant-a\" }`",+ "type": "string"+ },+ "value": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "string"+ }+ ],+ "description": "`true`/`false` for boolean flags, or a variant name string for multivariate flags."+ }+ },+ "required": ["key", "value"],+ "type": "object"+ }+ ]+ },+ "type": "array"+ },+ "type": {+ "const": "events",+ "default": "events",+ "type": "string"+ }+ },+ "required": ["id"],+ "type": "object"+ },+ {+ "properties": {+ "id": {+ "description": "The numeric action ID from the plan. This is the field the retention query engine uses to look up the action definition. For events use `AssistantRetentionEventsNode` instead, where `id` is the event name string.",+ "type": "number"+ },+ "name": {+ "description": "Optional human-readable label for the action, used for display only. Defaults to the action's stored name if omitted and is never used for action matching.",+ "type": "string"+ },+ "properties": {+ "description": "Property filters for the action.",+ "items": {+ "anyOf": [+ {+ "anyOf": [+ {+ "properties": {+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "description": "`icontains` - case insensitive contains. `not_icontains` - case insensitive does not contain. `regex` - matches the regex pattern. `not_regex` - does not match the regex pattern.",+ "enum": [+ "exact",+ "is_not",+ "icontains",+ "not_icontains",+ "regex",+ "not_regex"+ ],+ "type": "string"+ },+ "type": {+ "enum": [+ "event",+ "person",+ "session",+ "feature"+ ],+ "type": "string"+ },+ "value": {+ "description": "Only use property values from the plan. If the operator is `regex` or `not_regex`, the value must be a valid ClickHouse regex pattern to match against. Otherwise, the value must be a substring that will be matched against the property value. Use the string values `true` or `false` for boolean properties.",+ "type": "string"+ }+ },+ "required": ["key", "operator", "type", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "enum": ["exact", "gt", "lt"],+ "type": "string"+ },+ "type": {+ "enum": [+ "event",+ "person",+ "session",+ "feature"+ ],+ "type": "string"+ },+ "value": {+ "type": "number"+ }+ },+ "required": ["key", "operator", "type", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "description": "`exact` - exact match of any of the values. `is_not` - does not match any of the values.",+ "enum": ["exact", "is_not"],+ "type": "string"+ },+ "type": {+ "enum": [+ "event",+ "person",+ "session",+ "feature"+ ],+ "type": "string"+ },+ "value": {+ "description": "Only use property values from the plan. Always use strings as values. If you have a number, convert it to a string first. If you have a boolean, convert it to a string \"true\" or \"false\".",+ "items": {+ "type": "string"+ },+ "type": "array"+ }+ },+ "required": ["key", "operator", "type", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "enum": [+ "is_date_exact",+ "is_date_before",+ "is_date_after"+ ],+ "type": "string"+ },+ "type": {+ "enum": [+ "event",+ "person",+ "session",+ "feature"+ ],+ "type": "string"+ },+ "value": {+ "description": "Value must be a date in ISO 8601 format.",+ "type": "string"+ }+ },+ "required": ["key", "operator", "type", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "description": "`is_set` - the property has any value. `is_not_set` - the property doesn't have a value or wasn't collected.",+ "enum": ["is_set", "is_not_set"],+ "type": "string"+ },+ "type": {+ "enum": [+ "event",+ "person",+ "session",+ "feature"+ ],+ "type": "string"+ }+ },+ "required": ["key", "operator", "type"],+ "type": "object"+ }+ ]+ },+ {+ "anyOf": [+ {+ "properties": {+ "group_type_index": {+ "description": "Index of the group type from the group mapping.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ },+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "description": "`icontains` - case insensitive contains. `not_icontains` - case insensitive does not contain. `regex` - matches the regex pattern. `not_regex` - does not match the regex pattern.",+ "enum": [+ "exact",+ "is_not",+ "icontains",+ "not_icontains",+ "regex",+ "not_regex"+ ],+ "type": "string"+ },+ "type": {+ "const": "group",+ "default": "group",+ "type": "string"+ },+ "value": {+ "description": "Only use property values from the plan. If the operator is `regex` or `not_regex`, the value must be a valid ClickHouse regex pattern to match against. Otherwise, the value must be a substring that will be matched against the property value. Use the string values `true` or `false` for boolean properties.",+ "type": "string"+ }+ },+ "required": [+ "group_type_index",+ "key",+ "operator",+ "value"+ ],+ "type": "object"+ },+ {+ "properties": {+ "group_type_index": {+ "description": "Index of the group type from the group mapping.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ },+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "enum": ["exact", "gt", "lt"],+ "type": "string"+ },+ "type": {+ "const": "group",+ "default": "group",+ "type": "string"+ },+ "value": {+ "type": "number"+ }+ },+ "required": [+ "group_type_index",+ "key",+ "operator",+ "value"+ ],+ "type": "object"+ },+ {+ "properties": {+ "group_type_index": {+ "description": "Index of the group type from the group mapping.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ },+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "description": "`exact` - exact match of any of the values. `is_not` - does not match any of the values.",+ "enum": ["exact", "is_not"],+ "type": "string"+ },+ "type": {+ "const": "group",+ "default": "group",+ "type": "string"+ },+ "value": {+ "description": "Only use property values from the plan. Always use strings as values. If you have a number, convert it to a string first. If you have a boolean, convert it to a string \"true\" or \"false\".",+ "items": {+ "type": "string"+ },+ "type": "array"+ }+ },+ "required": [+ "group_type_index",+ "key",+ "operator",+ "value"+ ],+ "type": "object"+ },+ {+ "properties": {+ "group_type_index": {+ "description": "Index of the group type from the group mapping.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ },+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "enum": [+ "is_date_exact",+ "is_date_before",+ "is_date_after"+ ],+ "type": "string"+ },+ "type": {+ "const": "group",+ "default": "group",+ "type": "string"+ },+ "value": {+ "description": "Value must be a date in ISO 8601 format.",+ "type": "string"+ }+ },+ "required": [+ "group_type_index",+ "key",+ "operator",+ "value"+ ],+ "type": "object"+ },+ {+ "properties": {+ "group_type_index": {+ "description": "Index of the group type from the group mapping.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ },+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "description": "`is_set` - the property has any value. `is_not_set` - the property doesn't have a value or wasn't collected.",+ "enum": ["is_set", "is_not_set"],+ "type": "string"+ },+ "type": {+ "const": "group",+ "default": "group",+ "type": "string"+ }+ },+ "required": ["group_type_index", "key", "operator"],+ "type": "object"+ }+ ]+ },+ {+ "properties": {+ "key": {+ "const": "id",+ "default": "id",+ "type": "string"+ },+ "operator": {+ "default": "in",+ "enum": ["in", "not_in"],+ "type": "string"+ },+ "type": {+ "const": "cohort",+ "default": "cohort",+ "description": "Filter events by cohort membership. Use this to narrow down results to persons belonging to a specific cohort. Use `operator: \"in\"` to include cohort members, or `operator: \"not_in\"` to exclude them. Examples:\n- Include: `{ type: \"cohort\", key: \"id\", value: 42, operator: \"in\" }`\n- Exclude: `{ type: \"cohort\", key: \"id\", value: 42, operator: \"not_in\" }`",+ "type": "string"+ },+ "value": {+ "description": "The cohort ID to filter by.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ }+ },+ "required": ["value"],+ "type": "object"+ },+ {+ "anyOf": [+ {+ "properties": {+ "key": {+ "description": "The element property to filter on. `tag_name` — HTML tag (e.g., `button`, `a`, `input`). `text` — visible text content of the element. `href` — the `href` attribute for links. `selector` — a CSS selector matching the element (e.g., `div.main > button.cta`).",+ "enum": [+ "tag_name",+ "text",+ "href",+ "selector"+ ],+ "type": "string"+ },+ "operator": {+ "description": "`icontains` - case insensitive contains. `not_icontains` - case insensitive does not contain. `regex` - matches the regex pattern. `not_regex` - does not match the regex pattern.",+ "enum": [+ "exact",+ "is_not",+ "icontains",+ "not_icontains",+ "regex",+ "not_regex"+ ],+ "type": "string"+ },+ "type": {+ "const": "element",+ "default": "element",+ "description": "Filter by autocaptured HTML element properties (`$autocapture`, `$rageclick`). Example: `{ type: \"element\", key: \"text\", value: \"Sign Up\", operator: \"exact\" }`",+ "type": "string"+ },+ "value": {+ "description": "Only use property values from the plan. If the operator is `regex` or `not_regex`, the value must be a valid ClickHouse regex pattern to match against. Otherwise, the value must be a substring that will be matched against the property value. Use the string values `true` or `false` for boolean properties.",+ "type": "string"+ }+ },+ "required": ["key", "operator", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "The element property to filter on. `tag_name` — HTML tag (e.g., `button`, `a`, `input`). `text` — visible text content of the element. `href` — the `href` attribute for links. `selector` — a CSS selector matching the element (e.g., `div.main > button.cta`).",+ "enum": [+ "tag_name",+ "text",+ "href",+ "selector"+ ],+ "type": "string"+ },+ "operator": {+ "enum": ["exact", "gt", "lt"],+ "type": "string"+ },+ "type": {+ "const": "element",+ "default": "element",+ "description": "Filter by autocaptured HTML element properties (`$autocapture`, `$rageclick`). Example: `{ type: \"element\", key: \"text\", value: \"Sign Up\", operator: \"exact\" }`",+ "type": "string"+ },+ "value": {+ "type": "number"+ }+ },+ "required": ["key", "operator", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "The element property to filter on. `tag_name` — HTML tag (e.g., `button`, `a`, `input`). `text` — visible text content of the element. `href` — the `href` attribute for links. `selector` — a CSS selector matching the element (e.g., `div.main > button.cta`).",+ "enum": [+ "tag_name",+ "text",+ "href",+ "selector"+ ],+ "type": "string"+ },+ "operator": {+ "description": "`exact` - exact match of any of the values. `is_not` - does not match any of the values.",+ "enum": ["exact", "is_not"],+ "type": "string"+ },+ "type": {+ "const": "element",+ "default": "element",+ "description": "Filter by autocaptured HTML element properties (`$autocapture`, `$rageclick`). Example: `{ type: \"element\", key: \"text\", value: \"Sign Up\", operator: \"exact\" }`",+ "type": "string"+ },+ "value": {+ "description": "Only use property values from the plan. Always use strings as values. If you have a number, convert it to a string first. If you have a boolean, convert it to a string \"true\" or \"false\".",+ "items": {+ "type": "string"+ },+ "type": "array"+ }+ },+ "required": ["key", "operator", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "The element property to filter on. `tag_name` — HTML tag (e.g., `button`, `a`, `input`). `text` — visible text content of the element. `href` — the `href` attribute for links. `selector` — a CSS selector matching the element (e.g., `div.main > button.cta`).",+ "enum": [+ "tag_name",+ "text",+ "href",+ "selector"+ ],+ "type": "string"+ },+ "operator": {+ "enum": [+ "is_date_exact",+ "is_date_before",+ "is_date_after"+ ],+ "type": "string"+ },+ "type": {+ "const": "element",+ "default": "element",+ "description": "Filter by autocaptured HTML element properties (`$autocapture`, `$rageclick`). Example: `{ type: \"element\", key: \"text\", value: \"Sign Up\", operator: \"exact\" }`",+ "type": "string"+ },+ "value": {+ "description": "Value must be a date in ISO 8601 format.",+ "type": "string"+ }+ },+ "required": ["key", "operator", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "The element property to filter on. `tag_name` — HTML tag (e.g., `button`, `a`, `input`). `text` — visible text content of the element. `href` — the `href` attribute for links. `selector` — a CSS selector matching the element (e.g., `div.main > button.cta`).",+ "enum": [+ "tag_name",+ "text",+ "href",+ "selector"+ ],+ "type": "string"+ },+ "operator": {+ "description": "`is_set` - the property has any value. `is_not_set` - the property doesn't have a value or wasn't collected.",+ "enum": ["is_set", "is_not_set"],+ "type": "string"+ },+ "type": {+ "const": "element",+ "default": "element",+ "description": "Filter by autocaptured HTML element properties (`$autocapture`, `$rageclick`). Example: `{ type: \"element\", key: \"text\", value: \"Sign Up\", operator: \"exact\" }`",+ "type": "string"+ }+ },+ "required": ["key", "operator"],+ "type": "object"+ }+ ]+ },+ {+ "properties": {+ "key": {+ "description": "A HogQL boolean expression used as a filter condition.\n\nExamples:\n- Filter where a property exceeds a threshold: `toFloat(properties.load_time) > 5.0`\n- Filter with string matching: `properties.$current_url LIKE '%/pricing%'`\n- Filter with multiple conditions: `properties.$browser = 'Chrome' AND toFloat(properties.duration) > 30`",+ "type": "string"+ },+ "type": {+ "const": "hogql",+ "default": "hogql",+ "description": "Filter by a HogQL boolean expression for advanced filtering that can't be expressed with standard property filters.",+ "type": "string"+ }+ },+ "required": ["key"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "The feature flag key.",+ "type": "string"+ },+ "operator": {+ "const": "flag_evaluates_to",+ "default": "flag_evaluates_to",+ "type": "string"+ },+ "type": {+ "const": "flag",+ "default": "flag",+ "description": "Filter events by feature flag state — only include events where a specific flag evaluated to a given value. Examples:\n- Flag enabled: `{ type: \"flag\", key: \"new-onboarding\", operator: \"flag_evaluates_to\", value: true }`\n- Specific variant: `{ type: \"flag\", key: \"checkout-experiment\", operator: \"flag_evaluates_to\", value: \"variant-a\" }`",+ "type": "string"+ },+ "value": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "string"+ }+ ],+ "description": "`true`/`false` for boolean flags, or a variant name string for multivariate flags."+ }+ },+ "required": ["key", "value"],+ "type": "object"+ }+ ]+ },+ "type": "array"+ },+ "type": {+ "const": "actions",+ "default": "actions",+ "type": "string"+ }+ },+ "required": ["id"],+ "type": "object"+ }+ ],+ "description": "Retention event (event marking the user coming back)."+ },+ "targetEntity": {+ "anyOf": [+ {+ "properties": {+ "custom_name": {+ "description": "Custom name for the event if it is needed to be renamed.",+ "type": "string"+ },+ "id": {+ "description": "The event name from the plan as a string. This is the field the retention query engine uses to match events, so it must be populated exactly as the event appears in the plan. For actions use `AssistantRetentionActionsNode` instead, where `id` is the numeric action ID.",+ "type": "string"+ },+ "name": {+ "description": "Optional human-readable label for the event, used for display only. Defaults to `id` if omitted and is never used for event matching.",+ "type": "string"+ },+ "properties": {+ "description": "Property filters for the event.",+ "items": {+ "anyOf": [+ {+ "anyOf": [+ {+ "properties": {+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "description": "`icontains` - case insensitive contains. `not_icontains` - case insensitive does not contain. `regex` - matches the regex pattern. `not_regex` - does not match the regex pattern.",+ "enum": [+ "exact",+ "is_not",+ "icontains",+ "not_icontains",+ "regex",+ "not_regex"+ ],+ "type": "string"+ },+ "type": {+ "enum": [+ "event",+ "person",+ "session",+ "feature"+ ],+ "type": "string"+ },+ "value": {+ "description": "Only use property values from the plan. If the operator is `regex` or `not_regex`, the value must be a valid ClickHouse regex pattern to match against. Otherwise, the value must be a substring that will be matched against the property value. Use the string values `true` or `false` for boolean properties.",+ "type": "string"+ }+ },+ "required": ["key", "operator", "type", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "enum": ["exact", "gt", "lt"],+ "type": "string"+ },+ "type": {+ "enum": [+ "event",+ "person",+ "session",+ "feature"+ ],+ "type": "string"+ },+ "value": {+ "type": "number"+ }+ },+ "required": ["key", "operator", "type", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "description": "`exact` - exact match of any of the values. `is_not` - does not match any of the values.",+ "enum": ["exact", "is_not"],+ "type": "string"+ },+ "type": {+ "enum": [+ "event",+ "person",+ "session",+ "feature"+ ],+ "type": "string"+ },+ "value": {+ "description": "Only use property values from the plan. Always use strings as values. If you have a number, convert it to a string first. If you have a boolean, convert it to a string \"true\" or \"false\".",+ "items": {+ "type": "string"+ },+ "type": "array"+ }+ },+ "required": ["key", "operator", "type", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "enum": [+ "is_date_exact",+ "is_date_before",+ "is_date_after"+ ],+ "type": "string"+ },+ "type": {+ "enum": [+ "event",+ "person",+ "session",+ "feature"+ ],+ "type": "string"+ },+ "value": {+ "description": "Value must be a date in ISO 8601 format.",+ "type": "string"+ }+ },+ "required": ["key", "operator", "type", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "description": "`is_set` - the property has any value. `is_not_set` - the property doesn't have a value or wasn't collected.",+ "enum": ["is_set", "is_not_set"],+ "type": "string"+ },+ "type": {+ "enum": [+ "event",+ "person",+ "session",+ "feature"+ ],+ "type": "string"+ }+ },+ "required": ["key", "operator", "type"],+ "type": "object"+ }+ ]+ },+ {+ "anyOf": [+ {+ "properties": {+ "group_type_index": {+ "description": "Index of the group type from the group mapping.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ },+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "description": "`icontains` - case insensitive contains. `not_icontains` - case insensitive does not contain. `regex` - matches the regex pattern. `not_regex` - does not match the regex pattern.",+ "enum": [+ "exact",+ "is_not",+ "icontains",+ "not_icontains",+ "regex",+ "not_regex"+ ],+ "type": "string"+ },+ "type": {+ "const": "group",+ "default": "group",+ "type": "string"+ },+ "value": {+ "description": "Only use property values from the plan. If the operator is `regex` or `not_regex`, the value must be a valid ClickHouse regex pattern to match against. Otherwise, the value must be a substring that will be matched against the property value. Use the string values `true` or `false` for boolean properties.",+ "type": "string"+ }+ },+ "required": [+ "group_type_index",+ "key",+ "operator",+ "value"+ ],+ "type": "object"+ },+ {+ "properties": {+ "group_type_index": {+ "description": "Index of the group type from the group mapping.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ },+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "enum": ["exact", "gt", "lt"],+ "type": "string"+ },+ "type": {+ "const": "group",+ "default": "group",+ "type": "string"+ },+ "value": {+ "type": "number"+ }+ },+ "required": [+ "group_type_index",+ "key",+ "operator",+ "value"+ ],+ "type": "object"+ },+ {+ "properties": {+ "group_type_index": {+ "description": "Index of the group type from the group mapping.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ },+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "description": "`exact` - exact match of any of the values. `is_not` - does not match any of the values.",+ "enum": ["exact", "is_not"],+ "type": "string"+ },+ "type": {+ "const": "group",+ "default": "group",+ "type": "string"+ },+ "value": {+ "description": "Only use property values from the plan. Always use strings as values. If you have a number, convert it to a string first. If you have a boolean, convert it to a string \"true\" or \"false\".",+ "items": {+ "type": "string"+ },+ "type": "array"+ }+ },+ "required": [+ "group_type_index",+ "key",+ "operator",+ "value"+ ],+ "type": "object"+ },+ {+ "properties": {+ "group_type_index": {+ "description": "Index of the group type from the group mapping.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ },+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "enum": [+ "is_date_exact",+ "is_date_before",+ "is_date_after"+ ],+ "type": "string"+ },+ "type": {+ "const": "group",+ "default": "group",+ "type": "string"+ },+ "value": {+ "description": "Value must be a date in ISO 8601 format.",+ "type": "string"+ }+ },+ "required": [+ "group_type_index",+ "key",+ "operator",+ "value"+ ],+ "type": "object"+ },+ {+ "properties": {+ "group_type_index": {+ "description": "Index of the group type from the group mapping.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ },+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "description": "`is_set` - the property has any value. `is_not_set` - the property doesn't have a value or wasn't collected.",+ "enum": ["is_set", "is_not_set"],+ "type": "string"+ },+ "type": {+ "const": "group",+ "default": "group",+ "type": "string"+ }+ },+ "required": ["group_type_index", "key", "operator"],+ "type": "object"+ }+ ]+ },+ {+ "properties": {+ "key": {+ "const": "id",+ "default": "id",+ "type": "string"+ },+ "operator": {+ "default": "in",+ "enum": ["in", "not_in"],+ "type": "string"+ },+ "type": {+ "const": "cohort",+ "default": "cohort",+ "description": "Filter events by cohort membership. Use this to narrow down results to persons belonging to a specific cohort. Use `operator: \"in\"` to include cohort members, or `operator: \"not_in\"` to exclude them. Examples:\n- Include: `{ type: \"cohort\", key: \"id\", value: 42, operator: \"in\" }`\n- Exclude: `{ type: \"cohort\", key: \"id\", value: 42, operator: \"not_in\" }`",+ "type": "string"+ },+ "value": {+ "description": "The cohort ID to filter by.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ }+ },+ "required": ["value"],+ "type": "object"+ },+ {+ "anyOf": [+ {+ "properties": {+ "key": {+ "description": "The element property to filter on. `tag_name` — HTML tag (e.g., `button`, `a`, `input`). `text` — visible text content of the element. `href` — the `href` attribute for links. `selector` — a CSS selector matching the element (e.g., `div.main > button.cta`).",+ "enum": [+ "tag_name",+ "text",+ "href",+ "selector"+ ],+ "type": "string"+ },+ "operator": {+ "description": "`icontains` - case insensitive contains. `not_icontains` - case insensitive does not contain. `regex` - matches the regex pattern. `not_regex` - does not match the regex pattern.",+ "enum": [+ "exact",+ "is_not",+ "icontains",+ "not_icontains",+ "regex",+ "not_regex"+ ],+ "type": "string"+ },+ "type": {+ "const": "element",+ "default": "element",+ "description": "Filter by autocaptured HTML element properties (`$autocapture`, `$rageclick`). Example: `{ type: \"element\", key: \"text\", value: \"Sign Up\", operator: \"exact\" }`",+ "type": "string"+ },+ "value": {+ "description": "Only use property values from the plan. If the operator is `regex` or `not_regex`, the value must be a valid ClickHouse regex pattern to match against. Otherwise, the value must be a substring that will be matched against the property value. Use the string values `true` or `false` for boolean properties.",+ "type": "string"+ }+ },+ "required": ["key", "operator", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "The element property to filter on. `tag_name` — HTML tag (e.g., `button`, `a`, `input`). `text` — visible text content of the element. `href` — the `href` attribute for links. `selector` — a CSS selector matching the element (e.g., `div.main > button.cta`).",+ "enum": [+ "tag_name",+ "text",+ "href",+ "selector"+ ],+ "type": "string"+ },+ "operator": {+ "enum": ["exact", "gt", "lt"],+ "type": "string"+ },+ "type": {+ "const": "element",+ "default": "element",+ "description": "Filter by autocaptured HTML element properties (`$autocapture`, `$rageclick`). Example: `{ type: \"element\", key: \"text\", value: \"Sign Up\", operator: \"exact\" }`",+ "type": "string"+ },+ "value": {+ "type": "number"+ }+ },+ "required": ["key", "operator", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "The element property to filter on. `tag_name` — HTML tag (e.g., `button`, `a`, `input`). `text` — visible text content of the element. `href` — the `href` attribute for links. `selector` — a CSS selector matching the element (e.g., `div.main > button.cta`).",+ "enum": [+ "tag_name",+ "text",+ "href",+ "selector"+ ],+ "type": "string"+ },+ "operator": {+ "description": "`exact` - exact match of any of the values. `is_not` - does not match any of the values.",+ "enum": ["exact", "is_not"],+ "type": "string"+ },+ "type": {+ "const": "element",+ "default": "element",+ "description": "Filter by autocaptured HTML element properties (`$autocapture`, `$rageclick`). Example: `{ type: \"element\", key: \"text\", value: \"Sign Up\", operator: \"exact\" }`",+ "type": "string"+ },+ "value": {+ "description": "Only use property values from the plan. Always use strings as values. If you have a number, convert it to a string first. If you have a boolean, convert it to a string \"true\" or \"false\".",+ "items": {+ "type": "string"+ },+ "type": "array"+ }+ },+ "required": ["key", "operator", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "The element property to filter on. `tag_name` — HTML tag (e.g., `button`, `a`, `input`). `text` — visible text content of the element. `href` — the `href` attribute for links. `selector` — a CSS selector matching the element (e.g., `div.main > button.cta`).",+ "enum": [+ "tag_name",+ "text",+ "href",+ "selector"+ ],+ "type": "string"+ },+ "operator": {+ "enum": [+ "is_date_exact",+ "is_date_before",+ "is_date_after"+ ],+ "type": "string"+ },+ "type": {+ "const": "element",+ "default": "element",+ "description": "Filter by autocaptured HTML element properties (`$autocapture`, `$rageclick`). Example: `{ type: \"element\", key: \"text\", value: \"Sign Up\", operator: \"exact\" }`",+ "type": "string"+ },+ "value": {+ "description": "Value must be a date in ISO 8601 format.",+ "type": "string"+ }+ },+ "required": ["key", "operator", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "The element property to filter on. `tag_name` — HTML tag (e.g., `button`, `a`, `input`). `text` — visible text content of the element. `href` — the `href` attribute for links. `selector` — a CSS selector matching the element (e.g., `div.main > button.cta`).",+ "enum": [+ "tag_name",+ "text",+ "href",+ "selector"+ ],+ "type": "string"+ },+ "operator": {+ "description": "`is_set` - the property has any value. `is_not_set` - the property doesn't have a value or wasn't collected.",+ "enum": ["is_set", "is_not_set"],+ "type": "string"+ },+ "type": {+ "const": "element",+ "default": "element",+ "description": "Filter by autocaptured HTML element properties (`$autocapture`, `$rageclick`). Example: `{ type: \"element\", key: \"text\", value: \"Sign Up\", operator: \"exact\" }`",+ "type": "string"+ }+ },+ "required": ["key", "operator"],+ "type": "object"+ }+ ]+ },+ {+ "properties": {+ "key": {+ "description": "A HogQL boolean expression used as a filter condition.\n\nExamples:\n- Filter where a property exceeds a threshold: `toFloat(properties.load_time) > 5.0`\n- Filter with string matching: `properties.$current_url LIKE '%/pricing%'`\n- Filter with multiple conditions: `properties.$browser = 'Chrome' AND toFloat(properties.duration) > 30`",+ "type": "string"+ },+ "type": {+ "const": "hogql",+ "default": "hogql",+ "description": "Filter by a HogQL boolean expression for advanced filtering that can't be expressed with standard property filters.",+ "type": "string"+ }+ },+ "required": ["key"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "The feature flag key.",+ "type": "string"+ },+ "operator": {+ "const": "flag_evaluates_to",+ "default": "flag_evaluates_to",+ "type": "string"+ },+ "type": {+ "const": "flag",+ "default": "flag",+ "description": "Filter events by feature flag state — only include events where a specific flag evaluated to a given value. Examples:\n- Flag enabled: `{ type: \"flag\", key: \"new-onboarding\", operator: \"flag_evaluates_to\", value: true }`\n- Specific variant: `{ type: \"flag\", key: \"checkout-experiment\", operator: \"flag_evaluates_to\", value: \"variant-a\" }`",+ "type": "string"+ },+ "value": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "string"+ }+ ],+ "description": "`true`/`false` for boolean flags, or a variant name string for multivariate flags."+ }+ },+ "required": ["key", "value"],+ "type": "object"+ }+ ]+ },+ "type": "array"+ },+ "type": {+ "const": "events",+ "default": "events",+ "type": "string"+ }+ },+ "required": ["id"],+ "type": "object"+ },+ {+ "properties": {+ "id": {+ "description": "The numeric action ID from the plan. This is the field the retention query engine uses to look up the action definition. For events use `AssistantRetentionEventsNode` instead, where `id` is the event name string.",+ "type": "number"+ },+ "name": {+ "description": "Optional human-readable label for the action, used for display only. Defaults to the action's stored name if omitted and is never used for action matching.",+ "type": "string"+ },+ "properties": {+ "description": "Property filters for the action.",+ "items": {+ "anyOf": [+ {+ "anyOf": [+ {+ "properties": {+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "description": "`icontains` - case insensitive contains. `not_icontains` - case insensitive does not contain. `regex` - matches the regex pattern. `not_regex` - does not match the regex pattern.",+ "enum": [+ "exact",+ "is_not",+ "icontains",+ "not_icontains",+ "regex",+ "not_regex"+ ],+ "type": "string"+ },+ "type": {+ "enum": [+ "event",+ "person",+ "session",+ "feature"+ ],+ "type": "string"+ },+ "value": {+ "description": "Only use property values from the plan. If the operator is `regex` or `not_regex`, the value must be a valid ClickHouse regex pattern to match against. Otherwise, the value must be a substring that will be matched against the property value. Use the string values `true` or `false` for boolean properties.",+ "type": "string"+ }+ },+ "required": ["key", "operator", "type", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "enum": ["exact", "gt", "lt"],+ "type": "string"+ },+ "type": {+ "enum": [+ "event",+ "person",+ "session",+ "feature"+ ],+ "type": "string"+ },+ "value": {+ "type": "number"+ }+ },+ "required": ["key", "operator", "type", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "description": "`exact` - exact match of any of the values. `is_not` - does not match any of the values.",+ "enum": ["exact", "is_not"],+ "type": "string"+ },+ "type": {+ "enum": [+ "event",+ "person",+ "session",+ "feature"+ ],+ "type": "string"+ },+ "value": {+ "description": "Only use property values from the plan. Always use strings as values. If you have a number, convert it to a string first. If you have a boolean, convert it to a string \"true\" or \"false\".",+ "items": {+ "type": "string"+ },+ "type": "array"+ }+ },+ "required": ["key", "operator", "type", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "enum": [+ "is_date_exact",+ "is_date_before",+ "is_date_after"+ ],+ "type": "string"+ },+ "type": {+ "enum": [+ "event",+ "person",+ "session",+ "feature"+ ],+ "type": "string"+ },+ "value": {+ "description": "Value must be a date in ISO 8601 format.",+ "type": "string"+ }+ },+ "required": ["key", "operator", "type", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "description": "`is_set` - the property has any value. `is_not_set` - the property doesn't have a value or wasn't collected.",+ "enum": ["is_set", "is_not_set"],+ "type": "string"+ },+ "type": {+ "enum": [+ "event",+ "person",+ "session",+ "feature"+ ],+ "type": "string"+ }+ },+ "required": ["key", "operator", "type"],+ "type": "object"+ }+ ]+ },+ {+ "anyOf": [+ {+ "properties": {+ "group_type_index": {+ "description": "Index of the group type from the group mapping.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ },+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "description": "`icontains` - case insensitive contains. `not_icontains` - case insensitive does not contain. `regex` - matches the regex pattern. `not_regex` - does not match the regex pattern.",+ "enum": [+ "exact",+ "is_not",+ "icontains",+ "not_icontains",+ "regex",+ "not_regex"+ ],+ "type": "string"+ },+ "type": {+ "const": "group",+ "default": "group",+ "type": "string"+ },+ "value": {+ "description": "Only use property values from the plan. If the operator is `regex` or `not_regex`, the value must be a valid ClickHouse regex pattern to match against. Otherwise, the value must be a substring that will be matched against the property value. Use the string values `true` or `false` for boolean properties.",+ "type": "string"+ }+ },+ "required": [+ "group_type_index",+ "key",+ "operator",+ "value"+ ],+ "type": "object"+ },+ {+ "properties": {+ "group_type_index": {+ "description": "Index of the group type from the group mapping.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ },+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "enum": ["exact", "gt", "lt"],+ "type": "string"+ },+ "type": {+ "const": "group",+ "default": "group",+ "type": "string"+ },+ "value": {+ "type": "number"+ }+ },+ "required": [+ "group_type_index",+ "key",+ "operator",+ "value"+ ],+ "type": "object"+ },+ {+ "properties": {+ "group_type_index": {+ "description": "Index of the group type from the group mapping.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ },+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "description": "`exact` - exact match of any of the values. `is_not` - does not match any of the values.",+ "enum": ["exact", "is_not"],+ "type": "string"+ },+ "type": {+ "const": "group",+ "default": "group",+ "type": "string"+ },+ "value": {+ "description": "Only use property values from the plan. Always use strings as values. If you have a number, convert it to a string first. If you have a boolean, convert it to a string \"true\" or \"false\".",+ "items": {+ "type": "string"+ },+ "type": "array"+ }+ },+ "required": [+ "group_type_index",+ "key",+ "operator",+ "value"+ ],+ "type": "object"+ },+ {+ "properties": {+ "group_type_index": {+ "description": "Index of the group type from the group mapping.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ },+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "enum": [+ "is_date_exact",+ "is_date_before",+ "is_date_after"+ ],+ "type": "string"+ },+ "type": {+ "const": "group",+ "default": "group",+ "type": "string"+ },+ "value": {+ "description": "Value must be a date in ISO 8601 format.",+ "type": "string"+ }+ },+ "required": [+ "group_type_index",+ "key",+ "operator",+ "value"+ ],+ "type": "object"+ },+ {+ "properties": {+ "group_type_index": {+ "description": "Index of the group type from the group mapping.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ },+ "key": {+ "description": "Use one of the properties the user has provided in the plan.",+ "type": "string"+ },+ "operator": {+ "description": "`is_set` - the property has any value. `is_not_set` - the property doesn't have a value or wasn't collected.",+ "enum": ["is_set", "is_not_set"],+ "type": "string"+ },+ "type": {+ "const": "group",+ "default": "group",+ "type": "string"+ }+ },+ "required": ["group_type_index", "key", "operator"],+ "type": "object"+ }+ ]+ },+ {+ "properties": {+ "key": {+ "const": "id",+ "default": "id",+ "type": "string"+ },+ "operator": {+ "default": "in",+ "enum": ["in", "not_in"],+ "type": "string"+ },+ "type": {+ "const": "cohort",+ "default": "cohort",+ "description": "Filter events by cohort membership. Use this to narrow down results to persons belonging to a specific cohort. Use `operator: \"in\"` to include cohort members, or `operator: \"not_in\"` to exclude them. Examples:\n- Include: `{ type: \"cohort\", key: \"id\", value: 42, operator: \"in\" }`\n- Exclude: `{ type: \"cohort\", key: \"id\", value: 42, operator: \"not_in\" }`",+ "type": "string"+ },+ "value": {+ "description": "The cohort ID to filter by.",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ }+ },+ "required": ["value"],+ "type": "object"+ },+ {+ "anyOf": [+ {+ "properties": {+ "key": {+ "description": "The element property to filter on. `tag_name` — HTML tag (e.g., `button`, `a`, `input`). `text` — visible text content of the element. `href` — the `href` attribute for links. `selector` — a CSS selector matching the element (e.g., `div.main > button.cta`).",+ "enum": [+ "tag_name",+ "text",+ "href",+ "selector"+ ],+ "type": "string"+ },+ "operator": {+ "description": "`icontains` - case insensitive contains. `not_icontains` - case insensitive does not contain. `regex` - matches the regex pattern. `not_regex` - does not match the regex pattern.",+ "enum": [+ "exact",+ "is_not",+ "icontains",+ "not_icontains",+ "regex",+ "not_regex"+ ],+ "type": "string"+ },+ "type": {+ "const": "element",+ "default": "element",+ "description": "Filter by autocaptured HTML element properties (`$autocapture`, `$rageclick`). Example: `{ type: \"element\", key: \"text\", value: \"Sign Up\", operator: \"exact\" }`",+ "type": "string"+ },+ "value": {+ "description": "Only use property values from the plan. If the operator is `regex` or `not_regex`, the value must be a valid ClickHouse regex pattern to match against. Otherwise, the value must be a substring that will be matched against the property value. Use the string values `true` or `false` for boolean properties.",+ "type": "string"+ }+ },+ "required": ["key", "operator", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "The element property to filter on. `tag_name` — HTML tag (e.g., `button`, `a`, `input`). `text` — visible text content of the element. `href` — the `href` attribute for links. `selector` — a CSS selector matching the element (e.g., `div.main > button.cta`).",+ "enum": [+ "tag_name",+ "text",+ "href",+ "selector"+ ],+ "type": "string"+ },+ "operator": {+ "enum": ["exact", "gt", "lt"],+ "type": "string"+ },+ "type": {+ "const": "element",+ "default": "element",+ "description": "Filter by autocaptured HTML element properties (`$autocapture`, `$rageclick`). Example: `{ type: \"element\", key: \"text\", value: \"Sign Up\", operator: \"exact\" }`",+ "type": "string"+ },+ "value": {+ "type": "number"+ }+ },+ "required": ["key", "operator", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "The element property to filter on. `tag_name` — HTML tag (e.g., `button`, `a`, `input`). `text` — visible text content of the element. `href` — the `href` attribute for links. `selector` — a CSS selector matching the element (e.g., `div.main > button.cta`).",+ "enum": [+ "tag_name",+ "text",+ "href",+ "selector"+ ],+ "type": "string"+ },+ "operator": {+ "description": "`exact` - exact match of any of the values. `is_not` - does not match any of the values.",+ "enum": ["exact", "is_not"],+ "type": "string"+ },+ "type": {+ "const": "element",+ "default": "element",+ "description": "Filter by autocaptured HTML element properties (`$autocapture`, `$rageclick`). Example: `{ type: \"element\", key: \"text\", value: \"Sign Up\", operator: \"exact\" }`",+ "type": "string"+ },+ "value": {+ "description": "Only use property values from the plan. Always use strings as values. If you have a number, convert it to a string first. If you have a boolean, convert it to a string \"true\" or \"false\".",+ "items": {+ "type": "string"+ },+ "type": "array"+ }+ },+ "required": ["key", "operator", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "The element property to filter on. `tag_name` — HTML tag (e.g., `button`, `a`, `input`). `text` — visible text content of the element. `href` — the `href` attribute for links. `selector` — a CSS selector matching the element (e.g., `div.main > button.cta`).",+ "enum": [+ "tag_name",+ "text",+ "href",+ "selector"+ ],+ "type": "string"+ },+ "operator": {+ "enum": [+ "is_date_exact",+ "is_date_before",+ "is_date_after"+ ],+ "type": "string"+ },+ "type": {+ "const": "element",+ "default": "element",+ "description": "Filter by autocaptured HTML element properties (`$autocapture`, `$rageclick`). Example: `{ type: \"element\", key: \"text\", value: \"Sign Up\", operator: \"exact\" }`",+ "type": "string"+ },+ "value": {+ "description": "Value must be a date in ISO 8601 format.",+ "type": "string"+ }+ },+ "required": ["key", "operator", "value"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "The element property to filter on. `tag_name` — HTML tag (e.g., `button`, `a`, `input`). `text` — visible text content of the element. `href` — the `href` attribute for links. `selector` — a CSS selector matching the element (e.g., `div.main > button.cta`).",+ "enum": [+ "tag_name",+ "text",+ "href",+ "selector"+ ],+ "type": "string"+ },+ "operator": {+ "description": "`is_set` - the property has any value. `is_not_set` - the property doesn't have a value or wasn't collected.",+ "enum": ["is_set", "is_not_set"],+ "type": "string"+ },+ "type": {+ "const": "element",+ "default": "element",+ "description": "Filter by autocaptured HTML element properties (`$autocapture`, `$rageclick`). Example: `{ type: \"element\", key: \"text\", value: \"Sign Up\", operator: \"exact\" }`",+ "type": "string"+ }+ },+ "required": ["key", "operator"],+ "type": "object"+ }+ ]+ },+ {+ "properties": {+ "key": {+ "description": "A HogQL boolean expression used as a filter condition.\n\nExamples:\n- Filter where a property exceeds a threshold: `toFloat(properties.load_time) > 5.0`\n- Filter with string matching: `properties.$current_url LIKE '%/pricing%'`\n- Filter with multiple conditions: `properties.$browser = 'Chrome' AND toFloat(properties.duration) > 30`",+ "type": "string"+ },+ "type": {+ "const": "hogql",+ "default": "hogql",+ "description": "Filter by a HogQL boolean expression for advanced filtering that can't be expressed with standard property filters.",+ "type": "string"+ }+ },+ "required": ["key"],+ "type": "object"+ },+ {+ "properties": {+ "key": {+ "description": "The feature flag key.",+ "type": "string"+ },+ "operator": {+ "const": "flag_evaluates_to",+ "default": "flag_evaluates_to",+ "type": "string"+ },+ "type": {+ "const": "flag",+ "default": "flag",+ "description": "Filter events by feature flag state — only include events where a specific flag evaluated to a given value. Examples:\n- Flag enabled: `{ type: \"flag\", key: \"new-onboarding\", operator: \"flag_evaluates_to\", value: true }`\n- Specific variant: `{ type: \"flag\", key: \"checkout-experiment\", operator: \"flag_evaluates_to\", value: \"variant-a\" }`",+ "type": "string"+ },+ "value": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "string"+ }+ ],+ "description": "`true`/`false` for boolean flags, or a variant name string for multivariate flags."+ }+ },+ "required": ["key", "value"],+ "type": "object"+ }+ ]+ },+ "type": "array"+ },+ "type": {+ "const": "actions",+ "default": "actions",+ "type": "string"+ }+ },+ "required": ["id"],+ "type": "object"+ }+ ],+ "description": "Activation event (event putting the actor into the initial cohort)."+ },+ "timeWindowMode": {+ "description": "The time window mode to use for retention calculations.",+ "enum": ["strict_calendar_dates", "24_hour_windows"],+ "type": "string"+ },+ "totalIntervals": {+ "default": 8,+ "description": "How many intervals to show in the chart. The default value is 8 (meaning 7 periods after initial cohort).",+ "maximum": 9007199254740991,+ "minimum": -9007199254740991,+ "type": "integer"+ }+ },+ "required": ["returningEntity", "targetEntity"],+ "type": "object"+ }+ },+ "required": ["retentionFilter"],+ "type": "object"+ }+ },+ "required": ["source"],+ "type": "object"+}diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/query-retention.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/query-retention.jsonindex d38b8abd09da..581a2975cf83 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/query-retention.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/query-retention.json@@ -591,6 +591,7 @@"items": {"type": "number"},+ "maxItems": 31,"type": "array"},"retentionReference": {diff --git a/services/mcp/tests/unit/query-wrapper-factory.test.ts b/services/mcp/tests/unit/query-wrapper-factory.test.tsindex 469d513e829b..3e8b36cf222b 100644--- a/services/mcp/tests/unit/query-wrapper-factory.test.ts+++ b/services/mcp/tests/unit/query-wrapper-factory.test.ts@@ -94,6 +94,7 @@ describe('createQueryWrapper _posthogUrl', () => {trendsActors: ReturnType<typeof vi.fn>lifecycleActors: ReturnType<typeof vi.fn>pathsActors: ReturnType<typeof vi.fn>+ retentionActors: ReturnType<typeof vi.fn>} {const actorsResponse = {query: { kind: 'ActorsQuery', source: { kind: 'InsightActorsQuery' } },@@ -104,14 +105,15 @@ describe('createQueryWrapper _posthogUrl', () => {const trendsActors = vi.fn().mockResolvedValue(actorsResponse)const lifecycleActors = vi.fn().mockResolvedValue(actorsResponse)const pathsActors = vi.fn().mockResolvedValue(actorsResponse)+ const retentionActors = vi.fn().mockResolvedValue(actorsResponse)const context = {api: {- query: vi.fn().mockReturnValue({ trendsActors, lifecycleActors, pathsActors }),+ query: vi.fn().mockReturnValue({ trendsActors, lifecycleActors, pathsActors, retentionActors }),getProjectBaseUrl: vi.fn().mockReturnValue('http://localhost:8010/project/1'),},stateManager: { getProjectId: vi.fn().mockResolvedValue('1') },} as unknown as Context- return { context, trendsActors, lifecycleActors, pathsActors }+ return { context, trendsActors, lifecycleActors, pathsActors, retentionActors }}const actorsSchema = z.object({@@ -153,6 +155,19 @@ describe('createQueryWrapper _posthogUrl', () => {expect(result._posthogUrl).toContain('DataTableNode')})+ it('dispatches RetentionQuery source to retentionActors', async () => {+ const { context, trendsActors, lifecycleActors, pathsActors, retentionActors } = createActorsDispatchContext()+ const tool = createQueryWrapper({ name: 'test', schema: actorsSchema, kind: 'InsightActorsQuery' })()++ const result = (await tool.handler(context, { source: { kind: 'RetentionQuery' } })) as any++ expect(retentionActors).toHaveBeenCalledOnce()+ expect(trendsActors).not.toHaveBeenCalled()+ expect(lifecycleActors).not.toHaveBeenCalled()+ expect(pathsActors).not.toHaveBeenCalled()+ expect(result._posthogUrl).toContain('DataTableNode')+ })+it('uses hash param not query param', async () => {const context = createMockContext()const factory = createQueryWrapper({ name: 'test', schema, kind: 'TrendsQuery' })@@ -323,8 +338,8 @@ describe('createQueryWrapper actors dispatch', () => {const factory = createQueryWrapper({ name: 'test', schema: actorsSchema, kind: 'InsightActorsQuery' })const tool = factory()- await expect(tool.handler(context, { source: { kind: 'RetentionQuery' } })).rejects.toThrow(- 'Unsupported source kind for actors query: RetentionQuery'+ await expect(tool.handler(context, { source: { kind: 'StickinessQuery' } })).rejects.toThrow(+ 'Unsupported source kind for actors query: StickinessQuery')})})