v0 integration

The PostHog MCP lets v0 query your analytics data, investigate errors, manage feature flags, and run experiments - all through natural language.

Connect PostHog to v0

  1. In a v0 chat, click the + button in the bottom left
  2. Click MCPs
  3. Click Add MCP
  4. Select Custom MCP
  5. Enter the name PostHog and URL https://mcp.posthog.com/mcp
  6. Under Authentication, select OAuth
  7. Click Add, then authorize with PostHog when prompted

The PostHog MCP server is now available in your v0 chats.

EU region users

If your PostHog project is on EU Cloud, use https://mcp-eu.posthog.com/mcp instead.

Set up PostHog in your project

Once connected, give v0 this prompt to add PostHog with the Vercel Flags SDK:

text
## Add PostHog Analytics and Feature Flags
### Packages
`posthog-js`, `flags`, `@flags-sdk/posthog`
### Critical: Let the Client Own the Distinct ID
**Do NOT generate distinct IDs server-side.** The PostHog JS SDK manages its own `distinct_id` via `localStorage+cookie` persistence. If you bootstrap a server-generated ID, every server render can produce a different ID, breaking experiment attribution.
### Implementation Structure
- `/components/posthog-provider.tsx` - Client provider that initializes `posthog-js` with `persistence: "localStorage+cookie"`. Guard against re-init with `if (posthog.__loaded) return`. No `bootstrap` option needed.
- `/app/layout.tsx` - Wrap children in `<PostHogProvider>`. No async work or distinct ID generation needed.
- `/lib/flags.ts` *(optional, for server-side flag evaluation)* - If you need server-side flags, read the distinct ID from PostHog's native cookie `ph_<api_key>_posthog` (JSON format: `{"distinct_id": "..."}`). **Never generate a fallback UUID** -- if the cookie doesn't exist, skip server-side evaluation and let the client handle it.
### Reading Feature Flags Client-Side
Use `posthog.onFeatureFlags()` to wait for flags to load, then `posthog.getFeatureFlag("flag-key")` to read the variant. Always wait for flags to be ready before rendering flag-dependent UI.
### PostHog MCP Notes
- The MCP may default to a different project than the one your API key sends events to. Use `PostHog_projects-get` to list projects and `PostHog_switch-project` to point at the correct one before querying.
- Use `PostHog_query-run` with HogQL to verify events are flowing.
- Experiments created via `PostHog_experiment-create` use `control` as the default variant key (not the variant name). Map `control` to your first variant in code.

The agent will set up PostHog with the client owning identity via localStorage+cookie persistence, ensuring reliable experiment attribution.

What you can do with the MCP

Once connected, you can ask v0 to interact with your PostHog data directly:

Query your analytics

Prompt: "How many unique users signed up in the last 7 days, broken down by day?"

The agent will run a trends query and return daily signup counts with a breakdown.

Prompt: "What's the conversion rate from signup to first purchase?"

The agent will build a funnel query and calculate the conversion percentage between those two events.

Investigate errors

Prompt: "What are the top 5 errors in my project this week?"

The agent will fetch error groups sorted by occurrence count, including how many users were affected.

Prompt: "Show me details about the most recent TypeError"

The agent will pull the stack trace, affected users, and browser/OS context for that error.

Manage feature flags

Prompt: "Create a feature flag called 'new-checkout' enabled for 10% of users"

The agent will create the flag with a 10% rollout and return the configuration with a link to the flag in PostHog.

Prompt: "Update the 'beta-features' flag to 50% rollout"

The agent will modify the existing flag and confirm the new rollout percentage.

Run experiments

Prompt: "Create an A/B test for the pricing page that measures conversion to checkout"

The agent will set up an experiment with control/test variants and configure a funnel metric measuring pricing page to checkout conversion.

See all available MCP tools for the complete list.

Troubleshooting

OAuth not refreshing

If the OAuth token expires and won't refresh, you can use a personal API key instead:

  1. Create a personal API key with the MCP Server preset
  2. In v0, go to Manage MCPs and edit the PostHog connection
  3. Change authentication to Bearer and enter your API key

MCP not connecting

Try disconnecting and reconnecting the PostHog MCP server. Make sure you're logged into the correct PostHog account.

Next steps

Have feedback or questions? Let us know on GitHub or ask a question.

Community questions

Was this page useful?

Questions about this page? or post a community question.