|
| 1 | +--- |
| 2 | +title: Developing the wizard |
| 3 | +sidebar: Handbook |
| 4 | +showTitle: true |
| 5 | +--- |
| 6 | + |
| 7 | +Developers love the wizard: it's the fastest way to get a deep, correct integration of PostHog into their project, with none of the hallucinations that come from naive agent-based attempts. |
| 8 | + |
| 9 | +## The wizard's architecture |
| 10 | + |
| 11 | +The wizard is a CLI tool that runs locally in developers' projects. |
| 12 | + |
| 13 | +It wraps the [Claude Agent SDK](https://platform.claude.com/docs/en/agent-sdk/overview) to perform the integration, reviewing project code and making edits as needed. |
| 14 | + |
| 15 | +To direct the agent, the wizard uses the PostHog [MCP server](https://github.com/PostHog/posthog/tree/master/products/mcp) as a context provider. The MCP includes workflow prompts, documentation and example code to improve the correctness and completeness of the integration. |
| 16 | + |
| 17 | +MCP content is derived from the PostHog [examples repository](https://github.com/PostHog/examples), which includes code snippets, documentation and prompts. The examples repo generates a zip file and manifest that determine's the URIs and structure for `prompts` and `resources`. Updating the examples repo will instantly update the MCP content. |
| 18 | + |
| 19 | +## Developing the wizard |
| 20 | + |
| 21 | +Use these prompts to get your agent started. |
| 22 | + |
| 23 | +Get the repos: |
| 24 | + |
| 25 | +```md |
| 26 | + |
| 27 | +Clone these repositories: |
| 28 | + |
| 29 | +https://github.com/PostHog/wizard-workbench |
| 30 | +https://github.com/PostHog/examples |
| 31 | +https://github.com/PostHog/wizard |
| 32 | + |
| 33 | +(If you don't have it already, the PostHog repo includes the MCP server) https://github.com/PostHog/posthog |
| 34 | + |
| 35 | +``` |
| 36 | + |
| 37 | +Configure the workbench to run the wizard and its local dependencies: |
| 38 | + |
| 39 | +```md |
| 40 | + |
| 41 | +Read the README.md file in the wizard-workbench repository. Configure a .env file with the paths to the repos. |
| 42 | + |
| 43 | +``` |
| 44 | + |
| 45 | +With the workbench now configured, open a terminal at its root and run: |
| 46 | + |
| 47 | +```bash |
| 48 | +mprocs |
| 49 | +``` |
| 50 | + |
| 51 | +This will start the workbench and all its dependencies: |
| 52 | + |
| 53 | +- Making a change to the examples repo will instantly update the MCP content. |
| 54 | +- Editing the wizard's code will automatically rebuild and link the changes globally. Run it against any project on your machine with `wizard --local-mcp`. |
| 55 | +- Review the contents of the MCP server by selecting the **mcp-inspector** tab and opening the link it provides in your browser. |
| 56 | + |
| 57 | +## Using the MCP inspector |
| 58 | + |
| 59 | +You'll want the link that looks like this from the mcp-inspector tab: |
| 60 | + |
| 61 | +``` |
| 62 | +http://localhost:6274/?MCP_PROXY_AUTH_TOKEN=97e0ba... |
| 63 | +``` |
| 64 | + |
| 65 | +Look for the text `Open inspector with token pre-filled. |
| 66 | + |
| 67 | +Access the link in your browser, set the transport type to **Streamable HTTP**, and set the URL to **http://localhost:8787/mcp**. (Alternatively, you can also inspect the production MCP by setting the URL to **https://mcp.posthog.com/mcp**). |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | +You'll need a PostHog API key to access the MCP server. Get one from the [user API keys settings page](https://app.posthog.com/settings/user-api-keys?preset=mcp_server). Open the **Authentication** tab and paste the key into the **Bearer token** field. |
| 72 | + |
| 73 | +Hit connect and you'll see the MCP server's contents. |
0 commit comments