PostHog MCP server: setup, project pinning, tools and fixes
PostHog's MCP server at mcp.posthog.com: setup in Claude Code, Cursor and Codex, which project it uses, pinning one, read-only and exec modes, and fixes.
Updated
Short answer
PostHog runs an official MCP server (a connector that lets an AI agent use your PostHog) at https://mcp.posthog.com/mcp. It's free, works for US and EU accounts from the same address, and signs in with OAuth or a personal API key. The quickest setup is PostHog's wizard:
npx @posthog/wizard mcp add
Or in Claude Code, claude mcp add --transport http posthog https://mcp.posthog.com/mcp -s user, then /mcp to sign in. The one thing to get right is the project: without a pin, the agent works in whichever project you last had open in PostHog. Add ?project_id=<id> to the address to pin one.
PostHog's MCP server
| Address | https://mcp.posthog.com/mcp. The old /sse address redirects to it |
| Regions | One address for US and EU; it routes by the account you sign in with. https://mcp-eu.posthog.com/mcp also works |
| Sign-in | OAuth (clients register themselves), or a personal API key as Authorization: Bearer |
| Price | Free. Queries count toward normal PostHog usage, and AI-powered tools toward PostHog AI |
| Limits | 480 requests a minute and 4,800 an hour per credential, then 429 with Retry-After |
| Self-hosted PostHog | Only by running the server yourself with POSTHOG_API_BASE_URL; it needs Redis |
| Code | services/mcp in the PostHog monorepo. The old PostHog/mcp repo is archived |
PostHog's MCP docs and FAQ have the details. For a key, use the MCP Server preset on personal API keys.
Connect it to your client
Wizard. npx @posthog/wizard mcp add sets up Cursor, Claude Code, Claude Desktop, Codex, VS Code, Zed and PostHog Desktop.
Claude Code. claude mcp add --transport http posthog https://mcp.posthog.com/mcp -s user, then /mcp. There's also a plugin: claude plugin install posthog.
Cursor. Add {"mcpServers":{"posthog":{"url":"https://mcp.posthog.com/mcp"}}} to ~/.cursor/mcp.json, or install PostHog from the Cursor marketplace.
Codex. codex mcp add posthog --url https://mcp.posthog.com/mcp.
VS Code. {"servers":{"posthog":{"type":"http","url":"https://mcp.posthog.com/mcp"}}} in .vscode/mcp.json.
Windsurf. PostHog's docs run it through npx -y mcp-remote@latest https://mcp.posthog.com/mcp.
Claude. PostHog is in Claude's connector directory. If a Team or Enterprise admin added it, you still click Connect under Settings › Connectors to sign in yourself.
ChatGPT. PostHog has a plugin in ChatGPT's plugin directory.
Which project the agent uses
This is where most PostHog MCP confusion comes from.
- No pin: a new session starts in the project you have open in the PostHog app (your current project). If your sign-in can't reach that one, it picks one it can.
- That choice is frozen per session. Opening another project in PostHog later doesn't move a session that's already running.
switch-projectlasts one session. PostHog's FAQ: the switch tools "change the active context for the current session only". A new chat, or another agent, starts from the default again.- Clients without sessions get a
conversation_idon the first call and must send it back. If they don't, PostHog answers "Switch not applied. Retry with the returnedconversation_id…". - Pin a project with
?project_id=12345on the address, or thex-posthog-project-idheader. The header wins if you send both. - Pin an organization with
?organization_id=orx-posthog-organization-id. That hidesswitch-organization.
A pin is a starting point, not a fence. The FAQ says it "isn't an access limit": the agent can still switch to another project your login can reach. For a hard limit, use a personal API key scoped to one project.
The project ID is the number in the app's address when that project is open: us.posthog.com/project/12345/….
Tools, and the single exec tool
PostHog lists 1,349 tool definitions in 79 areas on its tools page, about half of them read-only. What a connection sees depends on your plan, scopes, feature flags and whether AI data processing is on.
Most clients don't see them one by one. CLI mode is the default for every client except Cursor: the agent gets one tool, exec, and runs commands through it, such as search dashboard, info query-trends or call execute-sql {"query":"SELECT 1"}. That keeps PostHog's hundreds of tool definitions out of the agent's context.
| Area | Read | Change |
|---|---|---|
| Workspace | organizations-get, projects-get |
switch-organization, switch-project |
| Querying | execute-sql (HogQL, read-only), insight-query, query-trends, query-funnel, query-retention, query-paths, query-stickiness, query-lifecycle |
|
| Feature flags | feature-flag-get-all and more |
create-feature-flag, update-feature-flag, delete-feature-flag, feature-flag-roll-out-to-everyone |
| Dashboards and insights | list and get tools | dashboard-create, dashboard-delete, insight-create, insight-delete |
| Experiments and surveys | list and get tools | experiment-launch, experiment-ship-variant, survey-launch, survey-delete |
| Error tracking | query-error-tracking-issues-list, query-error-tracking-issue |
error-tracking-issues-partial-update, merging issues |
| Docs | docs-search |
Address options
| Option | What it does |
|---|---|
?mode=tools |
Lists every tool on its own instead of exec |
?readonly=true |
Drops every tool that creates, updates or deletes |
?split_writes=true |
Two tools instead of exec: exec-read, which PostHog refuses to run writes through, and exec-write |
?features=flags,insights |
Only these areas. ?tools= adds single tools, ?exclude_tools= removes them |
?project_id=, ?organization_id= |
The pins above |
Each has a header form too, such as x-posthog-read-only: true or x-posthog-mcp-mode: tools.
Where PostHog's server stops
- Pins don't limit. Only a key or sign-in scoped to one project keeps an agent out of the others.
- All or nothing in CLI mode. Your client sees one
exectool, so its per-tool approvals can't tell a query from a flag rollout. Usesplit_writesorreadonlyfor that. - Each client keeps its own setup, with its own pin, mode and history.
For one project and one or two clients, PostHog's server with a pinned address is all you need.
Upsy and PostHog
Upsy connects to PostHog's server with your PostHog sign-in, at the same address as Upsy's other apps, https://upsy.ai/connect. Every client, including Grok and Muse, then reaches PostHog next to your Gmail, Slack, Linear and GitHub, with a history of every call.
How Upsy's PostHog connector works:
- One project, pinned. When you connect, Upsy keeps the project PostHog starts in (the one you have open in PostHog) and sends it as
x-posthog-project-idon every call. Opening another project in PostHog later doesn't move your agents. To change it, open Apps, click PostHog, and click Change under Project, then paste a link to any page of the project, or its ID. Upsy checks that your login can open it. - Switching stays with you. Upsy opens a new connection to PostHog for each call, so a
switch-projectwould be gone by the next one. Upsy answers a switch by telling the agent to ask you to change the project in Upsy. - Read and write tools. Upsy asks PostHog for
split_writes, so agents getexec-readandexec-writeinstead of oneexec. Read-only allowsexec-read, and PostHog itself refuses writes through it. Full access addsexec-write. Pick actions lets you choose either.
Add PostHog to Upsy
- Go to upsy.ai and click Set up Upsy.
- Open Apps, click Connect an app, pick PostHog and sign in.
- Click PostHog on Apps to check the project under Project, and set each assistant to Read-only or Full access.
- On the Assistants page, click Add assistant and pick your client under Which assistant? for its steps. In Claude Code:
claude mcp add --transport http --scope user upsy https://upsy.ai/connect. In Claude and ChatGPT, addhttps://upsy.ai/connectas a custom connector (Claude, ChatGPT).
Two projects at once
The built-in connector has one project per PostHog login. For a second one, add PostHog again as an MCP server with that project in its address: on Apps, click Connect an app, then Add on the MCP Server card under Any MCP server. Name it (say, PostHog Staging) and paste the address as the MCP Endpoint. Upsy keeps it exactly as you type it:
https://mcp.posthog.com/mcp?project_id=12345&split_writes=true
A server you add starts off for every assistant; set it per assistant on its page. You can add up to 30.
Check that it works
Using Upsy, which PostHog project are you in? Then tell me yesterday's pageviews.
The agent should name the project (run through project-get) before it queries. Upsy's History shows each call under that agent.
Troubleshooting
The numbers come from the wrong project
The session started in your current project, not the one you meant. Pin it with ?project_id= and reconnect. Through Upsy, open Apps, click PostHog, and change the project under Project.
"Switch not applied. Retry with the returned conversation_id…"
Your client doesn't keep sessions and didn't send the conversation_id back. Pin the project in the address instead.
"This connection pins … so a switch cannot persist"
You pinned a project, then asked to switch on a client without sessions. Change the pin in the address.
Codex or another client sees only one or two tools
That's CLI mode: exec (plus render-ui in some clients) is everything. Ask the agent to run search or tools through exec, or add ?mode=tools to list every tool.
invalid_scope when signing in
Reported with ?features=… addresses (issue #60593). Remove features from the address, or use a personal API key.
An EU account lands on the US sign-in
Use https://mcp.posthog.com/mcp, which routes by account, or add ?region=eu. Signing in through mcp-eu has failed with "Invalid client_id parameter value." (issue #49043); switch to the main address if you see it.
Changed a key's scopes, but the tools didn't change
PostHog re-reads a key's scopes after about two minutes. Reconnecting doesn't speed it up, because the key is the same.
429 errors
You passed 480 requests a minute or 4,800 an hour for that key or sign-in. Opening a session and listing tools count too. Wait for Retry-After.
"The user hasn't allowed you to use PostHog's "exec-write""
That's Upsy refusing a write because PostHog is set to Read-only for the agent. Reads still work through exec-read. Set it to Full access to let the agent change things.
"PostHog can't switch projects through Upsy"
The agent tried switch-project. Upsy keeps each PostHog account in one project; change it on PostHog's page in Apps, or add a second project as an MCP server (above).
Security and privacy
- It acts as you. Unless you limit it, the agent can change anything your PostHog login can, including feature flags in production.
- For a hard limit, use
?readonly=true,exec-readonly, or a personal API key scoped to one project with read scopes. - Feature flags are live switches.
feature-flag-roll-out-to-everyoneandexperiment-ship-variantchange what your users see. Keep your client's approval on for writes. - Prompt injection. Event properties, survey answers and error messages come from your users. PostHog tells agents to treat what it returns as untrusted, but keep write access away from agents that read it unattended.
- Through Upsy, agents never get your PostHog token or key: they call Upsy, and Upsy calls PostHog. Upsy emails you when one agent reads 100 or more times or deletes 50 or more items in 10 minutes, and when a new agent or app connects.
FAQ
What is the PostHog MCP server URL?
https://mcp.posthog.com/mcp, over Streamable HTTP. It serves US and EU accounts; https://mcp-eu.posthog.com/mcp also works for EU.
How do I pin the PostHog MCP server to one project?
Add ?project_id=<id> to the address, or send x-posthog-project-id. It sets where sessions start; it doesn't stop the agent switching.
Why does switch-project keep resetting?
A switch lasts one session. A new chat, a new agent, or a client that reconnects for every call starts in the default project again.
Is the PostHog MCP server free?
Yes. Connecting and calling tools is free; queries count toward your normal PostHog usage.
Does PostHog MCP have a read-only mode?
Yes: ?readonly=true or the x-posthog-read-only header drops every tool that changes data.
Why does my agent only see an exec tool?
PostHog defaults to CLI mode, one exec tool that reaches every PostHog tool. Add ?mode=tools to see them one by one.
Can I use a PostHog API key instead of OAuth?
Yes. Create a personal API key with the MCP Server preset and send it as Authorization: Bearer <key>.
Does it work with self-hosted PostHog?
Not the hosted server. Run PostHog's MCP server yourself with POSTHOG_API_BASE_URL pointed at your instance.