Model Context Protocol (MCP)

The PostHog Model Context Protocol (MCP) server enables your AI agents and tools to directly interact with PostHog's products.

Quick install using the PostHog wizard

Besides being able to quickly set up your project using AI, the PostHog Wizard can also install the MCP server directly into Cursor, Claude Code, Claude Desktop, VS Code and Zed.

Terminal
npx @posthog/wizard mcp add

We're working on adding more supported tools to the wizard. If you're using another option, you can manually install our MCP server with the instructions below.

Manual install

Add the MCP configuration to your client. When you first use the MCP server, you'll be prompted to log in to PostHog to authenticate.

EU region users

If your PostHog project is on EU Cloud, use https://mcp-eu.posthog.com/mcp instead.

Run the following command in your shell. The next time you run Claude Code, it will have access to the PostHog MCP.

Terminal
claude mcp add --transport http posthog https://mcp.posthog.com/mcp -s user

Be mindful of prompt injection – LLMs can be tricked into following untrusted commands, so always review tool calls before executing them.

Using an API key instead of OAuth?

If your MCP client doesn't support OAuth, you can authenticate manually:

  1. Create a personal API key using the MCP Server preset (this scopes access to a specific project)
  2. Add the Authorization: Bearer YOUR_API_KEY header to your MCP configuration

Example for Cursor (add to .cursor/mcp.json):

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

Available Tools

Tools trigger actions on behalf of the user based on the goals and information already in the context of the LLM. PostHog tools are also available in our agent toolkit which can be integrated with AI agent frameworks like Vercel's AI SDK and LangChain.

Here's a list of tools we provide:

Actions

ToolPurpose
action-createCreate a new action in the project.
action-deleteDelete an action by ID.
action-getGet a specific action by ID.
action-updateUpdate an existing action.
actions-get-allGet all actions in the project.

Dashboards

ToolPurpose
add-insight-to-dashboardAdd an existing insight to a dashboard.
dashboard-createCreate a new dashboard in the project.
dashboard-deleteDelete a dashboard by ID.
dashboard-getGet a specific dashboard by ID, including insights that are on the dashboard.
dashboard-reorder-tilesReorder tiles on a dashboard.
dashboard-updateUpdate an existing dashboard by ID.
dashboards-get-allGet all dashboards in the project with optional filtering.

Documentation

ToolPurpose
docs-searchSearch the PostHog documentation for information.

Error tracking

ToolPurpose
error-detailsGet the details of an error in the project.
list-errorsList errors in the project.

Events & properties

ToolPurpose
event-definitions-listList all event definitions in the project with optional filtering.
properties-listGet properties for events or persons.

Experiments

ToolPurpose
experiment-createCreate A/B test experiment with guided metric and feature flag setup
experiment-deleteDelete an experiment by ID.
experiment-getGet details of a specific experiment.
experiment-get-allGet all experiments in the project.
experiment-results-getGet comprehensive experiment results including metrics and exposure data.
experiment-updateUpdate an existing experiment with lifecycle management and restart capability.

Feature flags

ToolPurpose
create-feature-flagCreates a new feature flag in the project.
delete-feature-flagDelete a feature flag in the project.
feature-flag-get-allGet all feature flags in the project.
feature-flag-get-definitionGet the definition of a feature flag.
update-feature-flagUpdate a feature flag in the project.

Insights & analytics

ToolPurpose
insight-create-from-querySave a query as an insight.
insight-deleteDelete an insight by ID.
insight-getGet a specific insight by ID.
insight-queryExecute a query on an existing insight to get its results/data.
insight-updateUpdate an existing insight by ID.
insights-get-allGet all insights in the project with optional filtering.
query-generate-hogql-from-questionQueries project's PostHog data based on a provided natural language question.
query-runRun a trend, funnel or HogQL query.

LLM analytics

ToolPurpose
get-llm-total-costs-for-projectFetches the total LLM daily costs for each model for a project over a given number of days.

Logs

ToolPurpose
logs-list-attribute-valuesGet values for a log attribute.
logs-list-attributesList available log attributes.
logs-querySearch and query logs in the project.

Organization & project management

ToolPurpose
organization-details-getGet the details of the active organization.
organizations-getGet the organizations the user has access to.
projects-getFetches projects that the user has access to in the current organization.
property-definitionsGet event and property definitions for the project.
switch-organizationChange the active organization from the default organization.
switch-projectChange the active project from the default project.

Search

ToolPurpose
entity-searchSearch for entities by name or description.

Surveys

ToolPurpose
survey-createCreates a new survey in the project.
survey-deleteDelete a survey by ID.
survey-getGet a specific survey by ID.
survey-statsGet response statistics for a specific survey.
survey-updateUpdate an existing survey by ID.
surveys-get-allGet all surveys in the project with optional filtering.
surveys-global-statsGet aggregated response statistics across all surveys.

Example prompts

Here are some examples of what you can ask your AI agent to do with the PostHog MCP server:

Feature flag management

Prompt: "Create a feature flag called 'new-checkout-flow' that's enabled for 20% of users"

The agent will use the create-feature-flag tool to create the flag with a 20% rollout and return the configuration including the key, rollout percentage, and a link to the flag in PostHog.

Analytics queries

Prompt: "How many unique users signed up in the last 7 days, broken down by day?"

The agent will use the query-run tool to execute a trends query and return daily signup counts.

A/B test creation

Prompt: "Create an A/B test for our pricing page that measures conversion to checkout"

The agent will use experiment-create to set up an experiment with control/test variants and configure a funnel metric measuring pricing page to checkout conversion.

Error investigation

Prompt: "What are the top 5 errors in my project this week?"

The agent will use the list-errors tool to fetch error groups sorted by occurrence count and return details including affected user counts.

Prompts and resources

The MCP server provides resources, including framework-specific documentation and example code, to help agents build great PostHog integrations. You can try these yourself using the posthog:posthog-setup prompt, available via a slash command in your agent. Just hit the / key.

Currently we support Next.js, with more frameworks in progress.

Privacy and support

The MCP server acts as a proxy to your PostHog instance. It does not store your analytics data - all queries are executed against your PostHog project and results are returned directly to your AI client.

Next steps

Community questions

Was this page useful?

Questions about this page? or post a community question.