PostHog MCP Server: AI-Powered Analytics & Feature Flags

PostHog MCP server enables AI models to interact with PostHog analytics for project management, annotations, feature flags, and error analysis.

November 15, 2025
PostHogMCPAIAnalyticsFeature Flags
GitHub starsnpm versionnpm downloads

Overview

The PostHog MCP Server is an open-source Model Context Protocol (MCP) server that connects AI assistants (like Cline or Cursor) to PostHog’s analytics platform via natural language commands. It enables tasks like creating annotations, managing projects, querying insights, and toggling feature flags—all without touching PostHog’s UI.

Official Server:

Developed and maintained by PostHog

Key Features

📊

Project Management

List and manage PostHog projects

📝

Annotations

Add timestamped notes for events (e.g., product launches)

🚀

Feature Flags

Control and query feature flags dynamically

🐛

Error Tracking

Debug errors directly in your IDE

Available Tools

Quick Reference

ToolPurposeCategory
list_projectsList all PostHog projectsProject Management
create_annotationCreate a new annotationAnnotations
get_feature_flagGet the status of a feature flagFeature Flags
set_feature_flagSet the status of a feature flagFeature Flags
get_error_detailsGet details of an errorError Tracking

Detailed Usage

list_projects

List all projects in your PostHog organization.

use_mcp_tool({
  server_name: "posthog",
  tool_name: "list_projects",
  arguments: {}
});
create_annotation

Create a new annotation for a specific project.

use_mcp_tool({
  server_name: "posthog",
  tool_name: "create_annotation",
  arguments: {
    project_id: 123,
    content: "Launched new marketing campaign",
    date_from: "2024-01-01T00:00:00Z"
  }
});
get_feature_flag

Get the status of a specific feature flag for a project.

use_mcp_tool({
  server_name: "posthog",
  tool_name: "get_feature_flag",
  arguments: {
    project_id: 123,
    flag_key: "new-ui"
  }
});
set_feature_flag

Set the status of a specific feature flag for a project.

use_mcp_tool({
  server_name: "posthog",
  tool_name: "set_feature_flag",
  arguments: {
    project_id: 123,
    flag_key: "new-ui",
    enabled: true
  }
});
get_error_details

Get details of a specific error for a project.

use_mcp_tool({
  server_name: "posthog",
  tool_name: "get_error_details",
  arguments: {
    project_id: 123,
    error_id: "error-abc-123"
  }
});

Installation

{
  "mcpServers": {
    "posthog": {
      "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}"
      }
    }
  }
}

Custom Connection:

Replace {INSERT_YOUR_PERSONAL_API_KEY_HERE} with your actual PostHog personal API key. If you're using PostHog EU cloud or a self-hosted instance, you can specify a custom base URL by adding the POSTHOG_BASE_URL environment variable.

Common Use Cases

1. Annotate Product Launches

Create annotations for product launches or significant events to correlate with analytics data:

use_mcp_tool({
  server_name: "posthog",
  tool_name: "create_annotation",
  arguments: {
    project_id: 123,
    content: "New feature X launched to all users",
    date_from: "2024-05-20T10:00:00Z"
  }
});

2. Toggle Feature Flags

Programmatically enable or disable feature flags based on certain conditions:

// Enable a feature flag
use_mcp_tool({
  server_name: "posthog",
  tool_name: "set_feature_flag",
  arguments: {
    project_id: 123,
    flag_key: "dark-mode",
    enabled: true
  }
});

// Disable a feature flag
use_mcp_tool({
  server_name: "posthog",
  tool_name: "set_feature_flag",
  arguments: {
    project_id: 123,
    flag_key: "old-dashboard",
    enabled: false
  }
});

3. Monitor Errors

Retrieve details about specific errors to aid in debugging and incident response:

use_mcp_tool({
  server_name: "posthog",
  tool_name: "get_error_details",
  arguments: {
    project_id: 123,
    error_id: "error-404-page-not-found"
  }
});

Connection String Format

The PostHog MCP server primarily uses API keys for authentication. For npx installation, the Authorization header is used. For python installation, the POSTHOG_API_TOKEN environment variable is used.

Sources