Skip to content

prototype: people's own agents use patches through Patchy's MCP - #727

Closed
allisonmahmood wants to merge 8 commits into
mainfrom
prototype/agent-mcp
Closed

allisonmahmood wants to merge 8 commits into
mainfrom
prototype/agent-mcp

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Oct 16, 2026 •

Copy link
Copy Markdown
Owner

Prototype, not for merge. It's up so we can try the agent side of patches and react. Related: the tier 3 map (#623) reserved "Patchy MCP" as a seam; this is that seam, built as a throwaway.

Patches are nice to look at, but today a person has to type everything into them. People want their own agents (Claude Code, Codex, ChatGPT, whatever speaks MCP) to do that work for them, without every field becoming editable by an agent.

This prototype has three parts:

  • The builder decides what agents may do. In a tier 2 patch, the exports of server/agent.ts (the agent area) are the only things an agent can call. Each export needs a description, and its fields take .describe(…). Handlers see ctx.agent (the client's name), so a patch can hold agents to stricter rules (Brightline's addLeads makes agents fill every field) or tag what they did. Publish refuses undescribed tools and uploads or file handles in them. The patchy-server skill teaches all of this to the builder agent.
  • Each person connects their agent once. <instance>/mcp offers four fixed tools: find_patches, open_patch, read_patch and change_patch. The agent explores from there, so a new patch needs no new connection and the agent's context stays small. The door is stateless JSON-RPC, so any replica answers.
  • Agents act as the person, within what the company allows.
    • Patchy is the OAuth server MCP clients expect: discovery, dynamic client registration, PKCE, and a consent page on the normal browser session.
    • Each connection is the person's own machine token with purpose use. CLI tokens are build, and neither works on the other door. Connections are listed and disconnected on Your machines.
    • Agent access on /company is off until an admin turns it on.
    • Calls run on the served version through the same invocation pages use: same limits, same log, live updates for anyone with the patch open. The log reads "Jordan Lee via Codex".

Try it

pnpm dev up brightline
pnpm dev open allison                     # Company → Agent access → Turn on

The card printed by up lists the launchers:

  • <env>/worker starts Claude Code connected only to Patchy's MCP. On first use it opens the consent page, where you sign in as anyone.
  • <env>/worker-codex jordan and <env>/worker-grok priya start Codex or Grok as that person, with a minted token.
  • For any other client, run pnpm dev mcp-token <person> --client <name> and give it the MCP URL from the card.

Things to ask:

  • "What's in our pipeline in proposal?"
  • "Add a lead for Northwind Tea…". Agents must give every field, and the refusal says which ones are missing.
  • "Move Northline Bikes on". The board's stage rules apply to agents too.
  • "Draft a $400 spend request for fonts". It shows up on the person's Spend page to finish and submit.
  • "Approve Priya's hotel". It can't: approvals stay human-only.

Keep New Business open as someone else and watch rows arrive live. The card's Log says who did what, via which agent.

To build your own patch, use <env>/agent, the builder. Ask it for a patch "where agents can …" with whatever constraints you like, then use it from a worker.

What happened when I tried it

  • Codex as Jordan used only the MCP tools. It found the proposal-stage deals and refused to add a lead with an unknown service, asking which one was meant. It explained that spend approval happens on the Spend page. Asked again with the right details, it added the lead and a note, moved Northline Bikes (the rules allowed it) and drafted the spend request.
  • Claude Code as Priya summarised her deals by stage and added a note.
  • Codex's real OAuth login (codex mcp login) went end to end against the instance: it discovered the server, registered itself, got consent as Sofia and exchanged the code.
  • Claude Code's own OAuth login (the worker launcher) works too. Claude Code sends credentials over plain http only to localhost or 127.0.0.1, so a dev instance advertises its token endpoint on 127.0.0.1; production is https.
  • The builder agent, told only "agents can post my standup but must fill all three fields, posts must say an agent wrote them, only people resolve blockers", built and published a standup patch from the skills alone. A Claude Code worker then posted through it.
    • It found a real edge: an agent writes "None" for blockers because the field is required, and the page shows that as an open blocker. This is the kind of thing worth poking at.
  • pnpm check passes: 186 test files, 1,847 tests. GPT 6.1 Sol reviewed the build. It found no high-severity issues and three medium ones, all fixed:
    • read_patch racing a publish into a write
    • a foreign address resolving to a local namesake
    • advertising the 2026-07-28 MCP revision without its shapes

