Skip to content

: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.

feat(mcp): add query-stickiness-actors tool (#64823)

Georgis Andonisa0bf77a2a76a
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 5a2720314300..e3f150c4480d 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -4198,6 +4198,8 @@ snapshots:
hash: v1.k794b7964.ea34a8cf895551499ca3bacabcde98ea445e2caea7fdc5b9f75de7d1d6dd8e6b.UfvafB3BxwBsJ8t1xHzxTmm5sRu0_xMGrAp6e4ldb5Y
mcp-apps-insight-actors--event-counts--light:
hash: v1.k794b7964.f0b17778c7d50e26542186c2a6758796a67334f35a1269cbe10e3269cec66b87.qSfkrh0qKHklQNE_y-fxq5ZSlGUoK6N16jfxvKHvZrA
+ mcp-apps-insight-actors--membership-only--light:
+ hash: v1.k794b7964.380d44591c986f45785c5a333b7c54a790a99cb65709e6bf8e32fe4e85a9373d.gVnlH6Lc6h27krJUWQNKiZAdoolFbMxTjFXRVVaJJTM
mcp-apps-insight-actors--with-recordings--light:
hash: v1.k794b7964.6bc38bc90689750e45b0eefa5974ce2e0fee05f581a64552835accca3914ded3.5ZInU5bxqbu_rkPp-prY1W5D2hsW8hn21EAwNfRjf_g
mcp-apps-lifecycle--grouped--light:
diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.json
index b83ab78f5830..d19cd56038b4 100644
--- a/frontend/src/queries/schema.json
+++ b/frontend/src/queries/schema.json
@@ -3618,6 +3618,35 @@
"required": ["id", "kind", "name"],
"type": "object"
},
+ "AssistantStickinessActorsQuery": {
+ "additionalProperties": false,
+ "description": "Drills into a stickiness insight to list the persons behind one bar — the users who were active in exactly `day` intervals within the source's date range (e.g. active on exactly 13 days). Returned rows are `distinct_id`, `email`, and `name`.\n\nPair this with `query-stickiness`: run the stickiness query first to read the distribution (the X-axis is the number of active intervals, the Y-axis is the number of users), then call this tool with the **same** stickiness query as `source` and `day` set to the bar you want to drill into.\n\nStickiness drilldown is membership-based and does not surface a matched-recordings column, so `includeRecordings` is intentionally omitted (as with lifecycle and retention).",
+ "properties": {
+ "compare": {
+ "description": "Whether to pull from the previous period when `compareFilter` is enabled in the source.",
+ "enum": ["current", "previous"],
+ "type": "string"
+ },
+ "day": {
+ "$ref": "#/definitions/integer",
+ "description": "The number of active intervals to drill into — the X-axis value of the stickiness bar. Despite the name, this is an interval **count**, not a date: for a daily insight, `day: 13` lists the users who were active on exactly 13 days within the source's date range."
+ },
+ "kind": {
+ "const": "InsightActorsQuery",
+ "type": "string"
+ },
+ "series": {
+ "$ref": "#/definitions/integer",
+ "description": "0-based index of the series to drill into when the source has multiple series. Defaults to 0."
+ },
+ "source": {
+ "$ref": "#/definitions/AssistantStickinessQuery",
+ "description": "The source stickiness insight query whose bar we are drilling into."
+ }
+ },
+ "required": ["kind", "source", "day"],
+ "type": "object"
+ },
"AssistantStickinessDisplayType": {
"description": "Stickiness display types. Only time-series visualizations are supported:\n- `ActionsLineGraph` - line chart (default)\n- `ActionsBar` - bar chart\n- `ActionsAreaGraph` - area chart",
"enum": ["ActionsLineGraph", "ActionsBar", "ActionsAreaGraph"],
diff --git a/frontend/src/queries/schema/schema-assistant-queries.ts b/frontend/src/queries/schema/schema-assistant-queries.ts
index 45e4d87f6850..00600ddccb61 100644
--- a/frontend/src/queries/schema/schema-assistant-queries.ts
+++ b/frontend/src/queries/schema/schema-assistant-queries.ts
@@ -1429,6 +1429,38 @@ export interface AssistantRetentionActorsQuery {
interval?: integer
}
+/**
+ * Drills into a stickiness insight to list the persons behind one bar — the users who were active
+ * in exactly `day` intervals within the source's date range (e.g. active on exactly 13 days).
+ * Returned rows are `distinct_id`, `email`, and `name`.
+ *
+ * Pair this with `query-stickiness`: run the stickiness query first to read the distribution
+ * (the X-axis is the number of active intervals, the Y-axis is the number of users), then call this
+ * tool with the **same** stickiness query as `source` and `day` set to the bar you want to drill into.
+ *
+ * Stickiness drilldown is membership-based and does not surface a matched-recordings column, so
+ * `includeRecordings` is intentionally omitted (as with lifecycle and retention).
+ */
+export interface AssistantStickinessActorsQuery {
+ kind: NodeKind.InsightActorsQuery
+
+ /** The source stickiness insight query whose bar we are drilling into. */
+ source: AssistantStickinessQuery
+
+ /**
+ * The number of active intervals to drill into — the X-axis value of the stickiness bar.
+ * Despite the name, this is an interval **count**, not a date: for a daily insight, `day: 13`
+ * lists the users who were active on exactly 13 days within the source's date range.
+ */
+ day: integer
+
+ /** 0-based index of the series to drill into when the source has multiple series. Defaults to 0. */
+ series?: integer
+
+ /** Whether to pull from the previous period when `compareFilter` is enabled in the source. */
+ compare?: 'current' | 'previous'
+}
+
/**
* 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 — debugging
diff --git a/posthog/schema.py b/posthog/schema.py
index 22150984f34a..dc60bc8d7589 100644
--- a/posthog/schema.py
+++ b/posthog/schema.py
@@ -21326,6 +21326,34 @@ class AssistantRetentionActorsQuery(BaseModel):
)
+class AssistantStickinessActorsQuery(BaseModel):
+ model_config = ConfigDict(
+ extra="forbid",
+ )
+ compare: Compare | None = Field(
+ default=None,
+ description=("Whether to pull from the previous period when `compareFilter` is enabled in the source."),
+ )
+ day: int = Field(
+ ...,
+ description=(
+ "The number of active intervals to drill into — the X-axis value of the"
+ " stickiness bar. Despite the name, this is an interval **count**, not a"
+ " date: for a daily insight, `day: 13` lists the users who were active on"
+ " exactly 13 days within the source's date range."
+ ),
+ )
+ kind: Literal["InsightActorsQuery"] = "InsightActorsQuery"
+ series: int | None = Field(
+ default=None,
+ description=("0-based index of the series to drill into when the source has multiple series. Defaults to 0."),
+ )
+ source: AssistantStickinessQuery = Field(
+ ...,
+ description=("The source stickiness insight query whose bar we are drilling into."),
+ )
+
+
class AssistantTrendsActorsQuery(BaseModel):
model_config = ConfigDict(
extra="forbid",
diff --git a/posthog/schema_enums.py b/posthog/schema_enums.py
index ba220c1864ed..d55daace01b4 100644
--- a/posthog/schema_enums.py
+++ b/posthog/schema_enums.py
@@ -327,6 +327,11 @@ class AssistantSetPropertyFilterOperator(StrEnum):
IS_NOT_SET = "is_not_set"
+class Compare(StrEnum):
+ CURRENT = "current"
+ PREVIOUS = "previous"
+
+
class AssistantStickinessDisplayType(StrEnum):
ACTIONS_LINE_GRAPH = "ActionsLineGraph"
ACTIONS_BAR = "ActionsBar"
@@ -417,11 +422,6 @@ class AssistantTool(StrEnum):
OPEN_ACCOUNT = "open_account"
-class Compare(StrEnum):
- CURRENT = "current"
- PREVIOUS = "previous"
-
-
class Display(StrEnum):
AUTO = "Auto"
ACTIONS_LINE_GRAPH = "ActionsLineGraph"
diff --git a/products/product_analytics/mcp/apps/InsightActorsView.stories.tsx b/products/product_analytics/mcp/apps/InsightActorsView.stories.tsx
index 8320cea32a3f..16d56d1707ce 100644
--- a/products/product_analytics/mcp/apps/InsightActorsView.stories.tsx
+++ b/products/product_analytics/mcp/apps/InsightActorsView.stories.tsx
@@ -60,11 +60,32 @@ const withRecordings: InsightActorsData = {
offset: 0,
}
+// Membership-based sources (stickiness, lifecycle) project only the actor — no event count and no
+// recordings — so the table collapses to just the Actor column with no default sort.
+const membershipOnly: InsightActorsData = {
+ query: { kind: 'ActorsQuery', source: { kind: 'InsightActorsQuery', source: { kind: 'StickinessQuery' } } },
+ results: {
+ columns: ['distinct_id', 'email', 'name'],
+ results: [
+ ['0a1b2c3d', '[email protected]', 'Alice Adams'],
+ ['1c2d3e4f', '[email protected]', 'Ben Brown'],
+ ['2e3f4a5b', null, null],
+ ],
+ },
+ hasMore: false,
+ offset: 0,
+}
+
export const EventCounts: Story = {
render: () => <InsightActorsView data={withEventCounts} openLink={openLink} />,
name: 'Event counts',
}
+export const MembershipOnly: Story = {
+ render: () => <InsightActorsView data={membershipOnly} openLink={openLink} />,
+ name: 'Membership only (stickiness/lifecycle)',
+}
+
export const WithRecordings: Story = {
render: () => <InsightActorsView data={withRecordings} openLink={openLink} />,
name: 'With recordings',
diff --git a/products/product_analytics/mcp/apps/InsightActorsView.tsx b/products/product_analytics/mcp/apps/InsightActorsView.tsx
index b5a11789d7db..580d22428655 100644
--- a/products/product_analytics/mcp/apps/InsightActorsView.tsx
+++ b/products/product_analytics/mcp/apps/InsightActorsView.tsx
@@ -23,6 +23,9 @@ export function InsightActorsView({ data, openLink }: InsightActorsViewProps): R
function EventCountActorsView({ data, openLink }: InsightActorsViewProps): ReactElement {
const rows = useMemo(() => toActorRows(data), [data])
+ // Membership-based sources (stickiness, lifecycle) project only the actor — no event count and
+ // no recordings — so drive both columns off the actual result columns rather than assume them.
+ const hasEventCount = data.results.columns.includes('event_count')
const hasRecordings = data.results.columns.includes('recordings')
const columns = useMemo((): DataTableColumn<ActorRow>[] => {
@@ -42,14 +45,17 @@ function EventCountActorsView({ data, openLink }: InsightActorsViewProps): React
)
},
},
- {
+ ]
+
+ if (hasEventCount) {
+ cols.push({
key: 'event_count',
header: 'Event count',
sortable: true,
align: 'right',
render: (row): ReactNode => <Badge>{row.event_count?.toLocaleString() ?? '—'}</Badge>,
- },
- ]
+ })
+ }
if (hasRecordings) {
cols.push({
@@ -88,7 +94,7 @@ function EventCountActorsView({ data, openLink }: InsightActorsViewProps): React
}
return cols
- }, [hasRecordings, openLink])
+ }, [hasEventCount, hasRecordings, openLink])
return (
<div className="p-4">
@@ -102,7 +108,8 @@ function EventCountActorsView({ data, openLink }: InsightActorsViewProps): React
<DataTable<ActorRow>
columns={columns}
data={rows}
- defaultSort={{ key: 'event_count', direction: 'desc' }}
+ // Without an event count there's nothing to rank by — keep the query's actor order.
+ defaultSort={hasEventCount ? { key: 'event_count', direction: 'desc' } : undefined}
emptyMessage="No actors found for this data point"
/>
</div>
diff --git a/services/mcp/definitions/prompts/query-stickiness-actors.md b/services/mcp/definitions/prompts/query-stickiness-actors.md
new file mode 100644
index 000000000000..0b3839a138ac
--- /dev/null
+++ b/services/mcp/definitions/prompts/query-stickiness-actors.md
@@ -0,0 +1,19 @@
+List the persons behind one bar of a stickiness insight — the users who were active in a given number of intervals.
+
+Pair this with `query-stickiness`: first run the stickiness query to read the distribution (the X-axis is the number of active intervals, the Y-axis is the number of users), then call this tool with the **same** stickiness query as `source` and `day` set to the bar you want to drill into.
+
+Selectors:
+
+- `day` **(required)**: the number of active intervals to drill into — the X-axis value of the bar. Despite the name, this is an interval **count**, not a date. For a daily insight, `day: 13` lists the users who were active on exactly 13 days within the source's date range; for a weekly insight it is a count of weeks, and so on.
+- `series`: 0-based index of the series to drill into when the stickiness query has multiple series. Defaults to 0.
+- `compare`: `current` (default) or `previous` when the source has `compareFilter` enabled.
+
+Response:
+
+Each returned row contains `distinct_id`, `email`, and `name`. Results are limited to the top 100 actors. There is no `event_count`, and there is no `includeRecordings` selector — stickiness drilldown is membership-based (active on exactly N intervals) and does not surface a matched-recordings column.
+
+Guidance:
+
+- Keep the `source` stickiness query identical to the one whose bar the user is asking about — the series, interval granularity, date range, and filters all determine who falls in each bar.
+- `day` selects a single bar (a specific active-interval count), not a date. To list the users at a different bar, change `day`.
+- For 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.yaml
index 7b6441301042..07b35c23cd3e 100644
--- a/services/mcp/definitions/query-wrappers.yaml
+++ b/services/mcp/definitions/query-wrappers.yaml
@@ -229,3 +229,22 @@ wrappers:
exclude_properties:
- response
- modifiers
+
+ query-stickiness-actors:
+ schema_ref: AssistantStickinessActorsQuery
+ enabled: true
+ scopes:
+ - query:read
+ - person:read
+ annotations:
+ readOnly: true
+ destructive: false
+ idempotent: true
+ title: List persons behind a stickiness bar
+ description_file: ./prompts/query-stickiness-actors.md
+ system_prompt_hint: List persons who were active in a given number of intervals (one stickiness bar)
+ ui_resource_uri: ui://posthog/insight-actors.html
+ use_optimized_output: true
+ exclude_properties:
+ - response
+ - modifiers
diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.json
index 1ba6a85de9fb..9a740233e041 100644
--- a/services/mcp/schema/generated-tool-definitions.json
+++ b/services/mcp/schema/generated-tool-definitions.json
@@ -5708,6 +5708,21 @@
},
"system_prompt_hint": "Engagement frequency (how many days users do X)"
},
+ "query-stickiness-actors": {
+ "description": "List the persons behind one bar of a stickiness insight — the users who were active in a given number of intervals.\n\nPair this with `query-stickiness`: first run the stickiness query to read the distribution (the X-axis is the number of active intervals, the Y-axis is the number of users), then call this tool with the **same** stickiness query as `source` and `day` set to the bar you want to drill into.\n\nSelectors:\n\n- `day` **(required)**: the number of active intervals to drill into — the X-axis value of the bar. Despite the name, this is an interval **count**, not a date. For a daily insight, `day: 13` lists the users who were active on exactly 13 days within the source's date range; for a weekly insight it is a count of weeks, and so on.\n- `series`: 0-based index of the series to drill into when the stickiness query has multiple series. Defaults to 0.\n- `compare`: `current` (default) or `previous` when the source has `compareFilter` enabled.\n\nResponse:\n\nEach returned row contains `distinct_id`, `email`, and `name`. Results are limited to the top 100 actors. There is no `event_count`, and there is no `includeRecordings` selector — stickiness drilldown is membership-based (active on exactly N intervals) and does not surface a matched-recordings column.\n\nGuidance:\n\n- Keep the `source` stickiness query identical to the one whose bar the user is asking about — the series, interval granularity, date range, and filters all determine who falls in each bar.\n- `day` selects a single bar (a specific active-interval count), not a date. To list the users at a different bar, change `day`.\n- For large result sets, tighten the source (date range, filters) rather than expecting more than 100 rows.",
+ "category": "Query wrappers",
+ "feature": "insights",
+ "summary": "List persons behind a stickiness bar",
+ "title": "List persons behind a stickiness bar",
+ "required_scopes": ["query:read", "person:read"],
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ },
+ "system_prompt_hint": "List persons who were active in a given number of intervals (one stickiness bar)"
+ },
"query-trends": {
"description": "Run a trends query to analyze metrics over time. Trends insights visualize events over time using time series. They're useful for finding patterns in historical data.\n\nUse 'read-data-schema' to discover available events, actions, and properties for filters and breakdowns.\n\nThe trends insights have the following features:\n\n- The insight can show multiple trends in one request.\n- Custom formulas can calculate derived metrics, like `A/B*100` to calculate a ratio.\n- Filter and break down data using multiple properties.\n- Compare with the previous period and sample data.\n- Apply various aggregation types, like sum, average, etc., and chart types.\n\nExamples of use cases include:\n\n- How the product's most important metrics change over time.\n- Long-term patterns, or cycles in product's usage.\n- The usage of different features side-by-side.\n- How the properties of events vary using aggregation (sum, average, etc).\n- Users can also visualize the same data points in a variety of ways.\n\nCRITICAL: Be minimalist. Only include filters, breakdowns, and settings that are essential to answer the user's specific question. Default settings are usually sufficient unless the user explicitly requests customization.\n\n# Data narrowing\n\n## Property filters\n\nUse property filters to narrow results. Only include property filters when they are essential to directly answer the user's question. Avoid adding them if the question can be addressed without additional segmentation and always use the minimum set of property filters needed.\n\nIMPORTANT: Do not check if a property is set unless the user explicitly asks for it.\n\nWhen using a property filter, you should:\n\n- **Prioritize properties directly related to the context or objective of the user's query.** Avoid using properties for identification like IDs. Instead, prioritize filtering based on general properties like `paidCustomer` or `icp_score`.\n- **Ensure that you find both the property group and name.** Property groups should be one of the following: event, person, session, group.\n- After selecting a property, **validate that the property value accurately reflects the intended criteria**.\n- **Find the suitable operator for type** (e.g., `contains`, `is set`).\n- If the operator requires a value, use the `read-data-schema` tool to find the property values.\n- You set logical operators to combine multiple properties of a single series: AND or OR.\n\nInfer the property groups from the user's request. If your first guess doesn't yield any results, try to adjust the property group.\n\nSupported operators for the String type are:\n\n- equals (exact)\n- doesn't equal (is_not)\n- contains (icontains)\n- doesn't contain (not_icontains)\n- matches regex (regex)\n- doesn't match regex (not_regex)\n- is set\n- is not set\n\nSupported operators for the Numeric type are:\n\n- equals (exact)\n- doesn't equal (is_not)\n- greater than (gt)\n- less than (lt)\n- is set\n- is not set\n\nSupported operators for the DateTime type are:\n\n- equals (is_date_exact)\n- doesn't equal (is_not for existence check)\n- before (is_date_before)\n- after (is_date_after)\n- is set\n- is not set\n\nSupported operators for the Boolean type are:\n\n- equals\n- doesn't equal\n- is set\n- is not set\n\nAll operators take a single value except for `equals` and `doesn't equal` which can take one or more values (as an array).\n\n## Time period\n\nYou should not filter events by time using property filters. Instead, use the `dateRange` field. If the question doesn't mention time, use last 30 days as a default time period.\n\n# Trends guidelines\n\nTrends insights enable users to plot data from people, events, and properties however they want. They're useful for finding patterns in data, as well as monitoring product usage. Users can use multiple independent series in a single query to see trends. They can also use a formula to calculate a metric. Each series has its own set of property filters. Trends insights do not require breakdowns or filters by default.\n\n## Aggregation\n\nDetermine the math aggregation the user is asking for, such as totals, averages, ratios, or custom formulas. If not specified, choose a reasonable default based on the event type (e.g., total count). By default, the total count should be used. You can aggregate data by events, event's property values, groups, or users. If you're aggregating by users or groups, there's no need to check for their existence.\n\nAvailable math aggregation types for the event count are:\n\n- total count\n- average\n- minimum\n- maximum\n- median\n- 90th percentile\n- 95th percentile\n- 99th percentile\n- unique users\n- unique sessions\n- weekly active users\n- daily active users\n- first time for a user\n- unique groups (requires `math_group_type_index` to be set to the group type index from the group mapping)\n\nAvailable math aggregation types for event's property values are:\n\n- average\n- sum\n- minimum\n- maximum\n- median\n- 90th percentile\n- 95th percentile\n- 99th percentile\n\nAvailable math aggregation types counting number of events completed per user (intensity of usage) are:\n\n- average\n- minimum\n- maximum\n- median\n- 90th percentile\n- 95th percentile\n- 99th percentile\n\nExamples of using aggregation types:\n\n- `unique users` to find how many distinct users have logged the event per a day.\n- `average` by the `$session_duration` property to find out what was the average session duration of an event.\n- `99th percentile by users` to find out what was the 99th percentile of the event count by users.\n\n## Combining multiple events into a single series (`GroupNode`)\n\n**Use a `GroupNode`** when the user says \"X OR Y\" (or \"any of these events\") and wants **one line / one number** as the result. Different filters per event are fine — put them on the inner nodes. Use separate top-level series instead when the user wants the events compared side by side. Only `OR` is supported.\n\n**Where things live:**\n\n- On the group: `math` / `math_property` / `math_property_type` / `math_multiplier` / `math_group_type_index` / `math_hogql`, plus `name`. The engine reads aggregation from here.\n- On each inner node: `event` (or action `id`), `properties`, `name` — all respected normally; `properties` applies only to that node. Mirror the group's `math*` values on each inner node for UI round-trip, but they're ignored at execution time.\n\n### Example — different filter per event\n\n\"Pageviews on Safari OR pageleaves on Chrome, as one line.\" Each inner node carries its own `properties`; the group ORs them and aggregates as one series.\n\n```json\n{\n \"kind\": \"TrendsQuery\",\n \"series\": [\n {\n \"kind\": \"GroupNode\",\n \"operator\": \"OR\",\n \"name\": \"Pageviews on Safari, Pageleaves on Chrome\",\n \"math\": \"total\",\n \"nodes\": [\n {\n \"kind\": \"EventsNode\",\n \"event\": \"$pageview\",\n \"name\": \"Pageview\",\n \"math\": \"total\",\n \"properties\": [{ \"key\": \"$browser\", \"operator\": \"exact\", \"type\": \"event\", \"value\": [\"Safari\"] }]\n },\n {\n \"kind\": \"EventsNode\",\n \"event\": \"$pageleave\",\n \"name\": \"Pageleave\",\n \"math\": \"total\",\n \"properties\": [{ \"key\": \"$browser\", \"operator\": \"exact\", \"type\": \"event\", \"value\": [\"Chrome\"] }]\n }\n ]\n }\n ],\n \"dateRange\": { \"date_from\": \"-30d\" },\n \"interval\": \"day\"\n}\n```\n\n## Math formulas\n\nIf the math aggregation is more complex or not listed above, use custom formulas to perform mathematical operations like calculating percentages or metrics. If you use a formula, you should use the following syntax: `A/B`, where `A` and `B` are the names of the series. You can combine math aggregations and formulas.\n\nWhen using a formula, you should:\n\n- Identify and specify **all** events and actions needed to solve the formula.\n- Carefully review the list of available events and actions to find appropriate entities for each part of the formula.\n- Ensure that you find events and actions corresponding to both the numerator and denominator in ratio calculations.\n\nExamples of using math formulas:\n\n- If you want to calculate the percentage of users who have completed onboarding, you need to find and use events or actions similar to `$identify` and `onboarding complete`, so the formula will be `A / B * 100`, where `A` is `onboarding complete` (unique users) and `B` is `$identify` (unique users).\n- To calculate conversion rate: `A / B * 100` where A is conversions and B is total events.\n- To calculate average value: `A / B` where A is sum of property and B is count.\n\n## Time interval\n\nSpecify the time interval (group by time) using the `interval` field. Available intervals are: `hour`, `day`, `week`, `month`.\nUnless the user has specified otherwise, use the following default interval:\n\n- If the time period is less than two days, use the `hour` interval.\n- If the time period is less than a month, use the `day` interval.\n- If the time period is less than three months, use the `week` interval.\n- Otherwise, use the `month` interval.\n\n## Breakdowns\n\nBreakdowns are used to segment data by property values of maximum three properties. They divide all defined trends series into multiple subseries based on the values of the property. Include breakdowns **only when they are essential to directly answer the user's question**. You should not add breakdowns if the question can be addressed without additional segmentation. Always use the minimum set of breakdowns needed.\n\nWhen using breakdowns, you should:\n\n- **Identify the property group** and name for each breakdown.\n- **Provide the property name** for each breakdown.\n- **Validate that the property value accurately reflects the intended criteria**.\n\nExamples of using breakdowns:\n\n- page views trend by country: you need to find a property such as `$geoip_country_code` and set it as a breakdown.\n- number of users who have completed onboarding by an organization: you need to find a property such as `organization name` and set it as a breakdown.\n\n# Examples\n\n## How many users signed up?\n\n```json\n{\n \"kind\": \"TrendsQuery\",\n \"series\": [{ \"kind\": \"EventsNode\", \"event\": \"user signed up\", \"math\": \"total\" }],\n \"dateRange\": { \"date_from\": \"-30d\" },\n \"interval\": \"month\",\n \"trendsFilter\": { \"display\": \"BoldNumber\" }\n}\n```\n\n## Page views by referring domain for the last month\n\n```json\n{\n \"kind\": \"TrendsQuery\",\n \"series\": [{ \"kind\": \"EventsNode\", \"event\": \"$pageview\", \"math\": \"total\" }],\n \"dateRange\": { \"date_from\": \"-30d\" },\n \"interval\": \"day\",\n \"breakdownFilter\": {\n \"breakdowns\": [{ \"property\": \"$referring_domain\", \"type\": \"event\" }]\n }\n}\n```\n\n## DAU to MAU ratio for users from the US, compared to the previous period\n\n```json\n{\n \"kind\": \"TrendsQuery\",\n \"series\": [\n { \"kind\": \"EventsNode\", \"event\": \"$pageview\", \"math\": \"dau\" },\n { \"kind\": \"EventsNode\", \"event\": \"$pageview\", \"math\": \"monthly_active\" }\n ],\n \"dateRange\": { \"date_from\": \"-7d\" },\n \"interval\": \"day\",\n \"properties\": {\n \"type\": \"AND\",\n \"values\": [\n {\n \"type\": \"AND\",\n \"values\": [{ \"key\": \"$geoip_country_name\", \"operator\": \"exact\", \"type\": \"event\", \"value\": [\"United States\"] }]\n }\n ]\n },\n \"compareFilter\": { \"compare\": true },\n \"trendsFilter\": { \"display\": \"ActionsLineGraph\", \"formula\": \"A/B\", \"aggregationAxisFormat\": \"percentage_scaled\" }\n}\n```\n\n## Unique users and first-time users for \"insight created\" over the last 12 months\n\n```json\n{\n \"kind\": \"TrendsQuery\",\n \"series\": [\n { \"kind\": \"EventsNode\", \"event\": \"insight created\", \"math\": \"dau\" },\n { \"kind\": \"EventsNode\", \"event\": \"insight created\", \"math\": \"first_time_for_user\" }\n ],\n \"dateRange\": { \"date_from\": \"-12m\" },\n \"interval\": \"month\",\n \"filterTestAccounts\": true,\n \"trendsFilter\": { \"display\": \"ActionsLineGraph\" }\n}\n```\n\n## P99, P95, and median of a \"refreshAge\" property on \"viewed dashboard\" events\n\n```json\n{\n \"kind\": \"TrendsQuery\",\n \"series\": [\n { \"kind\": \"EventsNode\", \"event\": \"viewed dashboard\", \"math\": \"p99\", \"math_property\": \"refreshAge\" },\n { \"kind\": \"EventsNode\", \"event\": \"viewed dashboard\", \"math\": \"p95\", \"math_property\": \"refreshAge\" },\n { \"kind\": \"EventsNode\", \"event\": \"viewed dashboard\", \"math\": \"median\", \"math_property\": \"refreshAge\" }\n ],\n \"dateRange\": { \"date_from\": \"yStart\" },\n \"interval\": \"month\",\n \"filterTestAccounts\": true,\n \"trendsFilter\": { \"display\": \"ActionsLineGraph\", \"aggregationAxisFormat\": \"duration\" }\n}\n```\n\n## Organizations that signed up from Google in the last 30 days (group aggregation)\n\n```json\n{\n \"kind\": \"TrendsQuery\",\n \"series\": [\n {\n \"kind\": \"EventsNode\",\n \"event\": \"user signed up\",\n \"math\": \"unique_group\",\n \"math_group_type_index\": 0,\n \"properties\": [{ \"key\": \"is_organization_first_user\", \"operator\": \"exact\", \"type\": \"person\", \"value\": [\"true\"] }]\n }\n ],\n \"dateRange\": { \"date_from\": \"-30d\" },\n \"interval\": \"day\",\n \"properties\": {\n \"type\": \"AND\",\n \"values\": [\n {\n \"type\": \"OR\",\n \"values\": [{ \"key\": \"$initial_utm_source\", \"operator\": \"exact\", \"type\": \"person\", \"value\": [\"google\"] }]\n }\n ]\n },\n \"trendsFilter\": { \"display\": \"ActionsLineGraph\" }\n}\n```\n\n# Reminders\n\n- Ensure that any properties included are directly relevant to the context and objectives of the user's question. Avoid unnecessary or unrelated details.\n- Avoid overcomplicating the response with excessive property filters. Focus on the simplest solution.\n- When using group aggregations (unique groups), always set `math_group_type_index` to the appropriate group type index from the group mapping.\n- Visualization settings (display type, axis format, etc.) should only be specified when explicitly requested or when they significantly improve the answer.",
"category": "Query wrappers",
diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.json
index e0c7f7eb1d10..6c11045e99c1 100644
--- a/services/mcp/schema/tool-definitions-all.json
+++ b/services/mcp/schema/tool-definitions-all.json
@@ -6159,6 +6159,21 @@
},
"system_prompt_hint": "Engagement frequency (how many days users do X)"
},
+ "query-stickiness-actors": {
+ "description": "List the persons behind one bar of a stickiness insight — the users who were active in a given number of intervals.\n\nPair this with `query-stickiness`: first run the stickiness query to read the distribution (the X-axis is the number of active intervals, the Y-axis is the number of users), then call this tool with the **same** stickiness query as `source` and `day` set to the bar you want to drill into.\n\nSelectors:\n\n- `day` **(required)**: the number of active intervals to drill into — the X-axis value of the bar. Despite the name, this is an interval **count**, not a date. For a daily insight, `day: 13` lists the users who were active on exactly 13 days within the source's date range; for a weekly insight it is a count of weeks, and so on.\n- `series`: 0-based index of the series to drill into when the stickiness query has multiple series. Defaults to 0.\n- `compare`: `current` (default) or `previous` when the source has `compareFilter` enabled.\n\nResponse:\n\nEach returned row contains `distinct_id`, `email`, and `name`. Results are limited to the top 100 actors. There is no `event_count`, and there is no `includeRecordings` selector — stickiness drilldown is membership-based (active on exactly N intervals) and does not surface a matched-recordings column.\n\nGuidance:\n\n- Keep the `source` stickiness query identical to the one whose bar the user is asking about — the series, interval granularity, date range, and filters all determine who falls in each bar.\n- `day` selects a single bar (a specific active-interval count), not a date. To list the users at a different bar, change `day`.\n- For large result sets, tighten the source (date range, filters) rather than expecting more than 100 rows.",
+ "category": "Query wrappers",
+ "feature": "insights",
+ "summary": "List persons behind a stickiness bar",
+ "title": "List persons behind a stickiness bar",
+ "required_scopes": ["query:read", "person:read"],
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ },
+ "system_prompt_hint": "List persons who were active in a given number of intervals (one stickiness bar)"
+ },
"query-trends": {
"description": "Run a trends query to analyze metrics over time. Trends insights visualize events over time using time series. They're useful for finding patterns in historical data.\n\nUse 'read-data-schema' to discover available events, actions, and properties for filters and breakdowns.\n\nThe trends insights have the following features:\n\n- The insight can show multiple trends in one request.\n- Custom formulas can calculate derived metrics, like `A/B*100` to calculate a ratio.\n- Filter and break down data using multiple properties.\n- Compare with the previous period and sample data.\n- Apply various aggregation types, like sum, average, etc., and chart types.\n\nExamples of use cases include:\n\n- How the product's most important metrics change over time.\n- Long-term patterns, or cycles in product's usage.\n- The usage of different features side-by-side.\n- How the properties of events vary using aggregation (sum, average, etc).\n- Users can also visualize the same data points in a variety of ways.\n\nCRITICAL: Be minimalist. Only include filters, breakdowns, and settings that are essential to answer the user's specific question. Default settings are usually sufficient unless the user explicitly requests customization.\n\n# Data narrowing\n\n## Property filters\n\nUse property filters to narrow results. Only include property filters when they are essential to directly answer the user's question. Avoid adding them if the question can be addressed without additional segmentation and always use the minimum set of property filters needed.\n\nIMPORTANT: Do not check if a property is set unless the user explicitly asks for it.\n\nWhen using a property filter, you should:\n\n- **Prioritize properties directly related to the context or objective of the user's query.** Avoid using properties for identification like IDs. Instead, prioritize filtering based on general properties like `paidCustomer` or `icp_score`.\n- **Ensure that you find both the property group and name.** Property groups should be one of the following: event, person, session, group.\n- After selecting a property, **validate that the property value accurately reflects the intended criteria**.\n- **Find the suitable operator for type** (e.g., `contains`, `is set`).\n- If the operator requires a value, use the `read-data-schema` tool to find the property values.\n- You set logical operators to combine multiple properties of a single series: AND or OR.\n\nInfer the property groups from the user's request. If your first guess doesn't yield any results, try to adjust the property group.\n\nSupported operators for the String type are:\n\n- equals (exact)\n- doesn't equal (is_not)\n- contains (icontains)\n- doesn't contain (not_icontains)\n- matches regex (regex)\n- doesn't match regex (not_regex)\n- is set\n- is not set\n\nSupported operators for the Numeric type are:\n\n- equals (exact)\n- doesn't equal (is_not)\n- greater than (gt)\n- less than (lt)\n- is set\n- is not set\n\nSupported operators for the DateTime type are:\n\n- equals (is_date_exact)\n- doesn't equal (is_not for existence check)\n- before (is_date_before)\n- after (is_date_after)\n- is set\n- is not set\n\nSupported operators for the Boolean type are:\n\n- equals\n- doesn't equal\n- is set\n- is not set\n\nAll operators take a single value except for `equals` and `doesn't equal` which can take one or more values (as an array).\n\n## Time period\n\nYou should not filter events by time using property filters. Instead, use the `dateRange` field. If the question doesn't mention time, use last 30 days as a default time period.\n\n# Trends guidelines\n\nTrends insights enable users to plot data from people, events, and properties however they want. They're useful for finding patterns in data, as well as monitoring product usage. Users can use multiple independent series in a single query to see trends. They can also use a formula to calculate a metric. Each series has its own set of property filters. Trends insights do not require breakdowns or filters by default.\n\n## Aggregation\n\nDetermine the math aggregation the user is asking for, such as totals, averages, ratios, or custom formulas. If not specified, choose a reasonable default based on the event type (e.g., total count). By default, the total count should be used. You can aggregate data by events, event's property values, groups, or users. If you're aggregating by users or groups, there's no need to check for their existence.\n\nAvailable math aggregation types for the event count are:\n\n- total count\n- average\n- minimum\n- maximum\n- median\n- 90th percentile\n- 95th percentile\n- 99th percentile\n- unique users\n- unique sessions\n- weekly active users\n- daily active users\n- first time for a user\n- unique groups (requires `math_group_type_index` to be set to the group type index from the group mapping)\n\nAvailable math aggregation types for event's property values are:\n\n- average\n- sum\n- minimum\n- maximum\n- median\n- 90th percentile\n- 95th percentile\n- 99th percentile\n\nAvailable math aggregation types counting number of events completed per user (intensity of usage) are:\n\n- average\n- minimum\n- maximum\n- median\n- 90th percentile\n- 95th percentile\n- 99th percentile\n\nExamples of using aggregation types:\n\n- `unique users` to find how many distinct users have logged the event per a day.\n- `average` by the `$session_duration` property to find out what was the average session duration of an event.\n- `99th percentile by users` to find out what was the 99th percentile of the event count by users.\n\n## Combining multiple events into a single series (`GroupNode`)\n\n**Use a `GroupNode`** when the user says \"X OR Y\" (or \"any of these events\") and wants **one line / one number** as the result. Different filters per event are fine — put them on the inner nodes. Use separate top-level series instead when the user wants the events compared side by side. Only `OR` is supported.\n\n**Where things live:**\n\n- On the group: `math` / `math_property` / `math_property_type` / `math_multiplier` / `math_group_type_index` / `math_hogql`, plus `name`. The engine reads aggregation from here.\n- On each inner node: `event` (or action `id`), `properties`, `name` — all respected normally; `properties` applies only to that node. Mirror the group's `math*` values on each inner node for UI round-trip, but they're ignored at execution time.\n\n### Example — different filter per event\n\n\"Pageviews on Safari OR pageleaves on Chrome, as one line.\" Each inner node carries its own `properties`; the group ORs them and aggregates as one series.\n\n```json\n{\n \"kind\": \"TrendsQuery\",\n \"series\": [\n {\n \"kind\": \"GroupNode\",\n \"operator\": \"OR\",\n \"name\": \"Pageviews on Safari, Pageleaves on Chrome\",\n \"math\": \"total\",\n \"nodes\": [\n {\n \"kind\": \"EventsNode\",\n \"event\": \"$pageview\",\n \"name\": \"Pageview\",\n \"math\": \"total\",\n \"properties\": [{ \"key\": \"$browser\", \"operator\": \"exact\", \"type\": \"event\", \"value\": [\"Safari\"] }]\n },\n {\n \"kind\": \"EventsNode\",\n \"event\": \"$pageleave\",\n \"name\": \"Pageleave\",\n \"math\": \"total\",\n \"properties\": [{ \"key\": \"$browser\", \"operator\": \"exact\", \"type\": \"event\", \"value\": [\"Chrome\"] }]\n }\n ]\n }\n ],\n \"dateRange\": { \"date_from\": \"-30d\" },\n \"interval\": \"day\"\n}\n```\n\n## Math formulas\n\nIf the math aggregation is more complex or not listed above, use custom formulas to perform mathematical operations like calculating percentages or metrics. If you use a formula, you should use the following syntax: `A/B`, where `A` and `B` are the names of the series. You can combine math aggregations and formulas.\n\nWhen using a formula, you should:\n\n- Identify and specify **all** events and actions needed to solve the formula.\n- Carefully review the list of available events and actions to find appropriate entities for each part of the formula.\n- Ensure that you find events and actions corresponding to both the numerator and denominator in ratio calculations.\n\nExamples of using math formulas:\n\n- If you want to calculate the percentage of users who have completed onboarding, you need to find and use events or actions similar to `$identify` and `onboarding complete`, so the formula will be `A / B * 100`, where `A` is `onboarding complete` (unique users) and `B` is `$identify` (unique users).\n- To calculate conversion rate: `A / B * 100` where A is conversions and B is total events.\n- To calculate average value: `A / B` where A is sum of property and B is count.\n\n## Time interval\n\nSpecify the time interval (group by time) using the `interval` field. Available intervals are: `hour`, `day`, `week`, `month`.\nUnless the user has specified otherwise, use the following default interval:\n\n- If the time period is less than two days, use the `hour` interval.\n- If the time period is less than a month, use the `day` interval.\n- If the time period is less than three months, use the `week` interval.\n- Otherwise, use the `month` interval.\n\n## Breakdowns\n\nBreakdowns are used to segment data by property values of maximum three properties. They divide all defined trends series into multiple subseries based on the values of the property. Include breakdowns **only when they are essential to directly answer the user's question**. You should not add breakdowns if the question can be addressed without additional segmentation. Always use the minimum set of breakdowns needed.\n\nWhen using breakdowns, you should:\n\n- **Identify the property group** and name for each breakdown.\n- **Provide the property name** for each breakdown.\n- **Validate that the property value accurately reflects the intended criteria**.\n\nExamples of using breakdowns:\n\n- page views trend by country: you need to find a property such as `$geoip_country_code` and set it as a breakdown.\n- number of users who have completed onboarding by an organization: you need to find a property such as `organization name` and set it as a breakdown.\n\n# Examples\n\n## How many users signed up?\n\n```json\n{\n \"kind\": \"TrendsQuery\",\n \"series\": [{ \"kind\": \"EventsNode\", \"event\": \"user signed up\", \"math\": \"total\" }],\n \"dateRange\": { \"date_from\": \"-30d\" },\n \"interval\": \"month\",\n \"trendsFilter\": { \"display\": \"BoldNumber\" }\n}\n```\n\n## Page views by referring domain for the last month\n\n```json\n{\n \"kind\": \"TrendsQuery\",\n \"series\": [{ \"kind\": \"EventsNode\", \"event\": \"$pageview\", \"math\": \"total\" }],\n \"dateRange\": { \"date_from\": \"-30d\" },\n \"interval\": \"day\",\n \"breakdownFilter\": {\n \"breakdowns\": [{ \"property\": \"$referring_domain\", \"type\": \"event\" }]\n }\n}\n```\n\n## DAU to MAU ratio for users from the US, compared to the previous period\n\n```json\n{\n \"kind\": \"TrendsQuery\",\n \"series\": [\n { \"kind\": \"EventsNode\", \"event\": \"$pageview\", \"math\": \"dau\" },\n { \"kind\": \"EventsNode\", \"event\": \"$pageview\", \"math\": \"monthly_active\" }\n ],\n \"dateRange\": { \"date_from\": \"-7d\" },\n \"interval\": \"day\",\n \"properties\": {\n \"type\": \"AND\",\n \"values\": [\n {\n \"type\": \"AND\",\n \"values\": [{ \"key\": \"$geoip_country_name\", \"operator\": \"exact\", \"type\": \"event\", \"value\": [\"United States\"] }]\n }\n ]\n },\n \"compareFilter\": { \"compare\": true },\n \"trendsFilter\": { \"display\": \"ActionsLineGraph\", \"formula\": \"A/B\", \"aggregationAxisFormat\": \"percentage_scaled\" }\n}\n```\n\n## Unique users and first-time users for \"insight created\" over the last 12 months\n\n```json\n{\n \"kind\": \"TrendsQuery\",\n \"series\": [\n { \"kind\": \"EventsNode\", \"event\": \"insight created\", \"math\": \"dau\" },\n { \"kind\": \"EventsNode\", \"event\": \"insight created\", \"math\": \"first_time_for_user\" }\n ],\n \"dateRange\": { \"date_from\": \"-12m\" },\n \"interval\": \"month\",\n \"filterTestAccounts\": true,\n \"trendsFilter\": { \"display\": \"ActionsLineGraph\" }\n}\n```\n\n## P99, P95, and median of a \"refreshAge\" property on \"viewed dashboard\" events\n\n```json\n{\n \"kind\": \"TrendsQuery\",\n \"series\": [\n { \"kind\": \"EventsNode\", \"event\": \"viewed dashboard\", \"math\": \"p99\", \"math_property\": \"refreshAge\" },\n { \"kind\": \"EventsNode\", \"event\": \"viewed dashboard\", \"math\": \"p95\", \"math_property\": \"refreshAge\" },\n { \"kind\": \"EventsNode\", \"event\": \"viewed dashboard\", \"math\": \"median\", \"math_property\": \"refreshAge\" }\n ],\n \"dateRange\": { \"date_from\": \"yStart\" },\n \"interval\": \"month\",\n \"filterTestAccounts\": true,\n \"trendsFilter\": { \"display\": \"ActionsLineGraph\", \"aggregationAxisFormat\": \"duration\" }\n}\n```\n\n## Organizations that signed up from Google in the last 30 days (group aggregation)\n\n```json\n{\n \"kind\": \"TrendsQuery\",\n \"series\": [\n {\n \"kind\": \"EventsNode\",\n \"event\": \"user signed up\",\n \"math\": \"unique_group\",\n \"math_group_type_index\": 0,\n \"properties\": [{ \"key\": \"is_organization_first_user\", \"operator\": \"exact\", \"type\": \"person\", \"value\": [\"true\"] }]\n }\n ],\n \"dateRange\": { \"date_from\": \"-30d\" },\n \"interval\": \"day\",\n \"properties\": {\n \"type\": \"AND\",\n \"values\": [\n {\n \"type\": \"OR\",\n \"values\": [{ \"key\": \"$initial_utm_source\", \"operator\": \"exact\", \"type\": \"person\", \"value\": [\"google\"] }]\n }\n ]\n },\n \"trendsFilter\": { \"display\": \"ActionsLineGraph\" }\n}\n```\n\n# Reminders\n\n- Ensure that any properties included are directly relevant to the context and objectives of the user's question. Avoid unnecessary or unrelated details.\n- Avoid overcomplicating the response with excessive property filters. Focus on the simplest solution.\n- When using group aggregations (unique groups), always set `math_group_type_index` to the appropriate group type index from the group mapping.\n- Visualization settings (display type, axis format, etc.) should only be specified when explicitly requested or when they significantly improve the answer.",
"category": "Query wrappers",
diff --git a/services/mcp/src/api/client.ts b/services/mcp/src/api/client.ts
index 9e0c10fff08d..3c2c78c8c741 100644
--- a/services/mcp/src/api/client.ts
+++ b/services/mcp/src/api/client.ts
@@ -1253,6 +1253,10 @@ export class ApiClient {
const select = ['person', ...Array.from({ length: count }, (_, i) => `${period}_${i}`)]
return runActorsQuery(query, select, ['length(appearances) DESC', 'actor_id'])
},
+
+ // Stickiness drills into one bar (`day` = active-interval count). The runner projects only
+ // `actor_id` with no `matching_events`, so there is no recordings column — same as lifecycle.
+ stickinessActors: async ({ query }: { query: Record<string, unknown> }) => runActorsQuery(query, ['actor']),
}
}
diff --git a/services/mcp/src/tools/generated/query-wrappers.ts b/services/mcp/src/tools/generated/query-wrappers.ts
index 68ab52a0bb45..49a8b444553b 100644
--- a/services/mcp/src/tools/generated/query-wrappers.ts
+++ b/services/mcp/src/tools/generated/query-wrappers.ts
@@ -1303,6 +1303,21 @@ const AssistantRetentionActorsQuery = z.object({
source: AssistantRetentionQuery.describe('The source retention insight query whose cohort we are drilling into.'),
})
+const AssistantStickinessActorsQuery = z.object({
+ compare: z
+ .enum(['current', 'previous'])
+ .describe('Whether to pull from the previous period when `compareFilter` is enabled in the source.')
+ .optional(),
+ day: integer.describe(
+ "The number of active intervals to drill into — the X-axis value of the stickiness bar. Despite the name, this is an interval **count**, not a date: for a daily insight, `day: 13` lists the users who were active on exactly 13 days within the source's date range."
+ ),
+ kind: z.literal('InsightActorsQuery').default('InsightActorsQuery'),
+ series: integer
+ .describe('0-based index of the series to drill into when the source has multiple series. Defaults to 0.')
+ .optional(),
+ source: AssistantStickinessQuery.describe('The source stickiness insight query whose bar we are drilling into.'),
+})
+
const QueryTrendsSchema = AssistantTrendsQuery.extend({
output_format: z
.enum(['optimized', 'json'])
@@ -1403,6 +1418,16 @@ const QueryRetentionActorsSchema = AssistantRetentionActorsQuery.extend({
),
})
+const QueryStickinessActorsSchema = AssistantStickinessActorsQuery.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>>> = {
@@ -1488,4 +1513,11 @@ export const GENERATED_TOOLS: Record<string, ReturnType<typeof createQueryWrappe
uiResourceUri: 'ui://posthog/insight-actors.html',
outputFormat: 'optimized',
}),
+ 'query-stickiness-actors': createQueryWrapper({
+ name: 'query-stickiness-actors',
+ schema: QueryStickinessActorsSchema,
+ 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.ts
index c05c740b049b..a780ebcfb433 100644
--- a/services/mcp/src/tools/query-wrapper-factory.ts
+++ b/services/mcp/src/tools/query-wrapper-factory.ts
@@ -69,6 +69,9 @@ export function createQueryWrapper<T extends ZodObjectAny>(config: QueryWrapperC
case 'RetentionQuery':
data = await queryClient.retentionActors({ query })
break
+ case 'StickinessQuery':
+ data = await queryClient.stickinessActors({ query })
+ break
default:
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.ts
index 900c723279e5..a04f0b2975d7 100644
--- a/services/mcp/tests/tools/query-wrappers.integration.test.ts
+++ b/services/mcp/tests/tools/query-wrappers.integration.test.ts
@@ -618,4 +618,46 @@ describe('Query Wrapper Integration Tests', { concurrent: false }, () => {
).rejects.toThrow(/maximum is 32/)
})
})
+
+ describe('query-stickiness-actors', () => {
+ const stickinessSource = {
+ kind: 'StickinessQuery',
+ series: [{ kind: 'EventsNode', event: '$pageview', name: 'Pageview', math: 'dau' }],
+ interval: 'day',
+ dateRange: { date_from: '-30d' },
+ }
+
+ it('returns a flat {columns, rows} table with the actors projection', async () => {
+ const tool = getToolByName(GENERATED_TOOLS, 'query-stickiness-actors')
+ const result = (await tool.handler(context, { source: stickinessSource, day: 1 })) 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 actor projection', async () => {
+ const tool = getToolByName(GENERATED_TOOLS, 'query-stickiness-actors')
+ const result = (await tool.handler(context, { source: stickinessSource, day: 2, series: 0 })) as any
+
+ expect(result.query.kind).toBe('ActorsQuery')
+ expect(result.query.select).toEqual(['actor'])
+ expect(result.query.orderBy).toEqual([])
+ expect(result.query.source.kind).toBe('InsightActorsQuery')
+ expect(result.query.source.day).toBe(2)
+ expect(result.query.source.series).toBe(0)
+ expect(result.query.source.source.kind).toBe('StickinessQuery')
+ expect(result.results.columns).toEqual(['distinct_id', 'email', 'name'])
+ })
+
+ it('does not project a recordings column (membership-based output)', async () => {
+ const tool = getToolByName(GENERATED_TOOLS, 'query-stickiness-actors')
+ const result = (await tool.handler(context, { source: stickinessSource, day: 1 })) as any
+
+ expect(result.query.select).not.toContain('matched_recordings')
+ expect(result.results.columns).not.toContain('recordings')
+ })
+ })
})
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/query-stickiness-actors.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/query-stickiness-actors.json
new file mode 100644
index 000000000000..412bbd31b076
--- /dev/null
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/query-stickiness-actors.json
@@ -0,0 +1,2021 @@
+{
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "properties": {
+ "compare": {
+ "description": "Whether to pull from the previous period when `compareFilter` is enabled in the source.",
+ "enum": ["current", "previous"],
+ "type": "string"
+ },
+ "day": {
+ "description": "The number of active intervals to drill into — the X-axis value of the stickiness bar. Despite the name, this is an interval **count**, not a date: for a daily insight, `day: 13` lists the users who were active on exactly 13 days within the source's date range.",
+ "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"
+ },
+ "series": {
+ "description": "0-based index of the series to drill into when the source has multiple series. Defaults to 0.",
+ "maximum": 9007199254740991,
+ "minimum": -9007199254740991,
+ "type": "integer"
+ },
+ "source": {
+ "description": "The source stickiness insight query whose bar we are drilling into.",
+ "properties": {
+ "aggregation_group_type_index": {
+ "anyOf": [
+ {
+ "maximum": 9007199254740991,
+ "minimum": -9007199254740991,
+ "type": "integer"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Groups aggregation"
+ },
+ "compareFilter": {
+ "description": "Compare to date range. When enabled, shows the current and previous period side by side.",
+ "properties": {
+ "compare": {
+ "default": false,
+ "description": "Whether to compare the current date range to a previous date range.",
+ "type": "boolean"
+ },
+ "compare_to": {
+ "description": "The date range to compare to. The value is a relative date. Examples of relative dates are: `-1y` for 1 year ago, `-14m` for 14 months ago, `-100w` for 100 weeks ago, `-14d` for 14 days ago, `-30h` for 30 hours ago.",
+ "type": "string"
+ }
+ },
+ "type": "object"
+ },
+ "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"
+ },
+ "interval": {
+ "default": "day",
+ "description": "Granularity of the response. Can be one of `hour`, `day`, `week` or `month`. This determines what counts as one \"interval\" for stickiness measurement. For example, with `day` interval over a 30-day range, the X-axis shows 1 through 30 days, and each bar/point shows how many users performed the event on exactly that many days.",
+ "enum": ["second", "minute", "hour", "day", "week", "month"],
+ "type": "string"
+ },
+ "intervalCount": {
+ "description": "How many base intervals comprise one stickiness period. Defaults to 1. For example, `interval: \"day\"` with `intervalCount: 7` groups by 7-day periods.",
+ "maximum": 9007199254740991,
+ "minimum": -9007199254740991,
+ "type": "integer"
+ },
+ "kind": {
+ "const": "StickinessQuery",
+ "default": "StickinessQuery",
+ "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"
+ },
+ "series": {
+ "description": "Events or actions to include. Each series measures how many intervals (e.g. days) within the date range a user performed the event. Prioritize the more popular and fresh events and actions. When the `math` field is omitted on a series, it defaults to counting unique persons.",
+ "items": {
+ "anyOf": [
+ {
+ "properties": {
+ "custom_name": {
+ "type": "string"
+ },
+ "event": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "The event or `null` for all events."
+ },
+ "kind": {
+ "const": "EventsNode",
+ "default": "EventsNode",
+ "type": "string"
+ },
+ "math": {
+ "anyOf": [
+ {
+ "enum": [
+ "total",
+ "dau",
+ "weekly_active",
+ "monthly_active",
+ "unique_session",
+ "first_time_for_user",
+ "first_matching_event_for_user"
+ ],
+ "type": "string"
+ },
+ {
+ "enum": [
+ "total",
+ "first_time_for_user",
+ "first_time_for_user_with_filters"
+ ],
+ "type": "string"
+ },
+ {
+ "enum": [
+ "avg",
+ "sum",
+ "min",
+ "max",
+ "median",
+ "p75",
+ "p90",
+ "p95",
+ "p99"
+ ],
+ "type": "string"
+ },
+ {
+ "enum": [
+ "avg_count_per_actor",
+ "min_count_per_actor",
+ "max_count_per_actor",
+ "median_count_per_actor",
+ "p75_count_per_actor",
+ "p90_count_per_actor",
+ "p95_count_per_actor",
+ "p99_count_per_actor"
+ ],
+ "type": "string"
+ },
+ {
+ "const": "unique_group",
+ "type": "string"
+ },
+ {
+ "const": "hogql",
+ "type": "string"
+ },
+ {
+ "enum": [
+ "total",
+ "sum",
+ "unique_session",
+ "min",
+ "max",
+ "avg",
+ "dau",
+ "unique_group",
+ "hogql"
+ ],
+ "type": "string"
+ },
+ {
+ "enum": ["total", "dau"],
+ "type": "string"
+ }
+ ]
+ },
+ "math_group_type_index": {
+ "anyOf": [
+ {
+ "const": 0,
+ "type": "number"
+ },
+ {
+ "const": 1,
+ "type": "number"
+ },
+ {
+ "const": 2,
+ "type": "number"
+ },
+ {
+ "const": 3,
+ "type": "number"
+ },
+ {
+ "const": 4,
+ "type": "number"
+ }
+ ]
+ },
+ "math_hogql": {
+ "description": "Custom HogQL expression for aggregation. Use when the predefined `math` types are not sufficient. When set, `math` must be set to `hogql`.\n\nExamples:\n- Sum a numeric property: `sum(toFloat(properties.$revenue))`\n- Average of a property: `avg(toFloat(properties.load_time))`\n- Count distinct values: `count(distinct properties.$session_id)`\n- Conditional count: `countIf(toFloat(properties.duration) > 30)`\n- Percentile: `quantile(0.95)(toFloat(properties.response_time))`",
+ "type": "string"
+ },
+ "math_multiplier": {
+ "type": "number"
+ },
+ "math_property": {
+ "type": "string"
+ },
+ "math_property_type": {
+ "type": "string"
+ },
+ "name": {
+ "type": "string"
+ },
+ "properties": {
+ "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": "object"
+ },
+ {
+ "properties": {
+ "custom_name": {
+ "type": "string"
+ },
+ "id": {
+ "maximum": 9007199254740991,
+ "minimum": -9007199254740991,
+ "type": "integer"
+ },
+ "kind": {
+ "const": "ActionsNode",
+ "default": "ActionsNode",
+ "type": "string"
+ },
+ "math": {
+ "anyOf": [
+ {
+ "enum": [
+ "total",
+ "dau",
+ "weekly_active",
+ "monthly_active",
+ "unique_session",
+ "first_time_for_user",
+ "first_matching_event_for_user"
+ ],
+ "type": "string"
+ },
+ {
+ "enum": [
+ "total",
+ "first_time_for_user",
+ "first_time_for_user_with_filters"
+ ],
+ "type": "string"
+ },
+ {
+ "enum": [
+ "avg",
+ "sum",
+ "min",
+ "max",
+ "median",
+ "p75",
+ "p90",
+ "p95",
+ "p99"
+ ],
+ "type": "string"
+ },
+ {
+ "enum": [
+ "avg_count_per_actor",
+ "min_count_per_actor",
+ "max_count_per_actor",
+ "median_count_per_actor",
+ "p75_count_per_actor",
+ "p90_count_per_actor",
+ "p95_count_per_actor",
+ "p99_count_per_actor"
+ ],
+ "type": "string"
+ },
+ {
+ "const": "unique_group",
+ "type": "string"
+ },
+ {
+ "const": "hogql",
+ "type": "string"
+ },
+ {
+ "enum": [
+ "total",
+ "sum",
+ "unique_session",
+ "min",
+ "max",
+ "avg",
+ "dau",
+ "unique_group",
+ "hogql"
+ ],
+ "type": "string"
+ },
+ {
+ "enum": ["total", "dau"],
+ "type": "string"
+ }
+ ]
+ },
+ "math_group_type_index": {
+ "anyOf": [
+ {
+ "const": 0,
+ "type": "number"
+ },
+ {
+ "const": 1,
+ "type": "number"
+ },
+ {
+ "const": 2,
+ "type": "number"
+ },
+ {
+ "const": 3,
+ "type": "number"
+ },
+ {
+ "const": 4,
+ "type": "number"
+ }
+ ]
+ },
+ "math_hogql": {
+ "description": "Custom HogQL expression for aggregation. Use when the predefined `math` types are not sufficient. When set, `math` must be set to `hogql`.\n\nExamples:\n- Sum a numeric property: `sum(toFloat(properties.$revenue))`\n- Average of a property: `avg(toFloat(properties.load_time))`\n- Count distinct values: `count(distinct properties.$session_id)`\n- Conditional count: `countIf(toFloat(properties.duration) > 30)`\n- Percentile: `quantile(0.95)(toFloat(properties.response_time))`",
+ "type": "string"
+ },
+ "math_multiplier": {
+ "type": "number"
+ },
+ "math_property": {
+ "type": "string"
+ },
+ "math_property_type": {
+ "type": "string"
+ },
+ "name": {
+ "description": "Action name from the plan.",
+ "type": "string"
+ },
+ "properties": {
+ "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"
+ }
+ },
+ "required": ["id", "name"],
+ "type": "object"
+ }
+ ]
+ },
+ "type": "array"
+ },
+ "stickinessFilter": {
+ "description": "Properties specific to the stickiness insight",
+ "properties": {
+ "computedAs": {
+ "default": "non_cumulative",
+ "description": "Computation mode. `non_cumulative` (default) shows users active on exactly N intervals. `cumulative` shows users active on N or more intervals.",
+ "enum": ["non_cumulative", "cumulative"],
+ "type": "string"
+ },
+ "display": {
+ "default": "ActionsLineGraph",
+ "description": "Visualization type for the stickiness chart. `ActionsLineGraph` - line chart (default). `ActionsBar` - bar chart. `ActionsAreaGraph` - area chart.",
+ "enum": ["ActionsLineGraph", "ActionsBar", "ActionsAreaGraph"],
+ "type": "string"
+ },
+ "showLegend": {
+ "default": false,
+ "description": "Whether to show the legend describing series.",
+ "type": "boolean"
+ },
+ "showValuesOnSeries": {
+ "default": false,
+ "description": "Whether to show a value on each data point.",
+ "type": "boolean"
+ },
+ "stickinessCriteria": {
+ "description": "Filter which intervals count based on event frequency within each interval. For example, only count intervals where the user performed the event >= 3 times.",
+ "properties": {
+ "operator": {
+ "enum": ["gte", "lte", "exact"],
+ "type": "string"
+ },
+ "value": {
+ "maximum": 9007199254740991,
+ "minimum": -9007199254740991,
+ "type": "integer"
+ }
+ },
+ "required": ["operator", "value"],
+ "type": "object"
+ }
+ },
+ "type": "object"
+ }
+ },
+ "required": ["series"],
+ "type": "object"
+ }
+ },
+ "required": ["day", "source"],
+ "type": "object"
+}
diff --git a/services/mcp/tests/unit/query-wrapper-factory.test.ts b/services/mcp/tests/unit/query-wrapper-factory.test.ts
index 3e8b36cf222b..7a42ab7841b2 100644
--- a/services/mcp/tests/unit/query-wrapper-factory.test.ts
+++ b/services/mcp/tests/unit/query-wrapper-factory.test.ts
@@ -95,6 +95,7 @@ describe('createQueryWrapper _posthogUrl', () => {
lifecycleActors: ReturnType<typeof vi.fn>
pathsActors: ReturnType<typeof vi.fn>
retentionActors: ReturnType<typeof vi.fn>
+ stickinessActors: ReturnType<typeof vi.fn>
} {
const actorsResponse = {
query: { kind: 'ActorsQuery', source: { kind: 'InsightActorsQuery' } },
@@ -106,14 +107,21 @@ describe('createQueryWrapper _posthogUrl', () => {
const lifecycleActors = vi.fn().mockResolvedValue(actorsResponse)
const pathsActors = vi.fn().mockResolvedValue(actorsResponse)
const retentionActors = vi.fn().mockResolvedValue(actorsResponse)
+ const stickinessActors = vi.fn().mockResolvedValue(actorsResponse)
const context = {
api: {
- query: vi.fn().mockReturnValue({ trendsActors, lifecycleActors, pathsActors, retentionActors }),
+ query: vi.fn().mockReturnValue({
+ trendsActors,
+ lifecycleActors,
+ pathsActors,
+ retentionActors,
+ stickinessActors,
+ }),
getProjectBaseUrl: vi.fn().mockReturnValue('http://localhost:8010/project/1'),
},
stateManager: { getProjectId: vi.fn().mockResolvedValue('1') },
} as unknown as Context
- return { context, trendsActors, lifecycleActors, pathsActors, retentionActors }
+ return { context, trendsActors, lifecycleActors, pathsActors, retentionActors, stickinessActors }
}
const actorsSchema = z.object({
@@ -121,50 +129,29 @@ describe('createQueryWrapper _posthogUrl', () => {
source: z.looseObject({ kind: z.string() }),
})
- it('dispatches TrendsQuery source to trendsActors', async () => {
- const { context, trendsActors, lifecycleActors } = createActorsDispatchContext()
+ const ACTOR_HANDLERS = [
+ 'trendsActors',
+ 'lifecycleActors',
+ 'pathsActors',
+ 'retentionActors',
+ 'stickinessActors',
+ ] as const
+
+ it.each([
+ ['TrendsQuery', 'trendsActors'],
+ ['LifecycleQuery', 'lifecycleActors'],
+ ['PathsQuery', 'pathsActors'],
+ ['RetentionQuery', 'retentionActors'],
+ ['StickinessQuery', 'stickinessActors'],
+ ] as const)('dispatches %s source to %s and no other handler', async (sourceKind, expectedHandler) => {
+ const ctx = createActorsDispatchContext()
const tool = createQueryWrapper({ name: 'test', schema: actorsSchema, kind: 'InsightActorsQuery' })()
- const result = (await tool.handler(context, { source: { kind: 'TrendsQuery' } })) as any
-
- expect(trendsActors).toHaveBeenCalledOnce()
- expect(lifecycleActors).not.toHaveBeenCalled()
- expect(result._posthogUrl).toContain('DataTableNode')
- })
-
- it('dispatches LifecycleQuery source to lifecycleActors', async () => {
- const { context, trendsActors, lifecycleActors } = createActorsDispatchContext()
- const tool = createQueryWrapper({ name: 'test', schema: actorsSchema, kind: 'InsightActorsQuery' })()
-
- const result = (await tool.handler(context, { source: { kind: 'LifecycleQuery' } })) as any
-
- expect(lifecycleActors).toHaveBeenCalledOnce()
- expect(trendsActors).not.toHaveBeenCalled()
- expect(result._posthogUrl).toContain('DataTableNode')
- })
+ const result = (await tool.handler(ctx.context, { source: { kind: sourceKind } })) as any
- it('dispatches PathsQuery source to pathsActors', async () => {
- const { context, trendsActors, lifecycleActors, pathsActors } = createActorsDispatchContext()
- const tool = createQueryWrapper({ name: 'test', schema: actorsSchema, kind: 'InsightActorsQuery' })()
-
- const result = (await tool.handler(context, { source: { kind: 'PathsQuery' } })) as any
-
- expect(pathsActors).toHaveBeenCalledOnce()
- expect(trendsActors).not.toHaveBeenCalled()
- expect(lifecycleActors).not.toHaveBeenCalled()
- 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()
+ for (const handler of ACTOR_HANDLERS) {
+ expect(ctx[handler]).toHaveBeenCalledTimes(handler === expectedHandler ? 1 : 0)
+ }
expect(result._posthogUrl).toContain('DataTableNode')
})
@@ -338,8 +325,8 @@ describe('createQueryWrapper actors dispatch', () => {
const factory = createQueryWrapper({ name: 'test', schema: actorsSchema, kind: 'InsightActorsQuery' })
const tool = factory()
- await expect(tool.handler(context, { source: { kind: 'StickinessQuery' } })).rejects.toThrow(
- 'Unsupported source kind for actors query: StickinessQuery'
+ await expect(tool.handler(context, { source: { kind: 'FunnelsQuery' } })).rejects.toThrow(
+ 'Unsupported source kind for actors query: FunnelsQuery'
)
})
})