Project #3 copies project #2's lib/ wholesale โ
the loop, the MCP client, the schema translation โ and adds a handbrake.
Prerequisites, and scaffold without a fight
ANTHROPIC_API_KEYand aDATABASE_URL. Same scaffolding gotcha, third time: temp dir, then copy in.Read the types first. Again.
Checkpoint
You can state, without looking, whether
registerToolcan declare a tool destructive (it can) and whether your host should believe it (it should not).Provision Postgres
bashnpx vercel install neon npx vercel env pull .env.localIt provisions from the Vercel Marketplace, bills through Vercel, suspends rather than charges if you exceed the free tier, and never asks for a card.
Checkpoint
DATABASE_URLexists and its host contains-pooler.The notebook
bashnpm run db:initThe jar that remembers
The same
cookie_jartool, backed by Postgres instead of a variable โ finally fixing project #1's sandcastle. The model cannot tell the difference, which was the point.Curate the toolbox
Project #1's forgetful jar is hidden; the
secret_codecollision is kept. See One shelf, many servers.Checkpoint
bashnpm run mcp:listThe permission model
Thirty lines, and the most important file in the project.
Checkpoint
npm run mcp:translatenow ends with the rules table and a per-tool verdict โ so you can see which calls would stop before running anything.The handbrake
The loop learns to stop.
yield { type: "approval_required", calls, messages }and return.Pause and resume over HTTP
Two routes:
/api/chatstarts a run and ends on a pause;/api/resumeis a brand-new request that thaws it.Checkpoint
The whole feature, in a terminal, before any React exists:
bashnpm run approval deny npm run approval approveThe report card
Checkpoint
bashnpm run evals -- --attempts 3 --label "baseline"18/18. Then break a gate rule on purpose and watch it go red โ a suite you have never seen fail is a suite you have not tested.The rewind button
Nearly free, because the events were already rows. See Replay.
Typecheck, build, ship
Checkpoint
Verify against production by exercising the actual feature:
bashcurl -sN -X POST https://YOUR-APP.vercel.app/api/chat \ -H "Content-Type: application/json" \ -d '{"message":"Empty the jar completely."}' | grep approval_requiredNot "the page loads". The gate firing, on the deployed URL.
The checkpoints, in order
Each proves one layer before the next is stacked on it, so you are never more than one layer away from a bug. The first two cost nothing.
npm run mcp:list # 1. can we reach the servers? (no AI)
npm run mcp:translate # 2. do schemas convert? what's gated? (no AI)
npm run agent # 3. does the loop chain its output?
npm run approval # 4. THE GATE โ approve AND deny
npm run evals # 5. the report card
npm run replay # 6. the rewind buttonThe two tools that lie to you
Project #3's appendix has eight entries. These two are the ones worth memorising, because in both cases the tool tells you something false with a confident face.
The other six
tsc --noEmit failing on a clean clone; Vercel un-ignoring .env.example
repeatedly; an empty trace that made replay look broken; the seatbelt that
unbuckled itself on every resume; the model asking permission and that not
being a safety feature; and project #2's own server locking this project out.
All of them, with causes and fixes, are in the compendium.