Skip to content
MCP Five

The GateProject #327 / 51

Build it

Thirteen stages, their checkpoints, and two tools that lie to you.

Project #3 copies project #2's lib/ wholesale โ€” the loop, the MCP client, the schema translation โ€” and adds a handbrake.

  1. Prerequisites, and scaffold without a fight

    ANTHROPIC_API_KEY and a DATABASE_URL. Same scaffolding gotcha, third time: temp dir, then copy in.

  2. Read the types first. Again.

    Checkpoint

    You can state, without looking, whether registerTool can declare a tool destructive (it can) and whether your host should believe it (it should not).

  3. Provision Postgres

    bash
    npx vercel install neon
    npx vercel env pull .env.local

    It 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_URL exists and its host contains -pooler.

  4. The notebook

    bash
    npm run db:init
  5. The jar that remembers

    The same cookie_jar tool, backed by Postgres instead of a variable โ€” finally fixing project #1's sandcastle. The model cannot tell the difference, which was the point.

  6. Curate the toolbox

    Project #1's forgetful jar is hidden; the secret_code collision is kept. See One shelf, many servers.

    Checkpoint

    bash
    npm run mcp:list
  7. The permission model

    Thirty lines, and the most important file in the project.

    Checkpoint

    npm run mcp:translate now ends with the rules table and a per-tool verdict โ€” so you can see which calls would stop before running anything.

  8. The handbrake

    The loop learns to stop. yield { type: "approval_required", calls, messages } and return.

  9. Pause and resume over HTTP

    Two routes: /api/chat starts a run and ends on a pause; /api/resume is a brand-new request that thaws it.

    Checkpoint

    The whole feature, in a terminal, before any React exists:

    bash
    npm run approval deny
    npm run approval approve
  10. The report card

    Checkpoint

    bash
    npm 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.

  11. The rewind button

    Nearly free, because the events were already rows. See Replay.

  12. Typecheck, build, ship

    Checkpoint

    Verify against production by exercising the actual feature:

    bash
    curl -sN -X POST https://YOUR-APP.vercel.app/api/chat \
      -H "Content-Type: application/json" \
      -d '{"message":"Empty the jar completely."}' | grep approval_required

    Not "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.

bash
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 button

The 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.