: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
# MCP tool definitions. Tools are opt-in: an operation is exposed only when it has an entry here.
# List operations without an entry: pnpm --filter=@posthog/mcp run scaffold-yaml -- --candidates --product product_analytics
# Add one: pnpm --filter=@posthog/mcp run scaffold-yaml -- --add <operationId> --product product_analytics
# To keep an operation off on purpose, set enabled: false and give a disabled_reason.
category: Product analytics
feature: product_analytics
url_prefix: /insights
ui_apps:
insight-actors:
type: detail
view_prop: data
link_prop: openLink
explain-chart:
type: custom
app_name: PostHog Chart Explanation
description: A trends chart with the moments that stand out highlighted, explained one chapter at a time.
render_ui:
component_import: ../components/ExplainChart
view_component: ExplainChart
view_prop: data
data_type: ExplainChartData
link_prop: openLink
app_prop: app
tools:
elements-stats-retrieve:
operation: elements_stats_retrieve
enabled: true
scopes:
- element:read
annotations:
readOnly: true
destructive: false
idempotent: true
title: Get element click stats
description: >
Counts of autocapture clicks, rage clicks, and dead clicks grouped by page element, ordered by count. Each
result carries the parsed element chain (tag, text, href, attributes) of the clicked element. Filter by date
range, event types, URL or other event/person properties, and the project's internal-test-account filters.
This powers heatmap/clickmap views; use it to answer "what do users click most" and "which elements get rage
or dead clicks". Responses can be very large on busy projects — always pass a small `limit` (e.g. 100) and
paginate with `offset` if you need more results.
insight-create:
operation: insights_create
enabled: true
scopes:
- insight:write
annotations:
readOnly: false
destructive: false
idempotent: false
enrich_url: '{short_id}'
title: Create insight
description: >
Create a new saved insight from a name and query definition. Test queries with query-trends / query-funnel /
query-retention / query-paths / query-stickiness / query-lifecycle first to confirm the shape, then save.
Returns insight metadata only — after creating, call the insight-query tool with the returned `short_id` if
you want to see the computed results.
Put the insight definition in `query.source`, under the wrapper node that matches it. Use
`InsightVizNode` for a product analytics chart, `DataVisualizationNode` for a SQL visualization, and
`DataTableNode` with an `EventsQuery` source for a table of individual events:
```json
{ "name": "Example", "query": { "kind": "DataVisualizationNode", "source": { "kind": "HogQLQuery", "query":
"SELECT 1" } } }
```
Bare `TrendsQuery`, `HogQLQuery`, and `EventsQuery` definitions are accepted too. They are wrapped for you,
so a query you just ran through one of the `query-*` tools can be passed straight through.
A saved SQL insight must follow the dashboard and insight date range. Before you save a `HogQLQuery`,
replace its fixed date window, such as `timestamp >= now() - INTERVAL 30 DAY`, with the `{filters}`
placeholder: `WHERE event = 'signed_up' AND {filters}`. Then put the requested window in
`query.source.filters.dateRange`, for example `{"date_from": "-30d"}`. A fixed window ignores the date
picker, and `{filters}` without a `dateRange` shows all time. `{filters}` also applies the property and
test-account filters. For a table without a `timestamp` column, bind its date column with
`{filters(created_at AS timestamp)}`.
Save a `MetricsQuery` or `MetricsHistogramQuery` bare, as the top-level `query`. Do not put it in an
`InsightVizNode`.
For a PromQL metrics insight, set `language` to `promql`, put the expression in `promql`, and send `clauses`
as an empty list. When query-metrics accepts a `promql` field, test the expression with it first:
```json
{ "name": "Request rate", "query": { "kind": "MetricsQuery", "language": "promql", "promql":
"sum(rate(http_requests_total[5m]))", "clauses": [], "dateRange": { "date_from": "-24h" } } }
```
Choose the TrendsQuery `trendsFilter.display` from the question the insight answers:
- Change over time: `ActionsLineGraph` (default), `ActionsAreaGraph`, or `ActionsBar`.
- Compare breakdown values or series as totals ("top pages", "failures by reason"): `ActionsBarValue`, or
`ActionsPie` for the share of a whole with a few values.
- One number for the period, or this period against the previous one: `Metric` with `compareFilter.compare:
true` for a comparison, or `BoldNumber` when a trend has no meaning.
- Many breakdown rows that a person reads rather than compares: `ActionsTable`.
- Totals per country from a `$geoip_country_code` breakdown: `WorldMap`.
In a TrendsQuery, `ActionsBar` is a time series with one bar per interval and the breakdown values stacked
in each bar. It is not one bar per category. In a SQL `DataVisualizationNode`, `ActionsBar` is one bar per
X-axis value, and `ActionsBarValue` draws the same bars horizontally.
agent_note: >
When you tell the user about this insight, name the display you chose and one or two other displays that
also fit this query, in one short sentence, and offer to change it. If the user agrees, change it with
insight-update. Suggest only displays that the insight kind supports and that fit the question:
- Trends (`trendsFilter.display`): for change over time `ActionsLineGraph`, `ActionsAreaGraph`, `ActionsBar`
or `ActionsUnstackedBar`; for totals per breakdown value or series `ActionsBarValue`, `ActionsPie` or
`ActionsTable`; for one number `Metric` or `BoldNumber`, never with a breakdown or more than one series;
`WorldMap` only for a `$geoip_country_code` breakdown.
- Funnels (`funnelsFilter.funnelVizType`): `steps` for drop-off per step, `trends` for conversion over time,
or `time_to_convert` for how long users take.
- Retention (`retentionFilter.display`): `ActionsLineGraph` or `ActionsBar`.
- Stickiness (`stickinessFilter.display`): `ActionsLineGraph`, `ActionsBar` or `ActionsAreaGraph`.
- Lifecycle: stacked or side-by-side bars (`lifecycleFilter.stacked`).
- SQL (`DataVisualizationNode` `display`): only displays that fit the columns the query returns.
- Paths: suggest nothing.
Use the chart names a person sees, such as "bar chart per category" or "line chart", not enum values or tool
names. If the user named the chart they want, do not suggest others. If you create several insights in this
task, give one short list of alternatives at the end, not one per insight.
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. After substantial visual
changes, check the final saved insight once if browser access is already available. Skip browser checks for
small edits.
exclude_params:
- query
include_params:
- name
- description
- tags
- favorited
- dashboards
param_overrides:
query:
schema_ref: InsightQuery
dashboards:
description: >
Dashboard IDs this insight should belong to. This is a full replacement — always include all
existing dashboard IDs when adding a new one.
description:
description: |
Optional, about 15 words. Omit if the name is enough. No change notes. Max 400 characters.
response:
exclude:
- result
- hasMore
- columns
- is_cached
- query_status
- hogql
- types
insight-delete:
operation: insights_destroy
enabled: true
scopes:
- insight:write
annotations:
readOnly: false
destructive: true
idempotent: true
title: Delete insight
description: |
Soft-delete an insight by ID. The insight will be marked as deleted and no longer appear in lists.
param_overrides:
id:
aliases:
- insightId
- insight_id
- short_id
- shortId
soft_delete: true
insight-get:
operation: insights_retrieve
enabled: true
scopes:
- insight:read
annotations:
readOnly: true
destructive: false
idempotent: true
enrich_url: '{short_id}'
title: Get insight
description: >
Fetch a saved insight by its numeric `id` or 8-character `short_id`. Returns the insight metadata and query
definition, but NOT the query results. To retrieve the actual data, call the insight-query tool with the
same identifier. Optionally accepts `variables_override` and `filters_override` to apply one-off overrides
to the returned query definition without mutating the saved insight.
exclude_params:
- format
- refresh
- from_dashboard
param_overrides:
id:
aliases:
- insightId
- insight_id
- short_id
- shortId
response:
exclude:
- result
- hasMore
- columns
- is_cached
- query_status
- hogql
- types
insight-update:
operation: insights_partial_update
enabled: true
scopes:
- insight:write
annotations:
readOnly: false
destructive: false
idempotent: true
enrich_url: '{short_id}'
title: Update insight
description: >
Update a saved insight by numeric `id` or `short_id`. Can update name, description, query, tags, favorited
status, and dashboards. Returns insight metadata only — after updating the query, call the insight-query
tool with the same identifier if you want to see the recomputed results. Query uses the same format as
insight-create. Replacing query replaces the entire definition; include all filters and visualization
settings you want to retain. After substantial visual changes, check the final saved insight once if browser
access is already available. Skip browser checks for small edits.
agent_note:
If this update added the insight to a dashboard through the `dashboards` field, consider offering the user a
recurring delivery of that dashboard as a next step. `dashboards` is a full replacement, so only offer when
the dashboard id you just added was not already on the insight before this call. Offer at most once per
dashboard in a conversation, however many insights you attach to it. First call subscriptions-list with
`dashboard` set to that dashboard's id, and do not offer a second subscription when it returns one. Say
nothing when this update left `dashboards` alone or only removed the insight from a dashboard. Describe it
the way a person would recognize it, for example a weekly email every Monday morning with these charts
attached, or the same thing posted to a Slack channel. To create it, use subscriptions-create. It needs
`dashboard` set to the dashboard's id, `dashboard_export_insights` listing up to 20 charts, `target_type` of
`email` or `slack`, and `target_value`, `frequency`, `interval` and `start_date`. For a Slack delivery, also
set `integration_id`. Find the connected Slack workspace with integrations-list (filter kind=slack) and the
channel for `target_value` with integrations-channels-retrieve. Ask the user for the recipients and the
cadence rather than choosing them, since this creates a recurring outbound delivery. If either
subscriptions-create or subscriptions-list is not available to you in this session, say nothing about
subscriptions. If the user already declined a subscription earlier in this conversation, do not offer again.
exclude_params:
- query
include_params:
- name
- description
- tags
- favorited
- dashboards
param_overrides:
id:
aliases:
- insightId
- insight_id
- short_id
- shortId
query:
schema_ref: InsightQuery
dashboards:
description: >
Dashboard IDs this insight should belong to. This is a full replacement — always include all
existing dashboard IDs when adding a new one.
description:
description: |
Optional, about 15 words. Omit if the name is enough. No change notes. Max 400 characters.
response:
exclude:
- result
- hasMore
- columns
- is_cached
- query_status
- hogql
- types
insights-activity-retrieve:
operation: insights_activity_retrieve
enabled: true
scopes:
- activity_log:read
annotations:
readOnly: true
destructive: false
idempotent: true
list: true
title: Get insight activity log
description: >
Audit trail for a single insight by numeric `id`. Returns a paginated list of every change made to it
(created, edited, deleted, restored), including who made each change and which fields changed. The full
`before`/`after` diff blobs are omitted to keep responses agent-friendly — to inspect the current state of
the insight after a change, call `insight-get` with the insight's `short_id`. Paginate with `limit` and
`page`.
response:
exclude:
- detail.changes.*.before
- detail.changes.*.after
- detail.trigger
- detail.type
insights-all-activity-retrieve:
operation: insights_all_activity_retrieve
enabled: true
scopes:
- activity_log:read
annotations:
readOnly: true
destructive: false
idempotent: true
list: true
title: Get recent insight activity across the project
description: >
Project-wide audit trail of changes to all insights, most recent first. Returns who created, edited,
deleted, or restored each insight and which fields changed. Useful for surfacing what people (or agents)
have been working on recently. The full `before`/`after` diff blobs are omitted to keep responses
agent-friendly — drill into a specific insight with `insights-activity-retrieve` (or `insight-get` for
current state). Paginate with `limit` and `page`.
response:
exclude:
- detail.changes.*.before
- detail.changes.*.after
- detail.trigger
- detail.type
insights-list:
operation: insights_list
enabled: true
scopes:
- insight:read
annotations:
readOnly: true
destructive: false
idempotent: true
enrich_url: '{short_id}'
list: true
title: Get all insights
description: >
List saved insights in the project with optional filtering by favorited status or search term. Returns
metadata only (name, description, tags, dashboards, ownership) — NOT the query results. To retrieve the
actual data for any insight in the list, call the insight-query tool with its `short_id` or numeric `id`.
exclude_params:
- basic
- format
- refresh
param_overrides:
limit:
cast: string-int
offset:
cast: string-int
response:
include:
- id
- short_id
- name
- derived_name
- description
- tags
- favorited
- dashboards
- created_at
- created_by
- last_modified_at
- last_modified_by
- last_viewed_at
- alerts
insights-trending-retrieve:
operation: insights_trending_retrieve
enabled: true
scopes:
- insight:read
annotations:
readOnly: true
destructive: false
idempotent: true
enrich_url: '{short_id}'
list: true
title: Get most-viewed insights
description: >
Returns the most-viewed insights in the project, ranked by view count over the last N days (default 7). Use
this to surface the insights that matter most to the team — the ones people actually open. Each result
includes standard insight metadata plus `view_count` and up to 3 recent `viewers`. Returns metadata only —
call `insight-query` with the returned `short_id` to fetch the actual data for any of them.
response:
include:
- id
- short_id
- name
- derived_name
- description
- tags
- favorited
- dashboards
- created_at
- created_by
- last_modified_at
- last_modified_by
- last_viewed_at
- view_count
- viewers