Connect Claude to PostHog for analytics insights, feature flags, user management, and more.
git clone https://github.com/ugzv/mcp-posthog.git
cd mcp-posthog
npm install
npm run buildYou'll need two API keys from PostHog:
- Personal API Key (
phx_...): For queries, dashboards, insights, feature flags- Get it from: Account Settings → Personal API Keys
- Project API Key (
phc_...): For event capture (optional)- Get it from: Project Settings → API Keys
Add to your Claude Desktop config file:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"posthog": {
"command": "node",
"args": ["/absolute/path/to/mcp-posthog/dist/index.js"],
"env": {
"POSTHOG_HOST": "https://us.posthog.com",
"POSTHOG_API_KEY": "phx_your_personal_api_key",
"POSTHOG_PROJECT_API_KEY": "phc_your_project_api_key",
"POSTHOG_PROJECT_ID": "12345"
}
}
}
}{
"mcpServers": {
"posthog": {
"command": "node",
"args": ["/absolute/path/to/mcp-posthog/dist/index.js"],
"env": {
"POSTHOG_HOST": "https://eu.posthog.com",
"POSTHOG_API_KEY": "phx_your_personal_api_key",
"POSTHOG_PROJECT_API_KEY": "phc_your_project_api_key",
"POSTHOG_PROJECT_ID": "12345"
}
}
}
}{
"mcpServers": {
"posthog": {
"command": "node",
"args": ["/absolute/path/to/mcp-posthog/dist/index.js"],
"env": {
"POSTHOG_HOST": "https://posthog.yourcompany.com",
"POSTHOG_API_KEY": "phx_your_personal_api_key",
"POSTHOG_PROJECT_API_KEY": "phc_your_project_api_key",
"POSTHOG_PROJECT_ID": "1"
}
}
}
}Note: Replace /absolute/path/to/mcp-posthog with the actual path to your cloned repository.
claude mcp add posthog \
--env POSTHOG_HOST=https://us.posthog.com \
--env POSTHOG_API_KEY=phx_your_personal_api_key \
--env POSTHOG_PROJECT_API_KEY=phc_your_project_api_key \
--env POSTHOG_PROJECT_ID=12345 \
-- node /absolute/path/to/mcp-posthog/dist/index.jsclaude mcp add posthog \
--env POSTHOG_HOST=https://eu.posthog.com \
--env POSTHOG_API_KEY=phx_your_personal_api_key \
--env POSTHOG_PROJECT_API_KEY=phc_your_project_api_key \
--env POSTHOG_PROJECT_ID=12345 \
-- node /absolute/path/to/mcp-posthog/dist/index.jsclaude mcp add posthog \
--env POSTHOG_HOST=https://posthog.yourcompany.com \
--env POSTHOG_API_KEY=phx_your_personal_api_key \
--env POSTHOG_PROJECT_API_KEY=phc_your_project_api_key \
--env POSTHOG_PROJECT_ID=1 \
-- node /absolute/path/to/mcp-posthog/dist/index.jsVerify the connection:
claude mcp listAsk Claude to:
- "Show me pageviews for the last 7 days"
- "Create a feature flag for dark mode with 20% rollout"
- "List all active users who signed up this month"
- "Run a HogQL query to find top events"
- "Create a funnel for signup → activation → purchase"
- "Capture a custom event when users complete onboarding"
Analytics: insights, trends, funnels, retention queries Feature Flags: create, update, evaluate, and manage flags Users: search, update, merge, and delete person data Dashboards: create and manage analytics dashboards Events: capture custom events and query with HogQL Cohorts: create and manage user segments Annotations: mark deployments and key events on charts Actions: define and track custom user actions
npm install # Install dependencies
npm run build # Build TypeScript
npm run dev # Run in development mode
npm run typecheck # Type check
npm run lint # Lint codeConnection Issues
- Verify
POSTHOG_HOSTmatches your PostHog instance (US/EU/self-hosted) - Check that personal API key starts with
phx_ - Ensure
POSTHOG_PROJECT_IDis correct (find it in PostHog project settings)
Event Capture Not Working
- Add a Project API Key (
phc_...) from Project Settings → API Keys - Personal API keys cannot be used for event capture
Project-Scoped API Keys
- If your personal key is project-scoped (most common), the MCP handles this automatically
- You can only access data from your configured project
MIT