Skip to content

feat(mcp): Patchy reads and enforces read-only actions and agent tools before anything writes them - #868

Merged
allisonmahmood merged 6 commits into
mainfrom
mcp/837-readers-first
Oct 22, 2026
Merged

allisonmahmood merged 6 commits into
mainfrom
mcp/837-readers-first

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

What changed

Patchy now reads the handler fields the Patchy MCP stack will write (a handler's and its values' descriptions, readOnly on actions, and the mark on each agent tool) and enforces their rules, before any CLI writes them. Deployed ahead of the stack, it means a rollback from the stack's release lands on a release that still loads every patch published in between and still holds read-only actions to reads and agent tools to agents.

Closes #837

Look at

1. One schema, read everywhere. packages/api/src/handlers.ts gains three optional fields. readOnly is accepted only on actions, the agentTool mark only on agent.* handlers, and absent fields stay omitted (never false or null). Every reader decodes through it: the CLI and guest, the instance's inspection (which also compares the bundle's word against the manifest's, new fields included), the execution loader, Runtime and Serving's stored rows. A tier 2 bundle carrying all three, built by hand because nothing writes them yet, fails on main's schema the way it would in production today:

main: Error [ExecutionError]: Execution bind failed: load_failed.
head: ✓ loads a hand-built bundle with descriptions, holds its read-only action to reads and keeps its agent tool from pages

2. The rules, in Runtime. The invocation capability carries readOnly. The callback gate refuses a read-only action's table inserts, updates and deletes and its file puts and deletes. Nested admission refuses its mutations and actions. A marked agent tool is refused on any call from a page, nested calls and live queries included. Whether a call came from an agent is the binding's own agent field, which nothing sets until #843. Same workerd test, on main's runtime, and then for a page calling the agent tool:

main: expected { ok: false, … } to have property 'code' of 'access_denied', but got 'table_not_declared'   ← the forced write got past the gate
main: { ok: true, value: 1 }   ← the page's call to agent.lookup ran
head: access_denied, "A read-only action cannot write." / access_denied

Postgres already runs every statement inside BEGIN READ ONLY (Execution.runStatement, covered by "denies INSERT, a side-effect function and multiple statements in native read-only transactions"). The gate leaves a read-only action's connection reads open.

3. The rollback rehearsal (scripts/rollback-rehearsal.ts) now also runs when a PR changes the descriptor schemas or the CLI files that write descriptors (ci.yml). It also gains the exercise for later PRs. At step 2 it probes HEAD's SDK. Once action({ readOnly: true, … }) keeps the flag (#839), HEAD's CLI inits and publishes a tier 2 patch with a described read-only action that forces a write and a described agent/ tool. Every later step must then serve the patch, answer access_denied to the forced write and leave no note behind, and, once HEAD's build marks the tool (#840), answer access_denied to the page's call to it. Today's CLI drops the flag, so this PR's own rehearsal publishes nothing new and exercises today's bundles only.

