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, Codex, 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.

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"
}
}
}
}
Pinning to a specific organization or project?

If you're building a programmatic integration or want to restrict the MCP session to a specific organization or project, you can pin the context using headers or query parameters.

When you pin the context, the switch-organization and switch-project tools are automatically excluded from the available tool list:

  • When projectId is provided: both switch-organization and switch-project are excluded
  • When only organizationId is provided: only switch-organization is excluded

Headers:

  • x-posthog-organization-id - Pin to a specific organization
  • x-posthog-project-id - Pin to a specific project

Query parameters:

  • organization_id - Pin to a specific organization
  • project_id - Pin to a specific project

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",
"x-posthog-organization-id": "your_org_id",
"x-posthog-project-id": "your_project_id"
}
}
}
}
Enabling read-only mode?

Read-only mode restricts the MCP server to only expose tools that don't modify data (i.e., tools annotated with readOnlyHint: true). This is useful when you want to limit an agent to querying and listing data without the ability to create, update, or delete resources.

You can enable read-only mode using a header or query parameter:

Header:

  • x-posthog-readonly - Set to true or 1

Query parameter:

  • readonly - Set to true or 1

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",
"x-posthog-readonly": "true"
}
}
}
}

Available Tools

Tools trigger actions on behalf of the user based on the goals and information already in the context of the LLM.

Here's a list of tools we provide:

Actions

ToolPurpose
action-createCreate action
action-deleteDelete action
action-getGet action
action-updateUpdate action
actions-get-allGet all actions

Activity logs

ToolPurpose
activity-logs-listList activity logs

Alerts

ToolPurpose
alert-createCreate alert
alert-deleteDelete alert
alert-getGet alert
alert-updateUpdate alert
alerts-listList alerts

Annotations

ToolPurpose
annotation-createCreate annotation
annotation-deleteDelete annotation
annotation-retrieveRetrieve annotation
annotations-listList annotations
annotations-partial-updateUpdate annotation

Cohorts

ToolPurpose
cohorts-add-persons-to-static-cohort-partial-updateAdd persons to static cohort
cohorts-createCreate cohort
cohorts-listList all cohorts
cohorts-partial-updateUpdate cohort
cohorts-retrieveGet cohort
cohorts-rm-person-from-static-cohort-partial-updateRemove person from static cohort

Dashboards

ToolPurpose
dashboard-createCreate dashboard
dashboard-deleteDelete dashboard
dashboard-getGet dashboard
dashboard-reorder-tilesReorder dashboard tiles
dashboard-updateUpdate dashboard
dashboards-get-allGet all dashboards

Data schema

ToolPurpose
read-data-schemaExplore the user's events, actions, properties, and property values.
read-data-warehouse-schemaRead core data warehouse schemas and table lists.

Data warehouse

ToolPurpose
warehouse-saved-queries-createCreate saved query
warehouse-saved-queries-destroyDelete saved query
warehouse-saved-queries-listList saved queries
warehouse-saved-queries-materialize-createMaterialize saved query
warehouse-saved-queries-partial-updateUpdate saved query
warehouse-saved-queries-retrieveGet saved query
warehouse-saved-queries-revert-materialization-createRevert materialization
warehouse-saved-queries-run-createRun saved query
warehouse-saved-queries-run-history-retrieveGet run history

Debug

ToolPurpose
debug-mcp-ui-appsDebug tool for testing MCP Apps SDK.

Documentation

ToolPurpose
docs-searchSearch the PostHog documentation for information.

Early access features

ToolPurpose
early-access-feature-createCreate early access feature
early-access-feature-destroyDelete early access feature
early-access-feature-listList early access features
early-access-feature-partial-updateUpdate early access feature
early-access-feature-retrieveGet early access feature

Error tracking

ToolPurpose
error-detailsGet the details of an error in the project.
error-tracking-issues-listList error tracking issues
error-tracking-issues-partial-updateUpdate error tracking issue
error-tracking-issues-retrieveGet error tracking issue
list-errorsList errors in the project.
update-issue-statusUpdate the status of an error tracking issue.

