# Use experiments over PostHog MCP

#### Contents

- Before you start
- What you can do here
- Example prompts
- Install the MCP server

The [PostHog MCP server](/content/docs/model-context-protocol/index.html) exposes experiments as function calling tools, so an AI agent can create an experiment, launch it, read its results, and end it without you switching to the PostHog app. It works in any MCP client – Cursor, Codex, Claude Code, Windsurf, VS Code, and others.

This is the surface to use when the experiment lives next to the code you're writing. You can scaffold the test in the same session you build the feature, then come back later and ask whether it won.

## Before you start

1. **Set up Experiments** – [install a PostHog SDK](/content/docs/experiments/installation/index.html) so your app can serve variants.
2. **Connect the MCP server** – [install it in your AI tool](/content/docs/experiments/surfaces/mcp#install-the-mcp-server/index.html) and give it access to your project.

## What you can do here

**Plan and create experiments**

Estimate a sample size and running time before anything exists, then create the experiment along with its backing [feature flag](/content/docs/feature-flags/index.html). You can also duplicate an existing experiment or copy one into another project.

**Read results**

Pull an experiment's configuration, its current statistical results, a timeseries of those results over time, and the full audit trail of who changed what.

**Manage the lifecycle**

Launch, pause, resume, end, and reset experiments, ship a winning variant, archive or unarchive finished ones, and freeze or unfreeze exposures when you want to [stop enrollment but keep measuring](/content/docs/experiments/tracking-long-term-metrics/index.html).

**Manage holdouts and shared metrics**

Create, list, update, and delete [holdout](/content/docs/experiments/holdouts/index.html) groups and shared [metrics](/content/docs/experiments/metrics/index.html) so they can be reused across experiments.

## 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.`
- `How long would I need to run this experiment to detect a 5% lift?`
- `What are the results of my new-pricing-page experiment?`
- `List all running experiments in this project.`
- `Ship the winning variant of the dark-mode test.`
- `Freeze exposures on the pricing experiment but keep collecting metrics.`
- `Who changed the targeting on the onboarding experiment, and when?`

## Install the MCP server

The recommended way to install is with the [AI wizard](/content/docs/ai-engineering/ai-wizard/index.html):

Terminal

PostHog AI

```bash
npx @posthog/wizard mcp add
```

The wizard supports Claude, Cursor, Windsurf, VS Code, and more. You can also [configure it manually](/content/docs/model-context-protocol#get-started-in-30-seconds/index.html).

### Still have questions?

Ask PostHog AI
