Skip to content

feat(mcp): builders describe handlers and declare read-only actions - #869

Merged
allisonmahmood merged 2 commits into
mainfrom
mcp/839-descriptions-readonly
Oct 23, 2026
Merged

allisonmahmood merged 2 commits into
mainfrom
mcp/839-descriptions-readonly

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

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:

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

Release impact

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

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

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:cli Touches the cli area area:docs Touches the docs area size:l 501-1,000 changed lines area:ci CI, shared testing infrastructure, development scripts and tooling labels Oct 22, 2026
@allisonmahmood
allisonmahmood force-pushed the mcp/839-descriptions-readonly branch from a021745 to 6914bda Compare October 22, 2026 08:26
@github-actions github-actions Bot removed the area:ci CI, shared testing infrastructure, development scripts and tooling label Oct 22, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

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

Round 1 (at 9b7df60)

  1. Blocking. The rollback rehearsal's forced-write handler returned Promise<unknown> for a t.json() result. Step 2's publish therefore failed typecheck, now that this PR's SDK writes readOnly and switches step 2 on. Fixed. Tier 2 readers accept handler descriptions, read-only actions and agent tools, and enforce them #837's branch fixed it in 6bac01d. This PR is rebased onto that tip and dropped its duplicate fix.
  2. Should-fix. The instance refusal carried a preformatted sentence on InvalidManifest, against the Effect service conventions. Fixed. packages/api exports a DescriptionProblem schema (handler, value, violation, length) and descriptionRefusal() to say it. The instance refuses with InvalidHandlerDescription, built from those fields; the name avoids Patches' existing InvalidDescription.
  3. Should-fix. CLI refusals didn't name the file, which the spec's Checks paragraph asks for. Fixed. descriptionFailure() prefixes server/<module>.ts: in the build and dev builds. README, ADR-0004 and the skill now say so.
  4. Note. The SDK doesn't refuse a description at construction. Kept: the spec's Checks paragraph puts the check on inspected descriptors in the CLI and on the instance. A throw at construction would surface only as workerd's "could not be loaded" and hide the fix. A blank literal is still a type error. The PR body records this.

Round 2 (at 6914bda): no findings. All three fixes verified; nothing blocking.

@allisonmahmood
allisonmahmood force-pushed the mcp/839-descriptions-readonly branch from 6914bda to ba74d58 Compare October 22, 2026 09:02
@allisonmahmood
allisonmahmood force-pushed the mcp/839-descriptions-readonly branch from ba74d58 to 2a4b34e Compare October 22, 2026 09:24
Base automatically changed from mcp/837-readers-first to main October 22, 2026 09:37
@allisonmahmood
allisonmahmood force-pushed the mcp/839-descriptions-readonly branch from 2a4b34e to 0cec8f4 Compare October 22, 2026 09:40
@allisonmahmood

allisonmahmood commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner Author

Acceptance: PASS with notes

Checked 0cec8f4ebe158cf23aa5ea0da11fa1639267358b (base dd3f41f26da57474bd53df564a8f8b8d3d029847, main) on fresh team and brightline instances, by GPT-6.1-Sol (xhigh), in the Codex harness on T3 Code.

Done means

  • Read-only action types and enforcement: passed. An independently initialized tier 2 repo, using its packed, generated SDK, typechecks with a described read-only action calling a sibling query. Replacing that read with ctx.tables.notes.insert fails typecheck. A published action forcing the insert past the types returns access_denied; subsequent reads still report zero rows. Page calls see ctx.agent === null. The focused runtime and inspection suites also passed, including forced nested mutation refusal and rejecting readOnly on queries.
  • Descriptions reach the published manifest: passed. Read the version actually stored by the throwaway instance: handler, argument, nested nullable/array and result descriptions survive; the descriptor remains kind: "action" with readOnly: true. Undescribed starter handlers still publish. Builder tests also preserve both inner and outer nullable descriptions.
  • Invalid descriptions and described columns: passed. Independent packed CLI publishes refuse a blank handler description, a nested 2,001-character value description and .describe() on a table column, each with invalid_manifest and a fix. Exactly 2,000 astral Unicode code points publish successfully. The focused API suite passed its hand-rolled-publish checks for blank and overlong descriptions (HTTP 422), and the watcher suite passed refusal and recovery.