Events & properties

ToolPurpose
event-definition-updateUpdate an event definition's metadata.
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-flagCreate feature flag
delete-feature-flagDelete feature flag
feature-flag-get-allGet all feature flags
feature-flag-get-definitionGet feature flag definition
update-feature-flagUpdate feature flag

Function templates

ToolPurpose
cdp-function-templates-listList function templates
cdp-function-templates-retrieveGet function template

Functions

ToolPurpose
cdp-functions-createCreate function
cdp-functions-deleteDelete function
cdp-functions-invocations-createTest-invoke function
cdp-functions-listList functions
cdp-functions-partial-updateUpdate function
cdp-functions-rearrange-partial-updateReorder transformation execution
cdp-functions-retrieveGet function

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, paths or HogQL query.

LLM analytics

ToolPurpose
evaluation-createCreate a new evaluation.
evaluation-deleteDelete an evaluation.
evaluation-getGet a specific evaluation by ID.
evaluation-runRun an evaluation on a specific event.
evaluation-updateUpdate an evaluation.
evaluations-getList LLM analytics evaluations.
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.

Notebooks

ToolPurpose
notebooks-createCreate notebook
notebooks-destroyDelete notebook
notebooks-listList notebooks
notebooks-partial-updateUpdate notebook
notebooks-retrieveGet notebook

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.

Persons

ToolPurpose
persons-bulk-deleteBulk delete persons
persons-cohorts-retrieveGet person cohorts
persons-listList persons
persons-property-deleteDelete person property
persons-property-setSet person property
persons-retrieveGet person
persons-values-retrieveGet person property values

Prompts

ToolPurpose
prompt-createCreate prompt
prompt-getGet prompt
prompt-listList prompts
prompt-updateUpdate prompt

Reverse proxy

ToolPurpose
proxy-createCreate reverse proxy
proxy-deleteDelete reverse proxy
proxy-getGet reverse proxy details
proxy-listList reverse proxies
proxy-retryRetry reverse proxy provisioning

Search

ToolPurpose
entity-searchSearch for entities by name or description.

SQL

ToolPurpose
execute-sqlExecute an SQL query.

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.

Workflows

ToolPurpose
workflows-getGet workflow
workflows-listList workflows

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.

Multivariate feature flags

Prompt: "Create a multivariate feature flag called 'homepage-hero-test' with three variants: control at 34%, variant_a at 33%, and variant_b at 33%"

The agent will use the create-feature-flag tool with a multivariate configuration to create the flag with multiple variants. Variant rollout percentages must be integers that sum to 100.

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.

Path analysis

Prompt: "What are the most common paths users take after signing up?"

The agent will use the query-run tool with a PathsQuery to analyze user journeys, returning the flow of events users follow after signup.

Prompt: "Show me the navigation paths from the pricing page to checkout"

The agent will execute a paths query with startPoint set to the pricing page and endPoint set to checkout, revealing the most common routes users take.

SQL and HogQL queries

Your AI agent can execute complex HogQL queries to analyze both system data and analytics data in PostHog.

Prompt: "Query my feature flags to find all flags that are rolled out to less than 50% of users"

The agent will use SQL to query the system.feature_flags table and return flags filtered by rollout percentage.

Prompt: "Write a HogQL query to find users who triggered the signup event but didn't complete onboarding in the last 30 days"

The agent will construct and execute a HogQL query against the events table, using subqueries to find users who signed up but are missing the onboarding completion event.

Prompt: "What cohorts contain users who made a purchase in the last week?"

The agent will query system.cohorts and cross-reference with purchase events to identify relevant cohorts.

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.

Log investigation

Prompt: "Show me error logs from the payments service in the last hour"

The agent will use logs-query to search for logs filtered by severity level and service name, returning log entries with timestamps, messages, and trace information.

Prompt management

Prompt: "List all prompts stored in my project"

The agent will use the prompt-list tool to retrieve all team prompts and return a summary with names, versions, and timestamps.

Prompt: "Create a prompt called 'code-reviewer' with instructions for reviewing pull requests"