How it was verified

  • New tests: the schema's round-trip and refusals (handlers.test.ts); the gate (CallbackGateway.test.ts); nested admission and agent tools, including a live query and a call with an agent binding (Invocation.test.ts); the hand-built bundle on real workerd (InvocationLocal.test.ts); publish and read-back, plus refusal of a manifest that drops a mark or description its bundle declares (PatchesApi.test.ts); and the loader (Inspection.test.ts). Each red on main's code as quoted above.

  • The runtime and api suites, the touched primitives, integrations, patches and execution suites, pnpm typecheck, lint and format.

  • The rehearsal's agent-area path, run locally before the rebase onto d4d6ed7. The branch was then at 6bac01d, now b25c549. A throwaway commit on top (never pushed) made the SDK keep readOnly and description, as Builders describe handlers and declare read-only actions #839 will:

    6bac01d → writer → 6bac01d   Exercised rollback paths passed … in 169s.
                                 (step 2's log: rehearsal.forcedWrite refused, access_denied; notes.list served)
    b780944 (main) → writer → b780944
                                 Step 3 of 3, the live commit (b780944) comes back, failed while exercising.
                                 /brightline/agent-area: the read-only action's forced write answered handler_failed, not access_denied
                                 /brightline/agent-area: the patch's own query answered handler_failed
    

    So once this is live, a writer PR's rehearsal passes with the patch served and the write refused by this release. Until then it fails, and that failure is the gate. The first run caught a fixture bug, fixed in b25c549. The agent-tool half waits for A tier 2 patch's agent area is its agent/ folder #840's build to mark one. Today's CLI writes neither field, so CI's rehearsal on this PR (against production's commit) logs "HEAD's CLI writes no read-only actions yet, so it publishes no agent area."

Release impact

  • Breaking — requires action from anyone already running this
  • Not breaking — no action required

Readers accept optional fields that nothing writes yet, and the new rules apply only to marks no published patch carries. Every bundle published today loads unchanged.

  • What does a revert leave behind? Nothing. There is no migration, no new row, and no CLI writes the fields, so no stored version carries them.
  • Does the release before it still work with that? Yes. Safe to ship alone. A rollback past it leaves nothing behind, as long as no release that writes the fields (Builders describe handlers and declare read-only actions #839 onward) has been deployed.

Built by Claude Opus 5.5 (xhigh) in Claude Code on T3 Code; reviewed and accepted by GPT-6.1-Sol (xhigh).

@github-actions github-actions Bot added area:server Touches the server area area:ci CI, shared testing infrastructure, development scripts and tooling area:docs Touches the docs area area:primitives Patch tables and files area:integrations Company connections and integration implementations size:l 501-1,000 changed lines labels Oct 22, 2026
@allisonmahmood

allisonmahmood commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner Author

Review: GPT-6.1-Sol (xhigh), two rounds

Round 1, on 2d7355f. Nothing blocking. Checked: every descriptor reader (CLI and guest, instance inspection, execution loader, stored-row decode, Runtime, Serving); write paths a read-only action could take (integrations, file adoption, files.inspectUpload, shared stores, nested queries); ways a page could reach an agent tool (live queries, nested calls, dev execution); the rehearsal; and the tests.

  • Should-fix: the rehearsal's CI trigger (.github/workflows/ci.yml) left out packages/patchy/src/config.ts, whose ValueSchema.toJSON() writes value descriptors. Fixed in 5daebd8.

Then a local run of the rehearsal's agent-area path caught a fixture bug: the forced write returned Promise<unknown> under result: t.json(), so the repo failed tsc. The run used a throwaway writer commit (never pushed). Fixed in 6bac01d. With that, 6bac01d → writer → 6bac01d passed and b780944 (main) → writer → b780944 failed at step 3, as the PR body shows.

Round 2, on 6bac01d. Nothing blocking.

  • Should-fix: the server-failure filter skipped every access_denied on the agent-area patch, and with no agent area it skipped unattributed access_denied events, because both patch ids were undefined. A runtime refusal is already recorded as refused, not failure (RuntimeApi.recordFailure), so the filter was unnecessary. Fixed in 421a51d by removing it; serverFailures is back to its original form.

Commit ids above predate the rebases onto d4d6ed7 and 5f474a6: 2d7355f → 972f904, 5daebd8 → 200bcf3, 6bac01d → b25c549, 421a51d → 1a86c18. Head is now 4e5b744: a docs reflow, plus WideEvents.layerNoop in the new workerd test, which Local.make needs since #865.

allisonmahmood and others added 6 commits October 22, 2026 11:14
…s before anything writes them

Handler descriptors gain an optional description on handlers and values,
readOnly on actions, and the agentTool mark on agent.* handlers. Every
reader decodes them through the shared schema, and absent fields stay
omitted, so every bundle published today loads unchanged.

A read-only action's invocation capability carries its flag: the callback
gate refuses its table and file writes, and nested admission refuses its
mutations and actions. Postgres already runs inside BEGIN READ ONLY.
Runtime refuses a marked agent tool on any call from a page, nested calls
included; whether a call came from an agent is the binding's own field,
never set yet.

The rollback rehearsal also runs when descriptors or what the CLI writes
into them change. Once HEAD's CLI writes read-only actions, step 2
publishes a tier 2 patch with one and an agent tool, and the live release
must serve it and enforce both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ady recorded as refused

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Acceptance: PASS with notes

Checked 4e5b7441083e469255fa3d9e29c179ae5871f34c (base 5f474a68c2d43cca5bf10d80d01167db7bb6ffa4) on a fresh, throwaway brightline instance, by GPT-6.1-Sol (xhigh) in the Codex harness on T3 Code. I did not write this change. Production was not accessed.

Done means

  • Described tier 2 bundles publish and serve; existing bundles still load: passed. Independently built and published a workerd bundle carrying handler/value descriptions, read-only actions and marked agent query/mutation/action handlers. Publish returned HTTP 201. Its page connected through the real browser transport and called its ordinary query. Existing Brightline tier 0, 1 and 2 patches published and loaded. Removing readOnly, agentTool or a handler description from the manifest while retaining it in the bundle returned HTTP 422 invalid_manifest in each case. Schema round-trip, inspection, publish/read-back and loader coverage passed in the local suites.
  • Read-only writes are refused and Postgres is read-only: passed. Real HTTP calls refused table insert/insertMany/update/delete, file put/delete, and nested mutation/action admission with access_denied. Table reads, file-byte reads and a nested query succeeded; ordinary actions retained their writes. The note count and original file bytes remained intact. The native Postgres test “denies INSERT, a side-effect function and multiple statements in native read-only transactions” passed.
  • Pages cannot call marked tools, including nested calls: passed. Direct page calls to marked query/mutation/action handlers and an ordinary action's nested call were refused. The actual sandboxed browser also received access_denied for a direct agent call and an agent live query. An unmarked agent.* query remained callable. Trusted-agent binding coverage passed in Invocation.test.ts.
  • Rollback rehearsal: current-bundle path passed; future writer path not run in this acceptance. The head CI rehearsal passed all three local steps, d77baaf → ffe9988 → d77baaf (ffe9988 is CI's PR merge ref). It explicitly logged: “HEAD's CLI writes no read-only actions yet, so it publishes no agent area.” See the limitation below.
  • Release impact accurately says safe alone: passed. No migration, data rewrite/deletion, infrastructure change or CLI descriptor writer is introduced. The answers correctly make rollback safety conditional on no later writer release having shipped.

Golden journeys

  • Publish a page: passed. The environment's CLI published a static page; Jordan saw its content and Home entry. Retirement replaced the content with the retirement notice, and restore served the original content at the same address.
  • Share and unshare: passed. CLI public sharing returned the content to a signed-out reader with HTTP 200; switching back to company returned HTTP 401 with the sign-in door.
  • Find and open a tool: passed. Jordan searched Home for kudos, got one match, and opened its frame.
  • Use a tier 1 tool live: passed. Jordan sent “Acceptance 868: thank you for checking the read-only rules.” Priya's already-open page showed the new message and the wall count changed from 14 to 15 without reloading. Screenshot attached.
  • Use a tier 2 tool: passed. Jordan moved Verdant Grocers from Lead to Discovery; Allison's already-open board showed Lead 3 / Discovery 4 and the moved card without reloading. Jordan moved it back, verified at Lead 4 / Discovery 3. Spend refused Allison's own $600 request with “You can't approve your own request.” Screenshots attached.

Rollback answers: match the diff. This is the reader/enforcer release; rolling back past it remains safe only before a subsequent release writes the new fields. A later writer release must retain this release as its rollback floor.

Evidence

Local focused command:

pnpm exec vitest run packages/api/src/handlers.test.ts packages/execution/src packages/runtime/src packages/patches/src/PatchesApi.test.ts packages/primitives/src packages/integrations/src/postgres
Test Files  54 passed (54)
     Tests  566 passed (566)
Independent HTTP and CLI results
PASS publish: HTTP 201; descriptions, readOnly and agentTool accepted in a real workerd bundle.
PASS read-only action: table read, file bytes and nested query succeed; ordinary action writes succeed.
PASS read-only insert: access_denied.
PASS read-only insertMany: access_denied.
PASS read-only update: access_denied.
PASS read-only delete: access_denied.
PASS read-only put: access_denied.
PASS read-only fileDelete: access_denied.
PASS read-only nestedMutation: access_denied.
PASS read-only nestedAction: access_denied.
PASS page agent.lookup: access_denied.
PASS page agent.change: access_denied.
PASS page agent.act: access_denied.
PASS page demo.reachAgent: access_denied.
PASS unmarked agent.*: ordinary page handler still callable.
PASS manifest drops readOnly: HTTP 422 invalid_manifest.
PASS manifest drops agentTool: HTTP 422 invalid_manifest.
PASS manifest drops description: HTTP 422 invalid_manifest.
PASS served page: signed-in HTTP 200.
PASS publish a page: CLI publish succeeded; Jordan sees its content and its Home entry.
PASS share public: signed-out HTTP 200 with published content.
PASS unshare: signed-out HTTP 401 with sign-in door.
PASS retire: retirement notice replaces the published content.
PASS restore: same address serves the original content, HTTP 200.

Every environment CLI invocation used env -u PATCHY_API_URL -u PATCHY_API_TOKEN PATCHY_STATE_DIR=<env>/cli-state <env>/bin/patchy ….

All checks reported by gh pr checks 868 passed on this head, including CI (Node 22/24/26 tests, browser, both CLI smoke jobs, tier 2 smoke, Postgres concurrency, live Clerk, lint, dependency review and rollback rehearsal), image and label checks.

Surfaces exercised: the wire schema and readers, runtime capability/callback/nesting rules, stored manifest and bundle agreement, existing scripted tiers, CLI publishing and reverse states. Reviewed the generated API documentation, runtime vocabulary, rehearsal and CI trigger. No migration or company-resource locking change applies.

Not run

  • A synthetic future writer commit through the complete three-step rollback rehearsal. This head's SDK/CLI intentionally drops the new writer fields, so the unchanged harness skips that branch. The author's earlier synthetic-writer rehearsal is recorded in the PR body; it was not independently repeated at this head. I verified the reader/enforcer behavior with hand-built bundles on the actual instance and browser, and read the successful current CI rehearsal's log.
  • Live Clerk was not run locally; the head's clerk-live CI check passed. Sign-in uses local personas for this acceptance.

Notes

  • The future writer release still needs its own acceptance at its final head, including the full rollback exercise with the agent mark emitted. This verdict does not treat today's deliberate skip as proof of that future writer path.
  • The custom browser fixture deliberately makes forbidden calls; their HTTP 403 resource messages are expected. The ordinary scenario pages had no unexpected browser errors.

Evidence screenshots contain only invented Brightline scenario data.

browser-rules

kudos-live

business-live

spend-refusal

@allisonmahmood
allisonmahmood merged commit dd3f41f into main Oct 22, 2026
14 checks passed
@allisonmahmood
allisonmahmood deleted the mcp/837-readers-first branch October 22, 2026 09:37
allisonmahmood added a commit that referenced this pull request Oct 22, 2026
…874)

## What changed

Release 16's What's new entry, written from `dd3f41f`. It covers
everything merged since release 15's `through` (`9e4b0df`), and sets the
`patchy` release to `0.16.0` (`packages/patchy/package.json` and
`CURRENT_RELEASE`).

| Change | PRs |
| --- | --- |
| Fixed: Revoke all machines stops logins still on their way | #867 |
| Behind the scenes: `mcp` and `oauth` kept off company addresses | #863
|
| Behind the scenes: read-only actions and agent tools understood and
enforced before anything writes them | #868 |
| Behind the scenes: logs record how long a tool's server takes to start
| #865 |

#814 is release 15's own entry, so it's left out. #818 and #831 are docs
(Patchy is live; the Patchy MCP spec) and #864 is dev tooling, so none
of them gets a line.

## Look at

- **The entry**, at the top of `releases` in
`packages/core/src/whatsNew.ts`. #867 is the only change a person could
notice. The page's button is still labelled "Revoke all machines"
(Disconnect everything is the spec's future name), so the entry uses
that label.
- **Rollback safety, from the live commit `d77baaf` to `dd3f41f`.** No
PR in the range is labelled `one-way`, and every PR answers both Release
impact questions with "Yes".
- #867 is the only migration: `0019_credentials_ended` adds two nullable
columns, `users.credentials_ended_at` and `device_logins.confirmed_at`.
At `d77baaf`, every insert into `users` and `device_logins` lists its
columns, and nothing reads either table with `SELECT *`.
- `rollback-rehearsal` passed on #863, #865, #867 and #868. #868's run
covered #867's migration already on main: `Exercised rollback paths
passed: d77baaf → ffe9988 → d77baaf`.
- A rollback would reopen what #867 closes: an approved login that
hasn't finished could again get past Revoke all machines. It would also
let new companies take the `mcp` and `oauth` addresses (#863). No
release that writes read-only actions or agent tools has shipped, so
going back past #868 leaves nothing behind.

## How it was verified

- `vitest run packages/core/src/whatsNew.test.ts
packages/api/src/schemas.test.ts`: 14 passed.
- `pnpm typecheck`: 23 of 23 tasks pass. Prettier and eslint are clean
on the changed files.
- The live commit was pinned from `/healthz/deep` (`d77baaf`, release
15). The Deploy run updated last succeeded, and none is unfinished.

## Release impact

- [ ] **Breaking** — requires action from anyone already running this
- [x] **Not breaking** — no action required

The changelog text plus the `patchy` version bump. A CLI installed
before this deploy is told to upgrade, as with every release.

- **What does a revert leave behind?** Nothing. People whose seen marker
reached 16 would just see no new release.
- **Does the release before it still work with that?** Yes.

If this release misbehaves, roll back to
`d77baafcf10c7cdf28c71bd65ea1a0009aa99ced` (release 15).

Built by Claude Opus 5.5 (xhigh) in Claude Code on T3 Code.

Co-authored-by: Claude Opus 5.5 <[email protected]>
allisonmahmood added a commit that referenced this pull request Oct 23, 2026
…869)

Bottom of #833's stack (#839–#860), now on `main` since #837 merged as
#868. It merges with the rest of the stack, not alone.

## What changed

Builder agents can now say what each handler and value is for, and
declare an action that only reads. `action({ readOnly: true, … })` gives
the handler a context with no writes. Patchy refuses a write forced past
the types. The published manifest carries the flag and every
description. Nothing requires a description yet; agent tools will
(#842).

Closes #839

## Look at

**1. A read-only action's context has no writes.** Part of the
compile-only checks in `packages/patchy/src/server.types.ts`. Every
`@ts-expect-error` holds, so each write is a type error:

```ts
export const peek = action({
  readOnly: true,
  description: "Counts leads and totals sales without changing anything.",
  args: { stage: t.enum(["open", "closed"]).describe("Which leads to count.") },
  result: t.object({ count: t.integer().describe("Matching leads."), total: t.number() }),
  handler: async (ctx, args) => {
    await ctx.files.documents.get("invoice.pdf");            // reads stay
    await ctx.connections.sales.query("select …");           // connections stay
    await ctx.run.leads.list({ stage: null });               // queries stay
    // @ts-expect-error a read-only action cannot insert rows
    await ctx.tables.leads.insert({ name: "forbidden" });
    // @ts-expect-error a read-only action runs queries only, never mutations
    void ctx.run.leads.save({ name: "forbidden" });
    …
```

`readOnly: true` on a query or mutation is a type error, and the
descriptor schema refuses it at build and inspection. At runtime the
guest still hands a read-only action an action's table object. That way
a forced `ctx.tables.notes.insert` reaches #837's gate and gets
`access_denied` (`InvocationLocal.test.ts`, now with SDK-built
handlers). The rollback rehearsal's step 2 needs exactly that.

**2. One description check, run on what inspection returns.**
`descriptionProblem` in `packages/api/src/handlers.ts` returns a
structured `DescriptionProblem`, and `descriptionRefusal` says it. They
run in three places: the CLI's build, dev rebuilds and the instance's
publish. Each runs on the descriptors inspected from the bundle, and
each refusal is `invalid_manifest` naming the handler, the value and the
fix. The CLI's also names the file, as the spec's Checks paragraph asks;
the instance's comes from `InvalidHandlerDescription`:

```
server/leads.ts: leads.read's description of result is 2,001 characters; descriptions are at most 2,000. Shorten it. The last successful binding stays served.
demo.find's description of args.name is blank. Say what it holds, or remove its .describe().
```

The SDK builders don't refuse at construction. Inspection runs the
bundle in workerd and reports only "could not be loaded", so a throw
from `.describe()` would hide the fix. A blank literal is still a type
error (`NonEmptyString`, as for table descriptions). Length is counted
in code points, like a patch description.

**3. Columns take no description.** `.describe()` turns a column into a
handler value, so `table()` refuses it by type. Config execution refuses
one forced past the types: `Column "title" of table "notes" has
.describe(), but table columns take no description. Remove .describe(),
and say what the column holds in the table's description.`

When a nullable wrapper and its value are both described, the descriptor
keeps both. The JSON Schema mapping in #842 shows the outer one; the
skill states the rule.

## How it was verified

- Typecheck of `api`, `patchy`, `sdk`, `patches` and `runtime`, plus
`tsconfig.test.json`. `server.types.ts` and `config.types.ts` hold the
type-level Done means: the read-only context, the flag refused on
queries and mutations, blank literals, and described columns, defaults
and refs.
- `vitest`: `api` (the shared check: blank, 2,001 code points, nested
paths), `patchy/server.test.ts` (descriptors written, absent fields
omitted, the flag refused past the types), `executeConfig.test.ts` (the
described-column refusal), `devServerWatch.test.ts` (a dev rebuild
refuses and recovers), `PatchesApi.test.ts` (an SDK-built read-only
action publishes, and a hand-rolled publish with a bad description is
refused at the instance), `InvocationLocal.test.ts`,
`Inspection.test.ts`, `sdk`.
- Rollback rehearsal: `main` now has #837 and #838, and against it all
three steps pass: `pnpm test:rollback-rehearsal --live dd3f41f` gives
`Exercised rollback paths passed: dd3f41f → 0cec8f4 → dd3f41f, in 188s.`
This PR switches on step 2, which publishes a read-only action that
forces a write. CI's run against production's d77baaf passes step 2 and
fails step 3. d77baaf predates #837, so it answers the forced write with
`handler_failed`. That's the gate #833 documents, and it stays red until
`main` with #837 is deployed.

## Release impact

- [ ] **Breaking** — requires action from anyone already running this
- [x] **Not breaking** — no action required

The SDK fields are optional and additive. The new refusals apply only to
descriptions, which nothing wrote before.

- **What does a revert leave behind?** Versions whose stored descriptors
carry `description` and `readOnly: true`.
- **Does the release before it still work with that?** Yes, as long as
it includes #837, which reads and enforces both fields. #833 releases
this stack only after #837 is live.

Built by Claude Opus 5.5 (xhigh) in Claude Code on T3 Code; reviewed and
accepted by GPT-6.1-Sol (xhigh).
allisonmahmood added a commit that referenced this pull request Oct 23, 2026
)

Stacked on #883 (ticket #851); merges with the rest of #833's stack, not
alone.

## What changed

A person's agent can now find their company's patches through Patchy's
MCP and open one to see its agent tools. `find_patches` lists exactly
the patches the person can open in the portal; `open_patch` answers one
patch's own document. While the company's agent access is off, every
tool call is refused and names the admins.

Closes #852

## Look at

1. **Visibility reuses the portal's rule.** `Catalogue.visible` is
`Patches.read({ state: "live" })` through `Patches.Openability`, the
same call the portal's All patches makes, then one new query,
`Patches.agentToolSummaries`, for the current versions' tool marks and
words. It doesn't load whole manifests and starts nothing.
`apps/server/src/McpDoor.test.ts` checks it against the portal's own
rendered list. It publishes through the API across sharing scopes
(company, public), lifecycle states (live, retired, deleted,
operator-disabled), a deactivated owner and a second company. Then it
compares `/patches` with `find_patches` for an owning admin, a
non-owning admin, a member and a member who owns only off patches. Every
listed patch opens. Every other one, by name, id or address, gets the
same refusal, and searching its name finds nothing. Making the door list
off patches fails it, and four catalogue tests.
2. **Choices within the spec's words**, for Allison to see:
- `search` matches when every word appears in the name, title,
description or owner's name, ignoring case.
- The cursor is base64url JSON `{ after: { tools, name, id }, search?,
detail? }`: a keyset position, so a publish or retire between pages
never repeats or skips one. It carries its search and detail, so `{
cursor }` alone continues a walk; a cursor sent with a different search
or detail is refused `invalid_args`. A forged cursor only positions
within the person's own list: pointing it at a hidden patch, another
company's, or none gives the same page.
- `patch` resolves an id first (ids never change), then a name through
`Patches.resolveName`, so a former name follows its rename as the
address does. An address must have this instance's origin and the
person's company handle. Every miss is one `not_found` in the same
words.
- `actingFor` is `{ person, company }`, each cut at 200 characters. A
find page is measured as it grows, so its compact JSON never passes
100,000 characters; a patch whose tools alone would pass it (only a
version that skipped the publish check could) is listed with their
names, or without them. `open_patch` refuses `too_large` past 64 KiB,
which only a version that skipped the publish check could reach.
- The `agent_access_off` refusal names where an admin turns it on and
the active admins by name, nothing else.
3. **Events** gain `patchRef`, `catalogueTotal`, `catalogueListed`,
`catalogueEndedEarly`, `catalogueSearched`, `catalogueDetail` and
`catalogueContinued`, beside `patchId`, `versionId` and `resultBytes`.
Never the search words or the cursor.

## How it was verified

- `packages/mcp`: `Catalogue.test.ts` covers a narrower openability
rule, order, 55 patches over two pages with a publish and a retire
between them, the read cap with `detail: "tools"`, search, cursor
tampering, bad arguments, resolution by name/id/address/former name,
other instances' and companies' addresses, and the 64 KiB cap.
`Door.test.ts` covers the agent access refusal for a member and an
admin, with discovery and the tool list still working. The shared
harness moved to `src/test/door.ts`.
- `packages/patches`: `agentToolSummaries` by version. `packages/api`:
summaries keep `open_patch`'s order.
- `pnpm verify` on 90262f1: format, lint, typecheck, synth,
postgres-concurrency, cli-smoke, tier2-smoke and browser passed. In
`test`, 2237 of 2239 passed. The two that timed out under the machine's
load are in packages this PR doesn't touch: `cliRepoBuild.test.ts` (30
s) and `SdkApi.test.ts` (5 s). Both pass alone, and in CI. Every CI
check is green on 90262f1. clerk-live passed on a rerun: its two live
tests had passed and only the cleanup sweep got a Clerk 404.
- No migration, so `rollback-rehearsal` has nothing to rehearse. #837
(PR #868) and #838 (PR #867) are both on `main`.
- Real clients against a dev instance, on the final head: Claude Code
2.1.308 through real consent, and Codex 0.163.0 with a minted token on
both its revisions. Each found Ben's 56 patches over two pages (50 + 6),
with `deal-desk` first as the one with agent tools, and opened it, by
name and by address. With agent access off, each call was refused naming
Ada Park, the admin.

<details><summary>Real clients against a dev instance,
transcripts</summary>

A `pnpm dev up team` environment (Acme Co: Ada Park, admin; Ben Ortiz,
member) with `deal-desk`, a tier 2 patch whose `agent/deals.ts` exports
`listDeals` and `moveDeal`, and 55 static pages, `standup-week-01` to
`-55`, all published by Ada. Every client ran as Ben from a temp dir
outside `$HOME`, with only that invocation's MCP config. Tool results
are cut to 220 characters here.

### Claude Code 2.1.308 through real consent

`claude --setting-sources project --strict-mcp-config --mcp-config
./mcp.json`, then `/mcp` › Authenticate. A stub `xdg-open` on its `PATH`
recorded the authorize URL instead of opening a browser. A headless
Playwright browser signed in as Ben
(`/dev/[email protected]&return=<authorize>`), saw the consent
page below and pressed Allow:

~~~text
consent <instance>/oauth/authorize — Connect Claude Code to Acme Co?
returned to
http://localhost:63680/callback?code=…&state=…&iss=<instance>
Authentication successful | You can close this tab and return to Claude
Code.

❯ /mcp
  ⎿  Authentication successful. Connected to patchy-dev-852.
~~~

![Connect Claude Code to Acme Co? as Ben
Ortiz](https://github.com/user-attachments/assets/f25486d8-8b1f-4e51-8d6b-4e9c6e838a82)

Then `claude -p` with the same config:

~~~text
tool_use mcp__patchy-dev-852__find_patches({})
-> {"actingFor":{"person":"Ben Ortiz","company":"Acme
Co"},"total":56,"patches":[{"name":"deal-desk","description":"Track the
sales team's open deals and move them through stages.","owner":"Ada
Park","address":"<instance>/…
tool_use mcp__patchy-dev-852__find_patches({"cursor":
"eyJhZnRlciI6eyJ0b29scyI6ZmFsc2UsIm5hbWUiOiJzdGFuZHVwLXdlZWstNDkiLCJpZCI6IjhwdXU4d3FqbXhzbSJ9fQ"})
-> {"actingFor":{"person":"Ben Ortiz","company":"Acme
Co"},"total":56,"patches":[{"name":"standup-week-50","description":"Team
standup notes for week 50: what shipped and what is next.","owner":"Ada
Park","address":"<instance>/…
tool_use mcp__patchy-dev-852__open_patch({"patch": "deal-desk"})
-> {"name":"deal-desk","description":"Track the sales team's open deals
and move them through stages.","owner":"Ada
Park","address":"<instance>/acme/deal-desk","tools":[{"name":"listDeal…
assistant: Acme Co has **56 patches**, and listing them took **2
pages**. I'm acting for Ben Ortiz.

- **Page 1:** 50 patches, which were `deal-desk` and `standup-week-01`
through `standup-week-49`. It returned a `next` cursor.
- **Page 2:** 6 patches, `standup-week-50` through `standup-week-55`. It
had no `next`, so that was the end.

That adds up to the server's reported total of 56: one `deal-desk` plus
55 weekly standup notes.

**Only one patch has agent tools: `deal-desk`**, owned by Ada Park. It
tracks the sales team's open deals and moves them through stages. None
of the 55 `standup-week-*` patches (also Ada Park's) have any agent
tools, so I can't read or change them through Patchy. Ada Park would
need to add tools for that.

### `deal-desk` tools

1. **`listDeals`** (read)
   - Lists the team's deals, newest first.
- You can pass an optional `stage` to see only deals in that stage:
`lead`, `proposal`, `negotiation`, `won` or `lost`.
- Each deal comes back with its `id`, `company` (the customer), `stage`,
`amount` (value in euros), `createdAt` and `updatedAt`.

2. **`moveDeal`** (change)
   - Moves one deal to a different stage and returns the updated deal.
   - It returns `null` if no deal has that id.
- It needs both an `id` (taken from `listDeals`) and a target `stage`
(same five options).
   - Any move is logged as Ben Ortiz, made through me.

I only opened the patch. I haven't listed any deals or moved anything.
~~~

With agent access turned off at Company by Ada:

~~~text
tool_use mcp__patchy-dev-852__find_patches({})
-> error: Agent access is off at Acme Co, so Patchy refuses every agent
until an admin turns it on at <instance>/company. Acme Co's admin is Ada
Park; tell the person to ask them.
assistant: The `find_patches` call didn't list any patches. It returned
an error. Here is the exact text:

> Agent access is off at Acme Co, so Patchy refuses every agent until an
admin turns it on at <instance>/company. Acme Co's admin is Ada Park;
tell the person to ask them.

Acme Co's agent access is turned off, so Patchy blocks every agent
request until it's switched on. You'll need to ask Ada Park, Acme Co's
admin, to turn it on at that URL. After that, I can run the call again
and list the patches.
~~~

Claude Code's stored token for the dev server was cleared afterwards
(`/mcp` › Clear authentication).

### Codex 0.163.0 with a minted token

`pnpm dev mcp-token ben --client Codex`, then `codex exec --ephemeral
--ignore-user-config -s read-only -c
'mcp_servers.patchy.url="<instance>/mcp"' -c
'mcp_servers.patchy.bearer_token_env_var="PATCHY_MCP_TOKEN"'`.

With agent access off, before Ada turned it on (on the first head,
before the singular "admin is" fix):

~~~text
agent: I’ll find the Patchy MCP tool and return its answer exactly.
mcp_tool_call patchy.find_patches({}) -> failed: Agent access is off at
Acme Co, so Patchy refuses every agent until an admin turns it on at
<instance>/company. Acme Co's admins are Ada Park; tell the person to
ask one of them.
agent: Agent access is off at Acme Co, so Patchy refuses every agent
until an admin turns it on at <instance>/company. Acme Co's admins are
Ada Park; tell the person to ask one of them.
~~~

On, at Codex's default revision (2025-06-18), asked: "Using the patchy
MCP server: list every patch my company has, following next until there
are no more pages. Tell me how many there are in all, how many pages it
took, and which ones have agent tools. Then open the one with agent
tools by its address and tell me what each of its tools does."

~~~text
agent: I’ll use the Patchy tools to list every page of patches, then
open the patch with agent tools and inspect what they do.
mcp_tool_call patchy.find_patches({}) -> completed:
{"actingFor":{"person":"Ben Ortiz","company":"Acme
Co"},"total":56,"patches":[{"name":"deal-desk","description":"Track the
sales team's open deals and move them through stages.","owner":"Ada
Park","address":"<instance>/…
mcp_tool_call patchy.find_patches({"cursor":
"eyJhZnRlciI6eyJ0b29scyI6ZmFsc2UsIm5hbWUiOiJzdGFuZHVwLXdlZWstNDkiLCJpZCI6IjhwdXU4d3FqbXhzbSJ9fQ"})
-> completed: {"actingFor":{"person":"Ben Ortiz","company":"Acme
Co"},"total":56,"patches":[{"name":"standup-week-50","description":"Team
standup notes for week 50: what shipped and what is next.","owner":"Ada
Park","address":"<instance>/…
mcp_tool_call patchy.open_patch({"patch": "<instance>/acme/deal-desk"})
-> completed: {"name":"deal-desk","description":"Track the sales team's
open deals and move them through stages.","owner":"Ada
Park","address":"<instance>/acme/deal-desk","tools":[{"name":"listDeal…
agent: The Patchy MCP connection is acting for **Ben Ortiz at Acme Co**.
I followed `next` until it was absent: **56 patches across 2 pages** (50
+ 6).

All patches are owned by Ada Park:

- **`deal-desk`** — the only patch with agent tools.
- **`standup-week-01` through `standup-week-55`**, inclusive — 55
standup patches with no agent tools.

I opened [deal-desk](<instance>/acme/deal-desk) by its address. Its
tools are:

| Tool | Kind | What it does |
|---|---|---|
| `listDeals` | Read | Lists deals newest first, optionally filtered by
stage. Returns each deal’s ID, customer, stage, value in euros, and
creation/update timestamps. |
| `moveDeal` | Change | Takes a deal ID from `listDeals` and a target
stage, moves the deal, and returns the updated record. Returns `null` if
the ID doesn’t exist. |

Both tools accept these stages: `lead`, `proposal`, `negotiation`,
`won`, `lost`.
~~~

With `--enable mcp_2026_07_28` it made the same three calls, with the
same answer.

### The door's request events for the final runs

| Status | Client | Era / version | Method | Tool | Code or patchRef |
Catalogue |
| ---: | --- | --- | --- | --- | --- | --- |
| 200 | Codex | legacy 2025-06-18 | tools/call | find_patches | — |
Total=56, Listed=50, EndedEarly=False, Continued=False |
| 200 | Codex | legacy 2025-06-18 | tools/call | find_patches | — |
Total=56, Listed=6, EndedEarly=False, Continued=True |
| 200 | Codex | legacy 2025-06-18 | tools/call | open_patch | name | — |
| 401 | — |   | — | — | missing_token | — |
| 200 | Claude Code | modern 2026-07-28 | server/discover | — | — | — |
| 200 | Claude Code | modern 2026-07-28 | tools/list | — | — | — |
| 200 | Claude Code | modern 2026-07-28 | server/discover | — | — | — |
| 200 | Claude Code | modern 2026-07-28 | tools/list | — | — | — |
| 200 | Claude Code | modern 2026-07-28 | tools/call | find_patches | —
| Total=56, Listed=50, EndedEarly=False, Continued=False |
| 200 | Claude Code | modern 2026-07-28 | tools/call | find_patches | —
| Total=56, Listed=6, EndedEarly=False, Continued=True |
| 200 | Claude Code | modern 2026-07-28 | tools/call | open_patch | name
| — |
| 200 | Codex | legacy 2025-06-18 | initialize | — | — | — |
| 202 | Codex | legacy 2025-06-18 | notifications/initialized | — | — |
— |
| 200 | Codex | legacy 2025-06-18 | tools/list | — | — | — |
| 200 | Codex | legacy 2025-06-18 | tools/call | find_patches | — |
Total=56, Listed=50, EndedEarly=False, Continued=False |
| 200 | Codex | legacy 2025-06-18 | tools/call | find_patches | — |
Total=56, Listed=6, EndedEarly=False, Continued=True |
| 200 | Codex | legacy 2025-06-18 | tools/call | open_patch | address |
— |
| 200 | Codex | modern 2026-07-28 | server/discover | — | — | — |
| 200 | Codex | modern 2026-07-28 | tools/list | — | — | — |
| 200 | Codex | modern 2026-07-28 | tools/call | find_patches | — |
Total=56, Listed=50, EndedEarly=False, Continued=False |
| 200 | Codex | modern 2026-07-28 | tools/call | find_patches | — |
Total=56, Listed=6, EndedEarly=False, Continued=True |
| 200 | Codex | modern 2026-07-28 | tools/call | open_patch | address |
— |
| 200 | Claude Code | modern 2026-07-28 | server/discover | — | — | — |
| 200 | Claude Code | modern 2026-07-28 | tools/list | — | — | — |
| 200 | Claude Code | modern 2026-07-28 | tools/call | find_patches | —
| Total=56, Listed=50, EndedEarly=False, Continued=False |
| 200 | Claude Code | modern 2026-07-28 | tools/call | find_patches | —
| Total=56, Listed=6, EndedEarly=False, Continued=True |
| 200 | Claude Code | modern 2026-07-28 | tools/call | open_patch | name
| — |
| 200 | Claude Code | modern 2026-07-28 | server/discover | — | — | — |
| 200 | Claude Code | modern 2026-07-28 | tools/list | — | — | — |
| 200 | Claude Code | modern 2026-07-28 | tools/call | find_patches |
agent_access_off | — |

</details>


## Release impact

- [ ] **Breaking** — requires action from anyone already running this
- [x] **Not breaking** — no action required

No migration and no stored data: the catalogue only reads.

- **What does a revert leave behind?** Nothing. Clients that called the
two tools get "not built" again, as on #883.
- **Does the release before it still work with that?** Yes.

Built by Claude Opus 5.5 (xhigh) in Claude Code on T3 Code; reviewed and
accepted by GPT-6.1-Sol (xhigh).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI, shared testing infrastructure, development scripts and tooling area:docs Touches the docs area area:integrations Company connections and integration implementations area:primitives Patch tables and files area:server Touches the server area size:l 501-1,000 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tier 2 readers accept handler descriptions, read-only actions and agent tools, and enforce them

1 participant