CLI and MCP server to look up PostHog persons and their events
npm install posthog-context-captureCLI and MCP server to look up PostHog persons and their events for debugging.
``bash`
npm install -g posthog-context-capture
Set environment variables:
`bash`
export POSTHOG_PERSONAL_API_KEY=phx_...
export POSTHOG_PROJECT_ID=12345
export POSTHOG_REGION=us # or "eu"
Personal API Key:
1. Go to Settings → Personal API keys in PostHog
2. Click "+ Create a personal API Key"
3. Select the query:read scope
4. Copy the key (starts with phx_)
Project ID: Found in your PostHog URL: https://us.posthog.com/project/12345/...
`bashLook up person by email
posthog-lookup --email user@example.com
MCP Server
The MCP server exposes PostHog lookup tools to AI assistants.
$3
Global (all projects) — add to
~/.mcp.json:`json
{
"mcpServers": {
"posthog": {
"type": "stdio",
"command": "posthog-mcp",
"env": {
"POSTHOG_PERSONAL_API_KEY": "phx_...",
"POSTHOG_PROJECT_ID": "12345",
"POSTHOG_REGION": "us"
}
}
}
}
`Per-project — add
.mcp.json to your project root with the same config.Restart Claude Code after adding. You'll be prompted to approve the server on first use.
$3
Add to
~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows):`json
{
"mcpServers": {
"posthog": {
"command": "posthog-mcp",
"env": {
"POSTHOG_PERSONAL_API_KEY": "phx_...",
"POSTHOG_PROJECT_ID": "12345",
"POSTHOG_REGION": "us"
}
}
}
}
`$3
Add to Cursor settings (
Cursor Settings → MCP), or create .cursor/mcp.json in your project:`json
{
"mcpServers": {
"posthog": {
"command": "posthog-mcp",
"env": {
"POSTHOG_PERSONAL_API_KEY": "phx_...",
"POSTHOG_PROJECT_ID": "12345",
"POSTHOG_REGION": "us"
}
}
}
}
`$3
-
lookup_person_by_email - Find a person by email with their recent events
- lookup_persons_by_event - Find persons who triggered a specific event
- get_person_events` - Get events for a specific person IDMIT