:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(mcp): offer an alert after creating an insight (#71968)
Vasco de Krijger3c8745ac4731
diff --git a/products/product_analytics/mcp/tools.yaml b/products/product_analytics/mcp/tools.yamlindex 641de13d8bee..527a1f3c6ce5 100644--- a/products/product_analytics/mcp/tools.yaml+++ b/products/product_analytics/mcp/tools.yaml@@ -109,6 +109,18 @@ tools:A bare query is accepted too. `{ "kind": "TrendsQuery", ... }` and `{ "kind": "HogQLQuery", ... }` are eachwrapped for you, so a query you just ran through one of the `query-*` tools can be passed straight through.+ agent_note:+ After creating a Trends, SQL (HogQL), Funnels or Metrics insight, call insight-query with the returned+ short_id, read the current value, and offer an alert when the metric is one someone would act on if it moved+ sharply (signups, active users, revenue, conversion rate, error or failure counts, latency). Name an actual+ number, never a placeholder such as X, for example "want me to alert you when daily signups drop below+ 400?". A count sitting at zero, such as errors or failures, is a strong case, so offer an upper bound of 1.+ Offer nothing when the insight returned no rows. When no absolute number fits and the insight supports it,+ offer a relative-change alert on a sudden increase or decrease. Skip metrics nobody acts on, such as raw+ pageview or event-volume counts, and skip high-cardinality breakdowns. Judge the metric, not the request. A+ newly created insight, or one the user just asked to see, is not throwaway for that reason. If the user+ already declined an alert in this conversation, do not offer again. If alert-create is unavailable, say+ nothing about alerts. Wait for the user to accept before creating an alert.exclude_params:- queryinclude_params:diff --git a/services/mcp/src/tools/generated/product_analytics.ts b/services/mcp/src/tools/generated/product_analytics.tsindex c76ecc2e1b03..1a53e374f58c 100644--- a/services/mcp/src/tools/generated/product_analytics.ts+++ b/services/mcp/src/tools/generated/product_analytics.ts@@ -272,7 +272,10 @@ const InsightCreateSchema = () => {})}-const insightCreate = (): ToolBase<ReturnType<typeof InsightCreateSchema>, WithPostHogUrl<Schemas.Insight>> => ({+const insightCreate = (): ToolBase<+ ReturnType<typeof InsightCreateSchema>,+ WithAgentNote<WithPostHogUrl<Schemas.Insight>>+> => ({name: 'insight-create',schema: InsightCreateSchema(),handler: async (context: Context, params: z.infer<ReturnType<typeof InsightCreateSchema>>) => {@@ -310,7 +313,10 @@ const insightCreate = (): ToolBase<ReturnType<typeof InsightCreateSchema>, WithP'hogql','types',]) as typeof result- return await withPostHogUrl(context, filtered, `/insights/${filtered.short_id}`)+ return withAgentNote(+ await withPostHogUrl(context, filtered, `/insights/${filtered.short_id}`),+ 'After creating a Trends, SQL (HogQL), Funnels or Metrics insight, call insight-query with the returned short_id, read the current value, and offer an alert when the metric is one someone would act on if it moved sharply (signups, active users, revenue, conversion rate, error or failure counts, latency). Name an actual number, never a placeholder such as X, for example "want me to alert you when daily signups drop below 400?". A count sitting at zero, such as errors or failures, is a strong case, so offer an upper bound of 1. Offer nothing when the insight returned no rows. When no absolute number fits and the insight supports it, offer a relative-change alert on a sudden increase or decrease. Skip metrics nobody acts on, such as raw pageview or event-volume counts, and skip high-cardinality breakdowns. Judge the metric, not the request. A newly created insight, or one the user just asked to see, is not throwaway for that reason. If the user already declined an alert in this conversation, do not offer again. If alert-create is unavailable, say nothing about alerts. Wait for the user to accept before creating an alert.'+ )},})