Golden journeys

  • Publish a page: passed. Packed tier 2 publish on team; each rehearsal step also publishes the static rehearsal page using that build's CLI.
  • Find and open a tool: passed. The rehearsal exercises the portal and every brightline patch, checks sample data and live-query delivery, and repeats after upgrade and rollback.
  • Use a tier 1 tool live: passed in head CI's browser suite. This includes a colleague's write updating the subscribed screen and reconnect catching a missed write.
  • Use a tier 2 tool: passed. Independent page-principal read-only calls and denied writes, plus all three rehearsal steps. The same green browser job covers two viewers staying in sync through ordinary server mutations and shared-source recovery.

Rollback answers: Match the diff for the prerequisite release specified by #833. A revert leaves published descriptors carrying descriptions and readOnly; dd3f41f, which contains #837 and #838, reads and enforces them. Independently reran all three steps successfully:

pnpm test:rollback-rehearsal --live dd3f41f
Step 1: dd3f41f seeds the data — passed in 114s
Step 2: 0cec8f4 upgrades it — passed in 50s
Step 3: dd3f41f comes back — passed in 65s
Exercised rollback paths passed: dd3f41f → 0cec8f4 → dd3f41f, in 230s.

Not run

  • Full pnpm verify and live Clerk were not rerun locally on the shared, loaded machine. Inspected the head's CI results: lint/typecheck, tests on Node 22/24/26, browser, CLI smoke on Node 22/26, tier 2 smoke, Postgres concurrency and live Clerk all passed. The rollback check is the exception below.

Notes

  • The required production-based rollback check remains red. Its log confirms steps 1 and 2 pass, then step 3 on d77baaf answers handler_failed instead of access_denied for the forced write. This is the prerequisite deployment gate documented in #833, not an unexplained regression: the readers must be deployed before this stack is released. This verdict does not make the PR merge-ready or waive that gate.
  • The initial single-worker focused run had 158 passed / 2 failed across 11 files. The ancillary archive-retention test hit its 5-second timeout; an installer expectation encountered the machine's existing global patchy on Node 26's PATH. Reran both complete SDK files on Node 24, whose bin has no global patchy: 26/26 passed, without source edits or timeout changes.
  • Mirrored surfaces checked: API refusal and docs; CLI exit contract, README and ADR-0004; generated server types and the release-bound patchy-server skill. No migrations, infrastructure, served-page layout, resource provisioning, reverse-state or package-layout changes.
  • Cleanup complete: pnpm dev down removed the team instance; the rehearsal exited 0 and removed its scratch worktree and scenario workspace. Recorded instance, rehearsal and test PIDs are gone. No processes belonging to other runs were stopped.
Independent packed CLI probe output
Packed generated types: the described read-only action and sibling query typecheck.
Type refusal: Property 'insert' does not exist on the read-only action's notes table.
Stored published manifest: kind=action, readOnly=true; handler, argument, nested and result descriptions retained; legacy undescribed handler retained.
Runtime page calls: read-only action runs sibling query; ctx.agent=null; forced write returns access_denied; row count stays 0.
Blank handler description: exit 1 invalid_manifest; server/acceptance.ts: acceptance.read's description is blank. Say what it does, or leave the description out.
Nested 2,001-character value description: exit 1 invalid_manifest; server/acceptance.ts: acceptance.peek's description of args.filter[] is 2,001 characters; descriptions are at most 2,000. Shorten it.
Unicode boundary: a nested description of 2,000 astral code points publishes successfully.
Described table column: exit 1 invalid_manifest; 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.
PASS: independent packed CLI, stored-manifest, type and runtime probes.

