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 and Claude Desktop.
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/mcp","--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:
Organization & project management
Tool | Purpose |
---|---|
organizations-get | Get the organizations the user has access to. |
switch-organization | Change the active organization from the default organization. |
organization-details-get | Get the details of the active organization. |
projects-get | Fetches projects that the user has access to in the current organization. |
switch-project | Change the active project from the default project. |
property-definitions | Get event and property definitions for the project. |
Feature flags
Tool | Purpose |
---|---|
feature-flag-get-all | Get all feature flags in the project. |
feature-flag-get-definition | Get the definition of a feature flag. |
create-feature-flag | Creates a new feature flag in the project. |
update-feature-flag | Update a feature flag in the project. |
delete-feature-flag | Delete a feature flag in the project. |
Insights & analytics
Tool | Purpose |
---|---|
insights-get-all | Get all insights in the project with optional filtering. |
insight-get | Get a specific insight by ID. |
insight-create-from-query | Save a query as an insight. |
insight-update | Update an existing insight by ID. |
insight-delete | Delete an insight by ID. |
insight-query | Execute a query on an existing insight to get its results/data. |
get-sql-insight | Queries project's PostHog data based on a provided natural language question. |
Dashboards
Tool | Purpose |
---|---|
dashboards-get-all | Get all dashboards in the project with optional filtering. |
dashboard-get | Get a specific dashboard by ID. |
dashboard-create | Create a new dashboard in the project. |
dashboard-update | Update an existing dashboard by ID. |
dashboard-delete | Delete a dashboard by ID. |
add-insight-to-dashboard | Add an existing insight to a dashboard. |
Error tracking
Tool | Purpose |
---|---|
list-errors | List errors in the project. |
error-details | Get the details of an error in the project. |
Documentation
Tool | Purpose |
---|---|
docs-search | Search the PostHog documentation for information. |
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. |
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?