Replit integration
Contents
The PostHog MCP lets Replit Agent set up analytics, error tracking, and feature flags in your project automatically. Once connected, you can also query your data, investigate errors, and manage experiments - all through natural language.
Connect PostHog to Replit
- When prompted, log in to PostHog to authorize access
- The PostHog MCP server is now available in your Replit Agent
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 Replit Agent this prompt to add PostHog with error tracking and source maps:
The agent will get your project credentials from the MCP, set up shared environment variables, install the SDKs, add an error boundary, and configure source map uploads. It will prompt you to provide the CLI secrets needed for source map uploads.
For source maps to work in production, add these as Production app secrets (go to Publish → Adjust settings):
POSTHOG_CLI_TOKEN- create a personal API key with the MCP Server presetPOSTHOG_CLI_ENV_ID- from your error tracking settings
What you can do with the MCP
Once set up, you can ask Replit Agent 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
Source maps not uploading
Check that POSTHOG_CLI_TOKEN and POSTHOG_CLI_ENV_ID are set as secrets in Replit. If they're not set, the build will succeed but source maps won't be uploaded.
Events not appearing
Verify VITE_POSTHOG_KEY and VITE_POSTHOG_HOST are set correctly and that PostHog is initialized before your app renders.
MCP not connecting
Try disconnecting and reconnecting the PostHog MCP server. Make sure you're logged into the correct PostHog account.
Next steps
- Error tracking docs - Learn more about error tracking features
- Source maps guide - Detailed source map configuration
- Feature flags - Set up feature flags in your code
- MCP tools reference - All available MCP tools
Have feedback or questions? Let us know on GitHub or ask a question.