Back to MCP Servers

PostHog MCP Server

Official PostHog MCP server for querying product analytics, feature flags, experiments, session replays, surveys, error tracking, and SQL across your PostHog projects.

Analytics by PostHog OAuth2 active
Overview

The PostHog MCP server is a provider-hosted remote server that lets AI agents interact directly with a PostHog workspace. It exposes the full PostHog API surface as MCP tools, covering product analytics (trends, funnels, retention, paths, lifecycle, stickiness), feature flags, A/B experiments, cohorts, dashboards, insights, surveys, annotations, alerts, persons, error tracking, logs, notebooks, session replays, web analytics, data warehouse sources, and HogQL/SQL execution.

The server lives at https://mcp.posthog.com/mcp and automatically routes to the correct data region (US or EU) based on the authenticated user. Authentication uses OAuth2 for supported clients (Cursor, Claude, VS Code, Zed, etc.) or a personal API key via a Bearer token header for clients without OAuth. Tools can be filtered per request using ?features= (feature categories like flags,dashboards,insights) or ?tools= (explicit tool names), and access can be pinned to a specific organization or project via x-posthog-organization-id and x-posthog-project-id headers.

The server is free to use, connection and tool invocations do not incur PostHog billing charges, and queries execute directly against the PostHog project without intermediate storage. The original standalone repo at github.com/PostHog/mcp has been archived and folded into the main PostHog monorepo under services/mcp.

Tools

Tool Description
query-run Execute trends, funnels, retention, paths, lifecycle, stickiness, or HogQL queries against PostHog events.
execute-sql Run a HogQL/SQL query directly against PostHog data.
query-generate-hogql-from-question Generate a HogQL query from a natural language question.
create-feature-flag Create a feature flag with rollout percentage or multivariate variants.
feature-flag-get-all List all feature flags in the project.
update-feature-flag Update an existing feature flag's configuration or rollout.
experiment-create Create an A/B test experiment with variants and metrics.
experiment-launch Launch a configured experiment.
experiment-results-get Retrieve results for a running or completed experiment.
cohorts-create Create a dynamic or static cohort of users.
cohorts-list List all cohorts in the project.
cohorts-add-persons-to-static-cohort-partial-update Add specific persons to a static cohort.
dashboard-create Create a new dashboard.
dashboard-get Get a dashboard's metadata and tiles.
dashboard-insights-run Run all insights on a dashboard and return results.
insight-query Query a saved insight.
survey-create Create a survey for in-product feedback.
survey-stats Get response statistics for a survey.
error-tracking-issues-partial-update Update error tracking issues (assign, suppress, merge).
alert-create Create an alert that fires on insight thresholds.
annotation-create Add a timeline annotation to a project or dashboard.
notebooks-create Create a PostHog notebook.
cdp-functions-create Deploy a CDP/destination function (e.g. Slack webhook on event).
switch-project Switch the active PostHog project for the session.
switch-organization Switch the active PostHog organization for the session.
property-definitions List event and person property definitions in the project.
projects-get Get details about projects available to the user.
Setup Guide

Prerequisites

  • A PostHog account (Cloud US or Cloud EU).
  • For API key auth: a personal API key created in PostHog with the "MCP Server" scope preset.

Quick install (recommended)

The PostHog wizard auto-configures the MCP server for Cursor, Claude Code, Claude Desktop, Codex, VS Code, Windsurf, and Zed:

npx @posthog/wizard@latest mcp add

Manual config (OAuth)

Most MCP clients can connect directly to the remote URL and complete an OAuth flow on first use:

{
  "mcpServers": {
    "posthog": {
      "url": "https://mcp.posthog.com/mcp"
    }
  }
}

Manual config (API key)

For clients without OAuth support, pass a personal API key as a Bearer token:

{
  "mcpServers": {
    "posthog": {
      "url": "https://mcp.posthog.com/mcp",
      "headers": {
        "Authorization": "Bearer phx_your_api_key_here"
      }
    }
  }
}

Optional: pin to an org/project or filter tools

Append query params to filter tools, or add headers to pin scope:

https://mcp.posthog.com/mcp?features=flags,dashboards,insights
https://mcp.posthog.com/mcp?tools=dashboard-get,feature-flag-get-all,execute-sql

Headers:

  • x-posthog-organization-id: pin to a specific organization
  • x-posthog-project-id: pin to a specific project
Use Cases
  • Ask an agent to build and run trends, funnel, retention, or path queries over your event data and return results inline, without writing HogQL by hand.
  • Create, update, and roll out feature flags (including multivariate variants and scheduled changes) directly from Cursor or Claude during a code change.
  • Spin up A/B experiments from a PR description, then check on results and end the experiment when the winning variant is decided.
  • Investigate production issues by combining error tracking, log queries, and session replay tools to find the affected users and root cause.
  • Build cohorts (dynamic or static), create surveys targeted at those cohorts, then pull response stats back into the conversation.
Example Prompts
  • "How many unique users signed up in the last 7 days, broken down by day?"
  • "Create a feature flag called new-checkout-flow rolled out to 20% of users."
  • "Create a multivariate flag homepage-hero-test with control 34%, variant_a 33%, variant_b 33%, and launch an experiment measuring conversion to checkout."
  • "What are the top 5 error tracking issues this week, and which release introduced the most affected one?"
  • "Build a dynamic cohort called power-users for anyone who completed a purchase more than 5 times in the last 30 days, then create a survey targeting them."
Pros
  • Officially built and hosted by PostHog, with no self-hosting or container required.
  • Very broad coverage across product analytics, feature flags, experiments, cohorts, dashboards, surveys, error tracking, logs, and HogQL/SQL.
  • Supports OAuth in addition to personal API keys, with org/project pinning and tool-level filtering via query params.
  • Auto-routes to US or EU PostHog regions and is free to use (no extra billing for MCP calls).
Limitations
  • The full tool surface is very large (hundreds of tools across categories), which can overwhelm an agent's context unless filtered with ?features= or ?tools=.
  • Some clients without remote MCP or OAuth support require manual Bearer token configuration with a personal API key.
  • The historical standalone repo (PostHog/mcp) is archived; source now lives inside the PostHog monorepo, which is less convenient to browse.
Alternatives