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:
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?
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.
What your agent can do in each product
Each product below links to a guide for using it over MCP.
| Product | What your agent can do |
|---|---|
| Product Analytics | Query trends, funnels, retention, and custom SQL. Create and update saved insights and dashboards. |
| Web Analytics | Check traffic after a deploy, investigate a drop, audit UTM tagging, and read a page's heatmap. |
| Session Replay | Find and read sessions to investigate a bug report or confirm a fix. |
| Replay Vision | Create scanners, scan sessions on demand, and read and search the results. |
| Feature Flags | Create flags, configure targeting rules, check rollout status, and schedule changes. |
| Experiments | Create an experiment, launch it, read its results, and end it. |
| Error Tracking | Triage issues, read stack traces, update issue status, and link issues to GitHub, GitLab, Linear, or Jira. |
| Logs | Search, filter, and analyze log data. |
| Surveys | Create, launch, and stop surveys. Read responses and summarize open-text answers. |
| AI Observability | Query LLM traces, check costs, monitor errors, and analyze model performance. |
| Data Warehouse | Run SQL queries, manage views, sync import sources, and annotate tables and columns. |
| Semantic layer | Run governed metrics, so every agent session uses the same definition for a metric like MRR. |
| Endpoints | Create and run endpoints, manage their versions, and read their execution logs. |
| Data Pipelines | Build destinations and transformations, test them against real events, debug running functions, and manage batch exports. |
| Workflows | Write and send emails, build broadcasts and automations, and see how each email performed. |
| Support | List and update tickets, and fill in reply macros for the current ticket. |
| MCP Analytics | Investigate tool usage and failures in your own MCP server. |
| AI wizard | Install 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
- PostHog CLI: Use PostHog from your terminal, coding agents, scripts, and CI/CD pipelines
- PostHog AI plugin: Install PostHog as a plugin for Claude Code, Codex, Cursor, and Gemini CLI
- Lovable integration: Set up PostHog in your Lovable project
- Replit integration: Set up PostHog with Replit Agent
- v0 integration: Set up PostHog with v0 and the Vercel Flags SDK
- PostHog MCP server on GitHub: The source for the MCP server
- PostHog VS Code extension: Inline analytics, flag management, and session replay links in your editor
- Model Context Protocol: Learn more about the MCP specification
- MCP: machine/copy paste: What exactly is MCP again?