What Allison's testing showed (2026-10-17)

She ran Claude Code, Codex and other agents against the brightline environment, had the builder make an agent comms board from one sentence, then had several people's agents use it to coordinate for the team. LGTM as a prototype; next is the map.

  • Permissions come in three layers.

    • Patchy: agent access is on, and the agent acts as the person.
    • The patch: only the agent area's tools, under the same rules as the page.
    • The client: confirmation prompts, auto-mode checks and the model's own judgement.

    In testing, Patchy would have allowed "mark Northline Won" for an admin, but Claude Code's auto mode held it back without an explicit confirmation. Claude also skipped a lead it judged a duplicate, though the patch has no duplicate rule.

  • Agents say who they act for. Signed in as Jordan from Allison's Claude account, the agent pointed out the mismatch before writing.

  • Agents confirm before writes. Clients ask before writes unless the person pre-approves. Open for the map: should a patch be able to mark a tool safe to run without asking?

  • Drafts for money and approvals. Spend's "agents draft, people submit" read well. Open for the map: should the builder skill steer that way by default?

  • Agents poll for now. They can loop and poll on tier 2. Pushing changes to agents waits for tier 3.

  • The builder needs no help. It moved itself from tier 1 to tier 2 once it found agent tools, and wrote about a dozen described tools with claims, hand-offs and dependencies.

  • Dev environment fixes:

    • Claude Code sends credentials over plain http only to localhost/127.0.0.1, so dev instances advertise their token endpoint on 127.0.0.1.
    • The builder put its patch in ~/Patchy (the global skill's default) instead of the workspace. The workspace should say where to build.

What this leaves out

  • Uploads and file handles across MCP.
  • Refresh tokens.
  • An agent's retry after a timeout makes a second write.
  • The stateless 2026-07-28 MCP revision.
  • A local MCP inside patchy dev: publish to try a tool.
  • Rate limits: agents get their own bucket beside the person's pages, but nothing is tuned for agents.
  • Docs: docs/product.md, an amendment to ADR-0008 (a second token purpose) and the glossaries beyond auth.
  • The UI is scaffolding built from existing components, not a design: the consent page, Agent access, Connect an agent, "What agents can do" on the card, and Spend's drafts strip.

Screenshots

The consent page an MCP client opens:

Consent page

Your machines: connect an agent, and the connection it made:

Your machines

The card shows what agents can do, and its recent activity names the agent:

Patch card

Agent access on the Company page:

Company

Spend, after Codex drafted a request for Jordan:

Spend draft

The patch's log

Log

Made by Claude Opus 5.5 via Claude Code (Opus 5.5 subagents built the lanes; GPT 6.1 Sol reviewed through Codex).

allisonmahmood and others added 7 commits October 16, 2026 17:21
The SDK's agent area (server/agent.ts, descriptions, ctx.agent), OAuth for MCP
clients with use-purpose machine tokens and the company's agent access switch,
agent calls on the served version with "via" attribution, and the /mcp door.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… no 2026-07-28 claim

From the Sol review: the read/change kind is checked against the version actually
invoked, another instance's address resolves to nothing, and the stateless revision
isn't advertised until its envelopes exist.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added area:server Touches the server area area:ci CI, shared testing infrastructure, development scripts and tooling area:cli Touches the cli area area:docs Touches the docs area area:integrations Company connections and integration implementations area:ui Portal and first-party browser pages, shared rendering and styles size:xl Over 1,000 changed lines; review in multiple passes labels Oct 16, 2026
…Claude Code accepts over http

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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).
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:cli Touches the cli area area:docs Touches the docs area area:integrations Company connections and integration implementations area:server Touches the server area area:ui Portal and first-party browser pages, shared rendering and styles size:xl Over 1,000 changed lines; review in multiple passes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant