Docs

Everything runs on your own machine with free tools. You need Python 3.12 or newer, Node.js 20 or newer, and a free API key from Groq. Gemini and OpenRouter keys add extra fallbacks.

Quickstart

Terminal
git clone https://github.com/hamzaishtiaq0318-bit/rehearsal.git
cd rehearsal

python -m venv .venv
.venv\Scripts\activate           # Windows; on macOS and Linux: source .venv/bin/activate
pip install -r requirements.txt

cd web && npm install && npm run build && cd ..

echo GROQ_API_KEY=your_key > .env
python -m rehearsal.server

The server prints a console link that contains a secret token for this launch. Open it and ask for something, for example please resolve ticket 1002. Pick AI agent to let a free model do the work. For ticket 1006 you can also pick Attack simulation, a clearly labelled scripted agent that obeys the hidden instruction, so you can see what Rehearsal catches.

No key at hand? Pick Recorded run. It replays a real model's recorded decisions through the live engine, so the private copy, the changes and the flags are all real. Or skip the install and try it in your browser.

Prefer Docker? docker build -t rehearsal . then docker run --rm -p 8000:8000 rehearsal and open http://localhost:8000. The container runs in demo mode, so keep it on your own machine.

Building the MCP server with Synapse

The demo app, Kestrel Desk, is a plain FastAPI service that plays the part of an existing internal tool. Its MCP server is generated by the Synapse CLI and committed exactly as written:

Terminal
npm install -g @2ndbrainlabs-ai/synapse-cli
cd legacy/kestrel_desk
synapse build --local --auto --discover --base-url http://127.0.0.1:8100 \
  --endpoints "GET /tickets,GET /tickets/{ticket_id},POST /orders/{order_id}/refunds,..."

Ten of the app's sixteen endpoints are exposed. Bulk customer export and permanent deletion are left out on purpose. The repository's docs/mcp-setup.md lists every choice and the reason for it.

Protecting your own app

Build the app's MCP server with Synapse, then let Rehearsal write the config. It reads the generated server, the app's code and its database schema, prints every decision, and writes a commented file you can correct:

Terminal
python -m rehearsal.init path/to/app --out app.toml
REHEARSAL_CONFIG=app.toml python -m rehearsal.server

The repository includes a second, unrelated app to prove the point: Larkspur Clinic, with patients, appointments and invoices. Its MCP server came from Synapse and its config from rehearsal init, with no Rehearsal code that knows about it. On the demo store, rehearsal init reproduces the hand written config exactly. That config looks like this:

rehearsal.toml
[target]
name = "Kestrel Desk"
app_dir = "legacy/kestrel_desk"
command = ["{python}", "-m", "uvicorn", "main:app", "--host", "127.0.0.1", "--port", "{port}"]
database_env = "KESTREL_DB"
live_database = "runtime/live/kestrel.db"
volatile_columns = ["created_at"]
owner_table = "customers"

[target.money]
refunds = "amount_cents"
credits = "amount_cents"

[target.outbound]
messages = "body"

[risk]
single_payment_limit_cents = 50000
bulk_rows = 5

[rules]
never_change = ["customers.email", "orders.total_cents"]
max_money_cents = 100000
max_money_per_owner_per_day_cents = 50000

[trust]
auto_apply = "low"

[rules] holds your own business rules: tables or columns no task may change, protected owners such as VIP customers (protected = [4, 12]), the most one task may pay out, and the most one customer may receive in a day across every task, so many small requests cannot add up unseen. Breaking any of them is high risk, so a person always decides, and a misspelt rule stops Rehearsal from starting instead of being ignored.

target.outbound names the text that leaves the business, such as replies to customers, so Rehearsal can check what a reply says about money against the money that actually moves. With auto_apply = "low", work that raises no flag at all is applied without asking, still verified and undoable; set it to "none" to approve every change yourself. Add second_approval = "high" and set REHEARSAL_REVIEWERS=Amira,Ben: each reviewer gets their own secret link at startup, and high risk work needs approvals from two of them. target.private names columns that hold personal data, so a reply that carries another customer's email or name is flagged.

Fully offline. Set OLLAMA_MODEL, for example qwen3:14b, to run the agent on a local Ollama model. Nothing the agent reads leaves your machine: no cloud model is used as a fallback and the Prompt Guard scan is switched off.

Phone alerts. Set REHEARSAL_NTFY_TOPIC to a long random name and subscribe to it in the free ntfy app. When a review is waiting you get the ticket, the risk and the totals, never customer names or an approval link.

Measuring an agent

The evaluator runs the real agent on six story tickets, grades each rehearsal against the refund policy, and rejects every rehearsal afterwards so live data is never touched:

Terminal
python -m rehearsal.evaluate --runs 2

In our runs a free gpt-oss-120b model resolved 12 of 12 tickets correctly and ignored the injected instruction both times.

Using your own agent over MCP

Cursor and any other MCP client can use Rehearsal directly. Put it in your MCP config where the Synapse server used to be. This prints the entry with your paths filled in:

Terminal
python -m rehearsal.proxy --print-config
MCP client config
{
  "mcpServers": {
    "rehearsal": {
      "command": "<repo>/.venv/Scripts/python.exe",
      "args": ["-m", "rehearsal.proxy"],
      "env": { "PYTHONPATH": "<repo>" }
    }
  }
}

Restart the client. Your agent keeps the same ten tools and gains two: submit_for_review, which ends a task and opens the review in your browser, and review_status, which tells the agent what you decided. Every other call runs on a private copy. The link that can approve opens in your browser and is never returned to the agent.

The proxy also serves the console, so run either the proxy or python -m rehearsal.server, not both.

Settings

Put any of these in .env or in the environment. A variable already set in the environment wins.

Settings
VariableWhat it does
GROQ_API_KEY, GEMINI_API_KEY, OPENROUTER_API_KEYFree model keys for the live agent. Without any, recorded runs and the attack simulation still work.
REHEARSAL_CONFIGThe app to protect, as a config file. Defaults to rehearsal.toml.
REHEARSAL_TOKENThe secret in the console link. A new random one is made at each start unless you set it.
REHEARSAL_REVIEWERSNames for two person approval, such as Amira,Ben. Each gets their own secret link at start.
REHEARSAL_HOST, REHEARSAL_PORTWhere the console listens. 127.0.0.1:8000 by default.
REHEARSAL_ALLOWED_HOSTSExtra host names the console answers to, besides the loopback ones.
REHEARSAL_MAX_ACTIVEHow many rehearsals may run at once. 3 by default.
REHEARSAL_PROMPT_GUARDSet to 0 to stop sending tool results to Groq's Prompt Guard.
REHEARSAL_AUDIT_KEYA secret that keys the audit log's hashes. Set it before the first run and keep it away from the log.
REHEARSAL_NTFY_TOPICA long random ntfy topic for phone alerts when a review is waiting.
OLLAMA_MODELRun the agent on a local Ollama model, fully offline.
REHEARSAL_PUBLIC_DEMOSet to 1 only for a demo nobody else can reach: anyone can then approve changes.

Free models and fallbacks

The agent walks a chain of free models across Groq, OpenRouter and Gemini. A model that is rate limited or overloaded is skipped until it cools down; a model an account cannot use is dropped. Add keys to .env and the chain picks them up automatically.

Tests

Terminal
python -m pytest tests

About two hundred tests run real app processes and real generated MCP servers: the full rehearsal cycle, the attack gallery, rollbacks and crashes part way through a replay, the argument guard, the console API and its security checks, and MCP proxy mode over the real protocol.