Model Context Protocol (MCP)

The PostHog Model Context Protocol (MCP) server is a free, hosted endpoint that lets your AI agent use PostHog – with just plain text questions your agents can ship a feature flag from a prompt, dig into a stack trace without leaving your editor, run a HogQL query through Claude, triage a support ticket, set up a CDP destination, and much more.

It works with any MCP-compatible client, including PostHog Desktop, Claude Code, Codex, Grok Build, Claude Desktop, VS Code, and Zed.

Connecting to the MCP server and calling its MCP tools is free, but some MCP tools use LLMs internally and may be billed as PostHog AI spend. These AI-powered MCP tools are only available when AI data processing is enabled in your organization settings.

Get started in 30 seconds

The fastest way to setup the MCP is the PostHog Wizard, which installs the MCP server directly into PostHog Desktop, Cursor, Claude Code, Claude Desktop, Codex, VS Code, and Zed:

Install the PostHog MCP

Learn more
npx @posthog/wizard mcp add

Supports Next.js, React, Python, and

Using something else? Pick your client to set it up manually:

Code editors

Platforms

The server URL is https://mcp.posthog.com/mcp. The PostHog authentication server automatically routes you to the correct data region (US or EU) based on the account you log in with.

What can you do with the PostHog MCP?

Using Claude Code to debug and fix errors via the PostHog MCP server

Once connected, your agent can read and write across PostHog's products. Here's a taste – triaging errors from inside your editor instead of context-switching to a browser:

"What are the top 5 errors in my project this week?" – Returns error groups ranked by occurrence with affected user counts.

"Show me the full stack trace for the most recent crash, then propose a fix." – Pulls the stack trace, error message, and metadata so the agent can suggest code changes.

"Mark this issue as resolved and assign all future TypeErrors to the backend team." – Updates issue status and creates an assignment rule in one go.

For more example prompts, including multi-step recipes that chain several products together, see the use cases.

Browse all use cases →

What your agent can do in each product

Each product below links to a guide for using it over MCP.

ProductWhat your agent can do
Product AnalyticsQuery trends, funnels, retention, and custom SQL. Create and update saved insights and dashboards.
Web AnalyticsCheck traffic after a deploy, investigate a drop, audit UTM tagging, and read a page's heatmap.
Session ReplayFind and read sessions to investigate a bug report or confirm a fix.
Replay VisionCreate scanners, scan sessions on demand, and read and search the results.
Feature FlagsCreate flags, configure targeting rules, check rollout status, and schedule changes.
ExperimentsCreate an experiment, launch it, read its results, and end it.
Error TrackingTriage issues, read stack traces, update issue status, and link issues to GitHub, GitLab, Linear, or Jira.
LogsSearch, filter, and analyze log data.
SurveysCreate, launch, and stop surveys. Read responses and summarize open-text answers.
AI ObservabilityQuery LLM traces, check costs, monitor errors, and analyze model performance.
Data WarehouseRun SQL queries, manage views, sync import sources, and annotate tables and columns.
Semantic layerRun governed metrics, so every agent session uses the same definition for a metric like MRR.
EndpointsCreate and run endpoints, manage their versions, and read their execution logs.
Data PipelinesBuild destinations and transformations, test them against real events, debug running functions, and manage batch exports.
WorkflowsWrite and send emails, build broadcasts and automations, and see how each email performed.
SupportList and update tickets, and fill in reply macros for the current ticket.
MCP AnalyticsInvestigate tool usage and failures in your own MCP server.
AI wizardInstall PostHog in a GitHub repository. The wizard makes the code changes and opens a pull request.

The server also has MCP tools for dashboards, notebooks, cohorts, alerts, access control, billing, and more. The MCP tools reference lists every MCP tool, grouped by category.

When to use the PostHog MCP server

Use the PostHog MCP server when:

  • Your product data is in PostHog, or you're deciding where to put it
  • You want one MCP server for Product Analytics, Feature Flags, Experiments, Error Tracking, Session Replay, and Support, instead of one server per tool
  • Your agent needs to act, not only read – for example, to create a flag, start an experiment, resolve an error, or write a survey

It's not a good fit when:

  • Your data is in another analytics tool that you don't plan to send to PostHog – the server only works with PostHog projects
  • You need bulk data exports – the server has rate limits, so use batch exports or Endpoints instead

Control what your agent can do

Agents can write to your project and can follow instructions hidden in untrusted data (prompt injection), so review MCP tool calls before they run. To limit what an agent can do, use:

  • Read-only mode – Remove every MCP tool that creates, updates, or deletes data
  • MCP tool filtering – Limit the session to specific feature categories or named MCP tools
  • Project restrictions – Limit the login to specific projects. Pinning a connection to a project only sets the agent's starting context – it can still switch to any project the login can access

Go deeper

  • Use cases – 20+ example prompts and multi-step recipes for the most useful MCP workflows
  • MCP tools reference – every MCP tool the server exposes, grouped by category
  • FAQ and advanced setup – auth, scoping, filtering, safety, and other operational details

Next steps

Still have questions?

Was this page useful?