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.
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
Start by getting a personal API key using the MCP Server preset here.
This lets you add the MCP configuration to any desktop client you use, such as Cursor, Windsurf, or Claude Desktop.
In all examples, make sure to replace the highlighted POSTHOG_AUTH_HEADER
environment variable placeholder with the personal API key you obtained in the first step.
Run the following command in your shell. The next time you run Claude Code, it will have access to the PostHog MCP.
claude mcp add-json posthog -s user '{"command": "npx","args": ["-y","mcp-remote@latest","https://mcp.posthog.com/sse","--header","Authorization:${POSTHOG_AUTH_HEADER}"],"env": {"POSTHOG_AUTH_HEADER": "Bearer {INSERT_YOUR_PERSONAL_API_KEY_HERE} "}}'
Security considerations
We recommend the following best practices to mitigate security risks when using the PostHog MCP server:
Use the right API key permissions: Use the provided MCP Server preset in the personal API key creator. If you use the MCP in an agentic workflow on production data, scope down the API key's permissions to only the permissions you want it to use. This prevents the AI from making unintended changes to your PostHog configuration or data.
Project scoping: Scope your MCP server to a specific PostHog project, limiting access to only that project's resources. This prevents AI agents from accessing data from other projects in your PostHog account and helps maintain data isolation.
Be mindful of prompt injection: Keep in mind that LLMs can be tricked into following untrusted commands within user content. Always review and sanitize tool calls before executing them.
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:
Dashboards
Tool | Purpose |
---|---|
add-insight-to-dashboard | Add an existing insight to a dashboard. |
dashboard-create | Create a new dashboard in the project. |
dashboard-delete | Delete a dashboard by ID. |
dashboard-get | Get a specific dashboard by ID, including insights that are on the dashboard. |
dashboard-update | Update an existing dashboard by ID. |
dashboards-get-all | Get all dashboards in the project with optional filtering. |
Documentation
Tool | Purpose |
---|---|
docs-search | Search the PostHog documentation for information. |
Error tracking
Tool | Purpose |
---|---|
error-details | Get the details of an error in the project. |
list-errors | List errors in the project. |
Events & properties
Tool | Purpose |
---|---|
event-definitions-list | List all event definitions in the project with optional filtering. |
event-properties-get | Get common properties for an event. |
Experiments
Tool | Purpose |
---|---|
experiment-get | Get details of a specific experiment. |
experiment-get-all | Get all experiments in the project. |
Feature flags
Tool | Purpose |
---|---|
create-feature-flag | Creates a new feature flag in the project. |
delete-feature-flag | Delete a feature flag in the project. |
feature-flag-get-all | Get all feature flags in the project. |
feature-flag-get-definition | Get the definition of a feature flag. |
update-feature-flag | Update a feature flag in the project. |
Insights & analytics
Tool | Purpose |
---|---|
get-sql-insight | Queries project's PostHog data based on a provided natural language question. |
insight-create-from-query | Save a query as an insight. |
insight-delete | Delete an insight by ID. |
insight-get | Get a specific insight by ID. |
insight-query | Execute a query on an existing insight to get its results/data. |
insight-update | Update an existing insight by ID. |
insights-get-all | Get all insights in the project with optional filtering. |
LLM observability
Tool | Purpose |
---|---|
get-llm-total-costs-for-project | Fetches the total LLM daily costs for each model for a project over a given number of days. |
Organization & project management
Tool | Purpose |
---|---|
organization-details-get | Get the details of the active organization. |
organizations-get | Get the organizations the user has access to. |
projects-get | Fetches projects that the user has access to in the current organization. |
switch-organization | Change the active organization from the default organization. |
switch-project | Change the active project from the default project. |
Next Steps
- PostHog MCP server: Check out GitHub repository for the MCP server
- Model Context Protocol: Learn more about the Model Context Protocol specification
- MCP: machine/copy paste: What exactly is MCP again?