@allisonmahmood
allisonmahmood force-pushed the mcp/839-descriptions-readonly branch from 0cec8f4 to 8434931 Compare October 23, 2026 02:08
@allisonmahmood allisonmahmood mentioned this pull request Oct 23, 2026
action({ readOnly: true, ... }) types its handler with a
ReadOnlyActionContext: an action's reads, no writes, and ctx.run for
queries only. The descriptor carries readOnly: true, its kind stays
action, and the flag on a query or mutation is refused by the types and
the descriptor schema. A write forced past the types still reaches the
host's gate, which #837 taught to refuse it.

Every handler takes an optional description and every handler value
.describe(text). Blank literals are type errors. The CLI's build and dev
builds, and the instance's publish, run one shared check on the
inspected descriptors, so a blank or over-2,000-character description is
invalid_manifest naming the handler and the fix. Inspection runs in
workerd and reports only that a bundle failed to load, so the SDK
doesn't refuse at construction, where the message would be lost.

.describe() turns a column into a handler value, so table() refuses it
by type, and config execution refuses one forced past the types with a
message saying how to fix it.

ctx.agent is in every handler context as { name } | null, always null
until agent tools run for agents. The generated server module exports a
bound ReadOnlyActionContext for helpers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The shared check now returns where the problem is and what it is, and one
formatter says it. The instance refuses with InvalidHandlerDescription,
built from those fields, instead of a preformatted sentence on
InvalidManifest. The CLI's build and dev builds name the handler's file,
as the spec's Checks paragraph asks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood force-pushed the mcp/839-descriptions-readonly branch from 8434931 to 706e730 Compare October 23, 2026 11:34
@allisonmahmood
allisonmahmood merged commit 844eaf1 into main Oct 23, 2026
14 checks passed
@allisonmahmood
allisonmahmood deleted the mcp/839-descriptions-readonly branch October 23, 2026 11:49
allisonmahmood added a commit that referenced this pull request Oct 23, 2026
Stacked on #869 (ticket #839); merges with the rest of #833's stack, not
alone.

## What changed

A tier 2 patch can now have tools for people's agents: every export of a
root `agent/*.ts` file publishes as an agent tool named after its
export, with no `refresh`. The page can't import or call them. #837's
readers already refuse page calls to them; this PR is what first writes
the mark.

Closes #840

## Look at

**1. The build folds `agent/` into one module named `agent`.** The
generated entry in `packages/patchy/src/serverBuild.ts` passes `agent/`
files by name to `createGuest`. `foldAgentArea` in
`handlerDescriptors.ts` merges them, and `extractHandlerDescriptors`
marks each `agent.<export>` descriptor `agentTool: true`. A re-export is
one handler under two names, unmarked for the page. Published on a dev
instance, from a fresh `patchy init --tier 2` plus this file, with no
refresh:

```ts
// agent/deals.ts
export { list } from "../server/notes.js";
export const addNote = mutation({ description: "Adds a note with a title. Refuses a blank title.", … });
```
```
$ patchy publish --json | jq -c '[.handlers[].name]'
["agent.addNote","agent.list","notes.create","notes.list"]
```

Inspection returns `agent.list` with `"agentTool": true` and
`notes.list` without it.

**2. Duplicate names are refused naming both files, `export *`
included.** The guest's fold reads the real module namespaces, so it
knows exactly which two files export a name. Inside workerd, though, a
throw while loading loses its message. So `createGuest` answers every
request with its refusal instead of throwing (`guest.ts`).
`packages/execution/src/inspection.ts` reports that answer as reason
`refused`, carrying its text as `problem`, and the CLI's publish and dev
builds show it. The instance keeps its generic `invalid_manifest` and
never echoes text from a bundle, and a refused bundle never binds.
Statically following `export *` was tried and dropped after review (see
the review comment). The build reads each file's own export statements
only to name a tool's file in #839's description refusals, or
`agent/*.ts` when there is none. The four refusals and the warning, from
the same dev repo:

