Create Experiments with MCP

The PostHog MCP server lets your AI coding agent create and manage Experiments directly from your code editor. Set up A/B tests, check results, and manage Experiment lifecycle – without switching to the PostHog app.

This works in any MCP client – Cursor, Windsurf, Claude Code, VS Code, and others.

How it works

With MCP, your coding agent can:

  • Create Experiments alongside your code – Set up an A/B test for a feature you're building without leaving your editor
  • Check results before shipping – "What are the results of the checkout Experiment?" to decide whether to merge
  • Manage Experiment lifecycle – Update targeting, adjust traffic splits, or archive completed Experiments
  • Validate implementation – Check that you correctly configured your feature flag before launching

Experiment tools

The MCP server provides these tools for working with Experiments:

ToolDescription
experiment-createCreate a new Experiment with specified variants, traffic split, and goal metrics. Automatically creates the backing feature flag.
experiment-getGet details for a specific Experiment, including current status and configuration.
experiment-get-allList all Experiments in the current project.
experiment-results-getGet the statistical results of an Experiment, including confidence intervals and significance.
experiment-updateUpdate an Experiment's name, description, or configuration.
experiment-deleteDelete an Experiment.

Example prompts

Try these with your MCP-enabled agent:

  • Create an A/B test for the new checkout flow with a 70/30 split. Use purchase_completed as the goal metric.
  • What are the results of my new-pricing-page Experiment?
  • List all running Experiments in this project.
  • Is the dark-mode-test Experiment statistically significant yet?
  • Archive the old-onboarding Experiment.

Install the MCP server

The recommended way to install is with the AI wizard:

Terminal
npx @posthog/wizard mcp add

The wizard supports Claude, Cursor, Windsurf, VS Code, and more. You can also configure it manually.

See the MCP server docs for full setup instructions.

Community questions

Was this page useful?

Questions about this page? or post a community question.