All docs

docs / automate

MCP server

An MCP server that changes nothing: any coding agent can run Petri's checks, read verdicts and Watch alerts, and draft plan changes.

On this page

petri-check mcp serves Petri's checks to any coding agent over the Model Context Protocol (stdio). The agent gets the same rule engine as the extension and the same decision rule, so its answer to "is this experiment measuring correctly, and can we ship it?" matches what you'd see in the editor.

sh
claude mcp add petri -- npx -y petri-check mcp

For Cursor, Codex, Copilot or any other MCP client, add a stdio server with the command npx and the arguments -y petri-check mcp. Start it from the repository (or pass path to each tool), so it can find flagsmith.json and flagsmith.env.

Read-only on purpose

The server has no tool that changes Flagsmith or code. An agent can check wiring, read experiments and propose changes, but it can't start, stop, complete or roll out anything through it. Changes stay in the editor, where every Flagsmith write shows the exact request and every code change a diff before you approve it (Copilot), behind the ⛔ gates of the Agent Skill, or in a reviewed pull request (petri_plan_change).

Tools

petri_check

Runs the 20 diagnostics on a repository and returns one line per finding.

Argument Meaning
path Folder to check (default: the server's working directory)
self_hosted Offline only: treat the code as talking to self-hosted Flagsmith
environment Flagsmith environment key (default: flagsmith.json)
api_url Flagsmith API URL (default: flagsmith.json, then Cloud)

Without credentials it runs the code-only rules (PETRI007, PETRI008, PETRI012, PETRI014, PETRI015–PETRI020, and PETRI013 against a committed petri.lock.json); with them, all twenty against live data.

petri_experiments

Every experiment in the environment, as JSON: status, hypothesis, per-metric and per-arm results (lift, 95% interval, chance to win, expected loss), the sample-ratio check, the health scorecard, Watch alerts with the commit to blame, the peek-safe sequential test, progress to the pre-registered stop, and Petri's verdict with its reasons and the variantId to roll out. Needs a key and an environment (Configuration).

petri_plan_change

Proposes a change as an entry for petri.plan.json and previews it against live Flagsmith (a dry run). It writes nothing: the agent adds the entry to the file and opens a pull request, and the review is the approval.

Argument Meaning
id, action A stable name, and start, pause, complete or ramp
experiment The experiment id (start, pause, complete)
decision, variant complete: variant (with the winning key), control or disable
flag, variant, percent ramp: serve the decided winner to this share of users (10 → 50 → 100)
production Must be true to apply in an environment named like production

petri_rule

Explains one diagnostic, PETRI001 to PETRI020, in a sentence, with a link to the full entry in Diagnostics.

Example session

text
you   > Is the checkout experiment measuring correctly, and can we ship it?
agent → petri_check { "path": "." }
        2 files checked offline (code-only rules): 1 errors, 0 warnings, 0 notes.
        server.mjs:6  ERROR PETRI012  You're on self-hosted Flagsmith, but eventProcessorConfig.eventsApiUrl isn't set…
agent   fixes server.mjs (you review the diff in your editor)
agent → petri_experiments { "path": "." }
        [{ "id": 2, "flag": "checkout_cta", "verdict": "ship", "variantKey": "free_shipping", … }]
agent   "The wiring is fixed. Petri's rule says ship free_shipping: +50.4% (95% interval +0.6% to +100.3%),
         98% chance to win, expected loss 0.23%. Complete it from the Petri sidebar."

Protocol notes

JSON-RPC 2.0 over stdio, one message per line: initialize, tools/list, tools/call and ping. It answers every request it has received before it exits when the client closes the pipe.

Prompt: wire_experiment

Agents given only a vendor prompt often wire experiments that run fine and measure nothing. The server also offers an MCP prompt, wire_experiment (optional arguments flag and events). It hands the agent Petri's wiring checklist: events on and flushed, the self-hosted events URL, getExperimentFlag with a stable identity, the same identity for conversions, exact event names, keyed variants, event storage, and no treatment edits mid-run. It then tells the agent to finish only on a clean petri_check. In Claude Code it appears as /petri:wire_experiment.