```
$ patchy publish --json   # agent/crm.ts re-exports addNote from agent/deals.ts
{"ok":false,"error":"addNote is exported by agent/crm.ts and agent/deals.ts; each tool needs its own name.","kind":"local","code":"invalid_manifest"}
$ patchy publish --json   # with server/agent.ts
{"ok":false,"error":"server/agent.ts: Agent tools live in agent/; move these exports there.","kind":"local","code":"invalid_manifest"}
$ patchy publish --json   # src/App.tsx imports ../agent/deals.js
{"ok":false,"error":"src/App.tsx imports \"../agent/deals.js\", but the page can't import agent/ at runtime. Agent tools are for people's agents only; call server/ handlers through patchy.server.","kind":"local","code":"import_refused"}
$ patchy publish --json | jq -c '{ok, warnings}'   # tsconfig.json include without agent
{"ok":true,"warnings":["tsconfig.json doesn't include agent/, so pnpm typecheck skips your agent tools. Add \"agent\" to its include list."]}
```

`agent/` below tier 2 is `tier_mismatch` (`agent/ requires tier 2.
Change the tier and run \`patchy refresh\`, or remove agent/.`), from
the same check as `server/` (`repoBuild.test.ts`). Page imports from
`server/` now get the same kind of fix-it message instead of the generic
package one.

**3. The dev watcher watches `agent/` beside `server/`.**
`devServerWatch.ts` keeps one directory watch per folder and restarts
the Vite watcher when either file list changes. A new agent file rebinds
with no refresh reminder. The tsconfig check runs whenever the agent
file list changes.

## How it was verified

- `vitest`: `devServerWatch.test.ts` covers, on real Vite and workerd
builds:
- a re-export plus a tool of its own, folded and marked with no refresh;
- a named duplicate and an `export *` duplicate, each refused naming
both files in watch, and through inspection of publish's `buildServer`
output;
  - ambiguous `export *` and a `__proto__` file building cleanly;
  - recovery;
  - an agent tool's blank description naming `agent/intake.ts`.

`Inspection.test.ts` carries a guest's refusal as `refused` and no other
failure's text, and `guest.test.ts` covers the refusing guest. Also
`server.test.ts`, `serverModules.test.ts`, `pageImports.test.ts`,
`repoBuild.test.ts`, `initProject.test.ts` and the bundled-CLI suites.
#837's fixtures for older `server/agent.ts` bundles
(`InvocationLocal.test.ts`, `PatchesApi.test.ts`) still pass.
- Typecheck of `patchy` and `tsconfig.test.json`; lint on the changed
files.
- Hand-checked on this worktree's dev instance, as above. `~/Patchy`
gained nothing.
- Rollback rehearsal: against `main` dd3f41f, which has #837 and #838:
`pnpm test:rollback-rehearsal --live dd3f41f` gives `Exercised rollback
paths passed: dd3f41f → bde24e7 → dd3f41f, in 208s.` Step 2 publishes
the rehearsal's `agent/notes.ts` through HEAD's CLI, which marks
`agent.countNotes` as an agent tool, and both releases refuse the page's
call to it. CI's run against production's d77baaf fails at step 3,
because d77baaf can't read the new descriptor fields. That's the gate
#833 documents until #837 is live.
- `pnpm verify` on bde24e7: format, lint, typecheck, synth,
postgres-concurrency, cli-smoke, tier2-smoke and browser pass. The test
stage had seven timeouts while other lanes loaded the machine. Its seven
failing files, rerun alone with two workers, pass (78 tests).
- Not checked here: an agent actually calling a tool. That needs #843
(agent invocation) and #844/#854 (`patchy dev agent`, the door).

## Release impact

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

