Build insights with MCP

The PostHog MCP server gives your AI coding agent direct access to PostHog analytics. Query trends, funnels, retention, and custom HogQL – all from your code editor.

This works in any MCP client – Cursor, Codex, Claude Code, Windsurf, VS Code, and others.

How it works

With MCP, your coding agent can:

  • Check feature performance before making code changes – "How many users are using the new search feature this week?"
  • Pull conversion rates into your workflow – "What's the funnel conversion from signup to first project?"
  • Investigate metric changes – "Did the login success rate change after last Tuesday's deploy?"
  • Build insights on demand – "Create a trend showing daily active users broken down by plan"

Analytics tools

The MCP server provides these tools for working with Product Analytics:

ToolDescription
query-runRun any analytics query – trends, funnels, retention, lifecycle, paths, stickiness, or custom HogQL. Returns results directly in your editor.
query-generate-hogql-from-questionGenerate a HogQL query from a natural language question. Useful when you want to inspect or modify the query before running it.
insight-create-from-queryCreate a saved insight from a query and optionally add it to a dashboard.
insight-getGet details for a specific insight by ID.
insights-get-allList all insights in the current project. Filter by name or type.
insight-queryRun the query behind a saved insight and return fresh results.
insight-updateUpdate a saved insight's name, description, or query.
insight-deleteDelete a saved insight.

Example prompts

Try these with your MCP-enabled agent:

  • How is the new checkout flow performing compared to last week?
  • Show me the top 10 events by volume today.
  • Create a funnel from user_signed_up to project_created to insight_viewed.
  • What's the retention rate for users who completed onboarding?
  • Run a HogQL query to find the most active users by event count this month.

Customize chart display

When creating or updating SQL-backed insights (HogQL queries), you can configure per-series display settings and number formatting on each Y-axis column.

Per-series display — set on each Y-axis column under settings.display:

SettingValuesDescription
yAxisPositionleft, rightWhich Y axis the series uses. Use right for a secondary axis.
displayTypeauto, line, bar, areaOverride the chart-level display for this series. Mix types by setting different values per column.
trendLinetrue, falseDraw a linear trend line for the series.
labelstringCustom label shown in the legend and tooltips instead of the column name.
colorhex string (e.g. #1d4aff)Custom color for the series.

Number formatting — set on each Y-axis column under settings.formatting:

SettingValuesDescription
stylenone, number, short, percentNumber format style. number adds thousands separators, short abbreviates (1.2k, 3.4M).
prefixstringText prepended to values (e.g. $).
suffixstringText appended to values (e.g. % or ms).
decimalPlacesnumberNumber of decimal places to display.

Chart-level settings — set on the DataVisualization node:

SettingValuesDescription
showValuesOnSeriestrue, falseShow values on each data point in the chart.

Example prompts:

  • Create a HogQL chart of daily revenue with values formatted as dollars and a trend line.
  • Update insight 123 to show the conversion rate series as a line and the volume series as bars.

Dashboard tools

You can also create and manage dashboards from your editor:

ToolDescription
dashboard-createCreate a new dashboard.
dashboard-getGet a dashboard and its tiles.
dashboards-get-allList all dashboards in the project.
add-insight-to-dashboardAdd an existing insight to a dashboard.
dashboard-updateUpdate a dashboard's name or description.
dashboard-deleteDelete a dashboard.

Install the MCP server

The recommended way to install is with the AI wizard:

Terminal
npx @posthog/wizard mcp add

The wizard supports Claude, Cursor, Windsurf, VS Code, and more. You can also configure it manually.

See the MCP server docs for full setup instructions.

Community questions

Was this page useful?

Questions about this page? or post a community question.