The agent will use the prompt-create tool to create a new prompt with the specified name and content, making it available for use across all MCP-connected agents in your team.

Prompt: "Get the latest version of my 'support-assistant' prompt"

The agent will use the prompt-get tool to retrieve the full prompt content by name. You can also request a specific version if needed.

Prompt: "Update the 'onboarding-guide' prompt to include a section about feature flags"

The agent will use the prompt-update tool to publish a new version of the prompt with the updated content. The update includes conflict detection to prevent overwriting changes made by others.

Annotation management

Prompt: "Create an annotation for today saying 'Deployed v2.5 with new checkout flow'"

The agent will use the annotation-create tool to create an annotation with the content and date, scoped to your current project. Annotations appear on charts to mark deployments, releases, and other significant changes.

Prompt: "List all annotations from the last month"

The agent will use the annotations-list tool to retrieve annotations, letting you review existing markers on your charts and dashboards.

Prompt: "Add an organization-wide annotation for March 15th marking our company rebrand"

The agent will create an annotation with scope set to organization so it appears across all projects in your organization.

Activity log queries

Prompt: "Show me all recent feature flag changes in the project"

The agent will use the activity-logs-list tool with scope set to FeatureFlag to return recent activity logs showing who created, updated, or deleted feature flags, including the specific fields that changed.

Prompt: "Who made changes to dashboard 42?"

The agent will use the activity-logs-list tool with scope set to Dashboard and item_id set to 42 to return all modifications to that specific dashboard, including who made each change and when.

Prompt: "What has changed in the project recently?"

The agent will use the activity-logs-list tool to return all recent activity across the project, ordered by most recent first, including feature flag updates, insight creations, experiment launches, and other changes.

Alert management

Prompt: "Create a daily alert on my pageview insight that fires when the value exceeds 500"

The agent will use the alert-create tool to create an alert with an absolute threshold. It will set up the alert to monitor the specified insight and notify subscribed users when the threshold is breached.

Prompt: "List all my alerts and show their current state"

The agent will use the alerts-list tool to retrieve all alerts in the project, returning their names, thresholds, current state (firing or not), and check intervals.

Prompt: "Update my pageview alert to fire when the value increases by more than 50% compared to the previous period"

The agent will use the alert-update tool to change the alert condition to a relative increase with a percentage threshold.

Prompt: "Snooze my pageview alert for 2 hours"

The agent will use the alert-update tool to set snoozed_until to temporarily pause notifications.

Prompt: "Delete the old weekly report alert"

The agent will use the alerts-list tool to find the alert by name, then use alert-delete to permanently remove it.

Notebook management

Prompt: "List all notebooks in my project"

The agent will use the notebooks-list tool to retrieve all notebooks and return a summary including titles, short IDs, and creation dates.

Prompt: "Create a new notebook called 'Q1 Analysis' with some initial content"

The agent will use the notebooks-create tool to create a notebook with the specified title and content as a ProseMirror-based JSON document structure.

Prompt: "Update the notebook 'abc123' to add a new section about user retention"

The agent will first use notebooks-retrieve to get the current content and version, then use notebooks-partial-update with the updated content and the correct version number for concurrency control.

Prompt: "Delete the notebook with ID 'xyz789'"

The agent will use the notebooks-destroy tool to soft-delete the notebook by its short_id.

Person management

Prompt: "Find all persons with email containing 'alice@example.com'"

The agent will use the persons-list tool with the email parameter to search for matching persons, returning their properties, distinct IDs, and a link to view them in PostHog.

Prompt: "Get the details for person ID 42 and show me which cohorts they belong to"

The agent will first use persons-retrieve to get the person's full profile, then use persons-cohorts-retrieve to list all cohorts the person is a member of.

Prompt: "Set the 'plan' property to 'enterprise' on the person with distinct_id 'user_abc123'"

The agent will use persons-list to find the person by distinct_id, then use persons-property-set to update their plan property. This is an async operation – the change is queued and processed by PostHog.

Prompt: "Remove the 'legacy_flag' property from person ID 42"

The agent will use persons-property-delete to remove the specified property from the person.

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.