Today the build ignores `agent/`. Now it builds it, and only tier 2
repos that have the folder change. A repo with a `server/agent.ts` is
refused; only the unmerged prototype (#727) used that file.

- **What does a revert leave behind?** Versions whose stored descriptors
mark `agent.*` handlers `agentTool: true`.
- **Does the release before it still work with that?** Yes, from #837
on, which reads the mark and refuses page calls to marked tools. #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
## What changed

This PR adds release 17's What's new entry, written from `5dd94f3`. It
covers everything merged since release 16's `through` (`dd3f41f`), and
it sets the `patchy` release to `0.17.0` in
`packages/patchy/package.json` and `CURRENT_RELEASE`. With this release,
people's agents can use their company's patches through Patchy MCP
(#833).

| Change | PRs |
| --- | --- |
| New: Your AI agent can use your company's tools | #873, #878, #880,
#881, #882, #883, #884, #886, #887 |
| New: Admins choose whether agents can use the company's tools | #871 |
| Improved: Your machines shows your agents too (Revoke all machines is
now Disconnect everything) | #885, #879 |
| New: See what agents can do with a tool | #876 |
| New: The log says when an agent made a change | #888 |
| New: Your agent can make a tool ready for agents | #869, #870, #872,
#875, #896 |
| Behind the scenes: agents' calls have their own limits, and a server
only an agent uses rests a minute after its last call | #889, #892 |
| Behind the scenes: New and Improved changes are public, for
patchyhq.com | #893 |
| Behind the scenes: library updates | #899 |

Five merged PRs get no line:
- #874 is release 16's own entry.
- #894 is dev tooling: worker agent launchers and scenario data. Its one
CLI fix lets a `patchy` installed outside a tier 2 repo publish it. The
skills have agents use the repo's pinned `pnpm patchy` instead, so that
path is off the documented one.
- #900 is CI.
- #901 rewords an internal skill.

## Look at

- **The entry**, at the top of `releases` in
`packages/core/src/whatsNew.ts`.
- It names only Claude Code and Codex. Both have connected through real
consent against dev instances. Hosted clients (Claude.ai, ChatGPT) are
checked in production only (`docs/product.md` › Patchy MCP ›
Acceptance).
- Its labels are the pages' own: Agent access on Company, Your machines,
What agents can do, Disconnect everything, and "Jordan Lee via Claude".
- **Rollback safety, from the live commit `e4243ff` to `5dd94f3`.**
- No PR in the range is labelled `one-way`, and every PR answers both
Release impact questions with "Yes".
  - Migrations 0020–0025 are all additive:
    - three defaulted or nullable columns on `companies`;
- `agent_name` on the runtime log, with a widened `credential_kind`
check;
    - the agent connection tables, `agent_consents` and `change_keys`;
    - two columns on execution bindings.

The new tables reference `users` without a cascade, but no release
deletes users or companies. Release 16 reads the runtime log only for
credential kinds it knows, so rows from agents can't break it.
- `rollback-rehearsal` on #892 rehearsed the whole stack, since #892
adds the last migration and the rest of the stack sits below it:
`Exercised rollback paths passed: e4243ff → c8bede4 → e4243ff → c8bede4,
in 238s.` #896's run skipped, because it changes no migration or handler
descriptor.
- #883 turns on the load balancer's host header preservation, which the
Deploy workflow's app stack deploy applies. A rollback leaves it on.
That's harmless, because release 16's server never reads `Host`.
- A rollback takes `/mcp` and `/whats-new.json` away. Connected agents
get a 404 until this release returns, and then their connections work
again, unless one ended in between. Agent tools published in between
stay refused to pages, because #837 already shipped in release 16.

## How it was verified

- `pnpm check` on `2d528b1`: format, lint, typecheck and synth passed.
In the test step, 2,300 of 2,301 tests passed. The one failure was
`packages/sdk/src/install.test.ts` › "says how to reach patchy when the
prefix's bin is not on PATH", which timed out at 180 s while the shared
machine was loaded. Rerun alone, that file passes all 7 tests in 62 s.
The release's own tests pass too: `whatsNew.test.ts`, `schemas.test.ts`
and `WhatsNewPages.test.ts`.
- The live commit was pinned from `/healthz/deep`: `e4243ff`, release
16. The Deploy run updated last succeeded, and none is unfinished.
- Each PR in the range was read with `gh pr view`, including its Release
impact answers.

## Release impact

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

This PR changes only the changelog text and the `patchy` version. As
with every release, a CLI installed before this deploy is told to
upgrade.

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

If this release misbehaves, roll back to
`e4243ff54d2acbbc88b60eeb0cf9b82a26dc9d5d` (release 16).

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

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:cli Touches the cli area area:docs Touches the docs area 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.

Builders describe handlers and declare read-only actions

1 participant