Skip to content

feat(mcp): the door at /mcp: revisions, request trust, the bearer and its limits - #883

Merged
allisonmahmood merged 4 commits into
mainfrom
mcp/851-door
Oct 23, 2026
Merged

allisonmahmood merged 4 commits into
mainfrom
mcp/851-door

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

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

What changed

People's agents get one MCP door at <instance>/mcp. This PR builds the door itself: it serves MCP 2026-07-28, 2025-11-25 and 2025-06-18, refuses requests it shouldn't trust before reading a token, opens only for an agent connection's work token, and holds each person to their requests a minute. It lists the four tools; each answers "not built yet" until #852, #854 and #855 land.

Closes #851

Look at

  1. Request trust, in this order: the host a request was addressed to must be the instance's own, port included (421, no challenge). That is an absolute-form target's authority with its port or its scheme's default, else its one Host field; two Host fields are refused. The door never believes a forwarded host. One infrastructure change, which needs your eyes: by default the ALB drops any port from Host on its 443 listener, so apps/infra now turns on preserveHostHeader, an in-place attribute change that ships with the stack's deploy and stays on after a rollback (see Release impact). Nothing else on the server reads Host (Clerk's session check sets its own), and the duplicates preservation lets through are refused by the door. Next, a malformed or duplicated Origin gets 403 (a dev instance also refuses anyone else's), then GET/HEAD/DELETE get 405, then the bearer. The door never reads cookies; apps/server/src/McpDoor.test.ts signs a persona in and shows the cookie opens /machines but gets 401 at /mcp.
  2. Revisions follow the official SDK's dual-era rules, body first (packages/mcp/src/Revisions.ts). One choice the spec doesn't spell out: a per-request _meta naming a legacy version gets -32022, because legacy versions are served only through initialize. A legacy client hears an unknown method over HTTP 200 (-32601), since a 404 means "session ended" to it; modern gets 404.
  3. Limits. Failed checks spend mcp.bearer.failures.perMinute (60 per address) only after they fail. A working token is never refused, even after its address is limited. mcp.requests.perMinute (600, burst 600, per person, company override) is a token bucket: on tools/call it is the tool's rate_limited refusal over 200, otherwise 429 with Retry-After. mcp.body.bytes answers 413 before parsing, with Connection: close, and an oversized request still spends the person's minute. A declared length over the cap is refused unread. A chunked body is read to its end, keeping only the cap, so its 413 arrives however long the body runs (Node's 5-minute request timeout bounds it); the socket test sends 6 MiB chunked and 2 MB declared and gets each 413.
  4. Real clients against a dev instance (details below): Codex lists the four tools on both revisions it speaks, and Claude Code goes from the 401 to the protected resource metadata and the authorization server metadata.
Real clients and the Done-means refusals, transcripts

Codex 0.163.0 at its default revision (2025-06-18)

A throwaway CODEX_HOME holding only [mcp_servers.patchy] (url and bearer_token_env_var), a token from pnpm dev mcp-token [email protected] --client Codex, run from a temp dir outside $HOME: codex exec --skip-git-repo-check --json "<prompt>".

agent: I’ll find Patchy’s tools, then call `find_patches` with no arguments.
mcp_tool_call patchy.find_patches({}) -> failed: find_patches isn't built on this instance yet, so nothing was read or changed. Tell the person Patchy's MCP isn't ready here.
agent: mcp__patchy__change_patch
mcp__patchy__find_patches
mcp__patchy__open_patch
mcp__patchy__read_patch

> find_patches isn't built on this instance yet, so nothing was read or changed. Tell the person Patchy's MCP isn't ready here.

The door's request events for that run:

Request Status Era / version Method Client Tool Code
POST /mcp 200 legacy 2025-06-18 initialize codex-mcp-client — —
POST /mcp 202 legacy 2025-06-18 notifications/initialized — — —
POST /mcp 200 legacy 2025-06-18 tools/list — — —
POST /mcp 200 legacy 2025-06-18 tools/call — find_patches not_built

Codex 0.163.0 with --enable mcp_2026_07_28

agent: I’ll find the Patchy tools, list their exact names, then call `find_patches` with no arguments.
mcp_tool_call patchy.find_patches({}) -> failed: find_patches isn't built on this instance yet, so nothing was read or changed. Tell the person Patchy's MCP isn't ready here.
agent: ```text
mcp__patchy__change_patch
mcp__patchy__find_patches
mcp__patchy__open_patch
mcp__patchy__read_patch
```

`find_patches({})` returned:

> find_patches isn't built on this instance yet, so nothing was read or changed. Tell the person Patchy's MCP isn't ready here.
Request Status Era / version Method Client Tool Code
POST /mcp 200 modern 2026-07-28 server/discover codex-mcp-client — —
POST /mcp 200 modern 2026-07-28 tools/list codex-mcp-client — —
POST /mcp 200 modern 2026-07-28 tools/call codex-mcp-client find_patches not_built

Claude Code 2.1.308 finds the protected resource metadata from the 401

No token: claude --setting-sources project --strict-mcp-config --mcp-config ./mcp.json --debug-file … -p "…" from a temp dir, with the server at http://127.0.0.1:<port>/mcp. This run was against 60bf7d6. It isn't repeated on the head, because each run leaves discovery state in the user's Claude Code store. The 401 it reads is unchanged since:

HTTP/1.1 401 Unauthorized
www-authenticate: Bearer resource_metadata="http://127.0.0.1:<port>/.well-known/oauth-protected-resource/mcp", scope="patches"
Request Status Era / version Method Client Tool Code
POST /mcp 401 — — — — missing_token
GET /.well-known/oauth-protected-resource/mcp 200 — — — — —
GET /.well-known/oauth-authorization-server 200 — — — — —
[DEBUG] MCP server "patchy": Initializing HTTP transport to http://127.0.0.1:<port>/mcp
[DEBUG] MCP server "patchy": No token data found
[DEBUG] MCP server "patchy": Saving discovery state (authServer: http://127.0.0.1:<port>/)
[DEBUG] MCP server "patchy": No client info found; deferring client registration to authentication time
[DEBUG] MCP server "patchy": Authentication required for HTTP server

With a minted token in headers, on the head, Claude Code speaks 2026-07-28 and lists the four tools:

The patchy-door-851 MCP server gives me these tools:

```
mcp__patchy-door-851__change_patch
mcp__patchy-door-851__find_patches
mcp__patchy-door-851__open_patch
mcp__patchy-door-851__read_patch
```

I called `find_patches` with no arguments. It returned an error instead of a list of patches. Its exact answer:

> find_patches isn't built on this instance yet, so nothing was read or changed. Tell the person Patchy's MCP isn't ready here.

So Patchy's MCP isn't ready on this instance yet. Nothing was read or changed.
Request Status Era / version Method Client Tool Code
POST /mcp 200 modern 2026-07-28 server/discover claude-code — —
POST /mcp 200 modern 2026-07-28 tools/list claude-code — —
POST /mcp 200 modern 2026-07-28 tools/call claude-code find_patches not_built

The refusals Done means names, against the same dev instance

$ POST /mcp  Host: evil.example:<port>  (a rebinding page's name for this address)
HTTP/1.1 421 Misdirected Request
{"error":"invalid_host","error_description":"Patchy's MCP answers only at http://127.0.0.1:<port>/mcp."}

$ POST /mcp  Origin: https://evil.example  (a dev instance takes only its own)
HTTP/1.1 403 Forbidden
{"error":"invalid_origin","error_description":"A dev instance's MCP answers only its own origin, http://127.0.0.1:<port>, or none."}

$ POST /mcp  Origin: evil  (malformed)
HTTP/1.1 403 Forbidden
{"error":"invalid_origin","error_description":"A dev instance's MCP answers only its own origin, http://127.0.0.1:<port>, or none."}

$ POST /mcp  Origin: http://127.0.0.1:<port>  (its own)
HTTP/1.1 200 OK
{"jsonrpc":"2.0","id":0,"result":{"protocolVersion":"2025-06-18","capabilities":{"tools":{"listChanged":false}},"serverInfo":{"name":"patchy","title":"Patchy","version":"0.15.0"},"instructions":"You act for Patchy Dev at Patchy Dev through Patchy, where the company's internal tools are patches. find

$ GET /api/patches  Bearer <build token>  (the CLI's machine token is live)
HTTP 200

$ POST /mcp  Bearer <build token>
HTTP/1.1 401 Unauthorized
www-authenticate: Bearer resource_metadata="http://127.0.0.1:<port>/.well-known/oauth-protected-resource/mcp", scope="patches", error="invalid_token"
{"error":"invalid_token","error_description":"This token is unknown or its agent connection has ended. Connect the agent to Patchy again."}

$ Revoke all machines on Your machines, signed in as [email protected]
HTTP 303

$ POST /mcp  Bearer <work token>  (its connection has ended)
HTTP/1.1 401 Unauthorized
www-authenticate: Bearer resource_metadata="http://127.0.0.1:<port>/.well-known/oauth-protected-resource/mcp", scope="patches", error="invalid_token"
{"error":"invalid_token","error_description":"This token is unknown or its agent connection has ended. Connect the agent to Patchy again."}

How it was verified

  • packages/mcp: request trust (Host case, trailing dot, default port, DNS-rebinding hosts; Origin shapes, duplicates, dev), the revision classifier against the status table, and the door over a migrated database: 401s and the challenge, build vs work, an ended connection, the failed-check limit counted after failure, the 413 boundary at exactly 1,114,112 bytes, initialize negotiation, discover and tools/list cache hints, the four tools' annotations, the per-person bucket shared across a person's clients, and one wide event per request that never holds the token, arguments, change key or instructions.
  • apps/server/src/McpDoor.test.ts, the whole server over a raw socket: the request event under /mcp, rebinding hosts, an absolute-form target, two Host fields, duplicated Origin, a real session cookie, HEAD, and the 413 on the wire for chunked and declared bodies over the cap.
  • Codex 0.163.0 (both revisions) and Claude Code 2.1.308 against pnpm dev, with per-invocation config only: a throwaway CODEX_HOME, --mcp-config from a temp dir outside $HOME.
  • Rollback rehearsal, pnpm test:rollback-rehearsal --live e4243ff (main, which has Tier 2 readers accept handler descriptions, read-only actions and agent tools, and enforce them #837 and Deactivation and Disconnect everything end pending device logins and record when a person's credentials ended #838): "Exercised rollback paths passed: e4243ff → 60bf7d6 → e4243ff → 60bf7d6". The CI check runs against production's commit and passes here only because this PR adds no migration.
  • pnpm verify runs on the final head before READY.

Release impact

  • Breaking — requires action from anyone already running this

  • Not breaking — a new route, new registry rows, new wide event fields and one ALB attribute that only the door reads; no migration, and nothing existing changes shape

  • What does a revert leave behind? No stored data: the door keeps its buckets in memory and writes no rows. The ALB keeps host header preservation on: CloudFormation leaves a load balancer attribute alone when a template stops listing it, so redeploying the template from before this PR doesn't turn it off. Turning it off takes an explicit loadBalancer.setAttribute("routing.http.preserve_host_header.enabled", "false") in apps/infra/src/AppStack.ts and a deploy; preserveHostHeader: false writes nothing, so it wouldn't. Agents connected to /mcp would get the page fallback's 404 until the door returns.

  • Does the release before it still work with that? Yes. Nothing in it reads Host: Clerk's session check sets its own, and pages use the configured public origin. A preserved Host, with its port or a second Host field, changes nothing for it. The stack ships as one release, and nothing below it reads anything this PR writes, so it isn't one-way.

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:docs Touches the docs area size:xl Over 1,000 changed lines; review in multiple passes area:ui Portal and first-party browser pages, shared rendering and styles labels Oct 22, 2026
@allisonmahmood
allisonmahmood force-pushed the mcp/851-door branch 2 times, most recently from 3472a33 to 413b5bc Compare October 22, 2026 17:23
@allisonmahmood

Copy link
Copy Markdown
Owner Author

GPT-6.1-Sol review (xhigh), rounds and outcomes

Round 1, on 60bf7d6: 1 blocking, 7 should-fix

  1. (blocking) The ALB doesn't preserve Host: absolute-form targets and explicit ports are rewritten. Dismissed at first: an absolute-form target's authority is RFC 9112's authority. Revisited in round 2 (item 2 there).
  2. Two Host fields were accepted, because Node keeps the first. Fixed: the door counts Host in the raw fields and answers 421 to two.
  3. The trailing dot was stripped on one side only. Fixed: both sides are normalized.
  4. The Origin regex accepted https://[:::], https://[1] and https://%. Fixed: the host must be a reg-name with valid %XX escapes, a WHATWG-valid IPv6 literal or an IPvFuture literal; null must match exactly.
  5. A chunked body over the cap rarely got its 413. Fixed in round 2.
  6. An oversized request didn't spend the person's minute. Fixed: the door spends it right after the bearer, before reading the body.
  7. Mcp-Name wasn't checked for prompts/get and resources/read. Fixed with one table of mirrored fields.
  8. Notification events had no metadata. Fixed: their era, version, method and client are recorded.

Round 2, on 3472a33: 1 blocking, 2 should-fix

  1. (blocking) A chunked body above four caps got no response. Fixed: a chunked body is read to its end, keeping only the cap, so its 413 always arrives. Node's 5-minute request timeout bounds the read. The socket test sends a 6 MiB chunked body and a 2 MB declared body sent whole, and gets a 413 on the wire for each.
  2. The ALB drops the port a client sent. Fixed: preserveHostHeader: true in apps/infra, so duplicates now reach the door, which refuses them. An absolute-form target keeps its own port, or its scheme's default.
  3. Refused requests lost their method, version and client on the event. Fixed.

Round 3, on 413b5bc: nothing blocking, 2 should-fix. Sol judged reading a chunked body to its end acceptable.

  1. A request refused for its id lost its era, and an initialize its offered version and client. Fixed in 26e2aef.
  2. A rate-limited tool call didn't name its tool. Fixed in 26e2aef.

Things every round found fine:

  • no cookie authority;
  • build/work separation, with ended connections answered 401;
  • the failed-check limit, counted only after a check fails;
  • no arguments, results, tokens, change keys or instructions on events;
  • revision negotiation;
  • no Effect service findings.

@github-actions github-actions Bot removed the area:ui Portal and first-party browser pages, shared rendering and styles label Oct 22, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Acceptance: PASS with notes

Checked 26e2aef4ac988190eeabfacf23f7aa832cf276a6 (base 2e101dcd709cd023ed9d94c8d948f271d6900a78, mcp/850-consent-page) on the prior run's team scenario, with a new detached checkout for this reassessment, by GPT-6.1-Sol (xhigh) in the Codex harness on T3 Code.

The corrected Release impact clears the sole failure from the previous two acceptance runs. It now correctly explains both retention after rollback and the explicit reset: loadBalancer.setAttribute("routing.http.preserve_host_header.enabled", "false"). The code/head and base are identical to the previous verdict.

This is a reassessment of that correction, not a new interactive acceptance run. I independently synthesized the actual base/head AppStack sources and both reset variants, reran the infrastructure suite, and rechecked head CI. The behavioral evidence below is carried forward from the preceding acceptance at this identical head, whose latest comment was 6348809109; it was not repeated here. It is preserved inline because this comment replaces that verdict.

Done means

  • Codex connects and lists the four tools on each revision it speaks: passed. Codex 0.163.0, with a minted work token and separate throwaway CODEX_HOMEs, completed these actual transport requests:

    default:                 initialize                200  legacy 2025-06-18
                             notifications/initialized 202  legacy 2025-06-18
                             tools/list                200  legacy 2025-06-18
    --enable mcp_2026_07_28:  server/discover           200  modern 2026-07-28
                             tools/list                200  modern 2026-07-28
    

    The list contains find_patches, open_patch, read_patch, change_patch. A subsequent model turn was unavailable without an OpenAI login in the isolated configuration; the required MCP connection and listing completed before that failure.

  • Claude Code finds protected resource metadata from the 401: passed. Claude Code 2.1.308 used an isolated configuration directory, received /mcp's 401, fetched /.well-known/oauth-protected-resource/mcp and /.well-known/oauth-authorization-server (both 200), and reported authentication required. No discovery state was written to the user's normal Claude configuration.

  • Specified refusals: passed on the real instance. Wrong Host: 421 invalid_host, no challenge, even with a correct forwarded host. Foreign, malformed and duplicated Origin: 403 invalid_origin. A valid build token: CLI API 200, MCP 401 invalid_token. After Ada revoked all machines, her work token: 401 invalid_token, with metadata, scope="patches" and error="invalid_token" in the challenge. A browser cookie opened /machines but got 401 at /mcp; a work token got 401 at the CLI API.

Golden journeys

  • Sign in / back: passed, Ben on team: company page 401 signed out, 200 signed in; sign-out cleared the browser cookies and restored the 401 door. Browser sign-out left an agent connection usable.
  • Log a machine in / back: passed, Ada: packaged CLI login, browser code confirmation, completion, whoami naming the new machine, then logout clearing its stored credential. Revoking all machines also ended the work connection as above.
  • Publish a page / back: passed, Ada and Ben: publish, Ben opens it at its address and finds it on Home; retire shows its retirement notice; restore returns the page at the same address; delete shows its deletion notice and restore by patch id returns it again.
  • Share / unshare: passed on fresh team data: public admitted a signed-out reader with 200; company sharing restored 401.
  • Find/open a tool, tier 1 live sync, tier 2 tools, invite/join: not run interactively on their prescribed scenarios. I used the green head CI's browser, tier2-smoke, cli-smoke and clerk-live suites for broader server/auth regression coverage; this is not a claim to have repeated those exact scenario journeys locally. Head CI.

Additional same-head evidence retained

  • Direct HTTP checks passed for both legacy versions, unknown initialize negotiation, modern discovery/list cache scopes and annotations, all four not_built refusals, the modern error/status table, no batching, ignored session id, and GET/HEAD/DELETE refusals.
  • Exactly 1,114,112 bytes was accepted; a declared body one byte larger and a 6 MiB chunked body each returned 413 with Connection: close.
  • The default person bucket reached 429; a second connection of that person shared it, tools/call returned a 200 rate_limited refusal with retry timing, and a colleague still succeeded. Failed bearer checks reached 429 while a valid bearer still succeeded.
  • Six observed request cases each emitted exactly one event with sampleProbability: 1, including errors and notifications. Invalid-id initialize retained its legacy version and client. Origin was clipped to 256 characters. Sent argument/change-key sentinels and the minted work token were absent from logs; MCP events had no argument, result, token or instruction fields.

Revalidation this run

  • New detached checkout at the exact head, frozen-lockfile installation, and clean git status --short before and after checks.

  • pnpm exec vitest run apps/infra/src/stacks.test.ts:

    Test Files  1 passed (1)
         Tests  6 passed (6)
    
  • Offline synthesis with the actual AppStack sources and pinned [email protected]:

    base template:                         preserve_host_header attribute absent
    head template:                         preserve_host_header attribute true
    head with preserveHostHeader: false:   preserve_host_header attribute absent
    head with explicit setAttribute false: preserve_host_header attribute false
    All four assertions passed; no other template changes.
    

    The variants were copies outside the checkout. I also compared their complete templates after removing this one attribute: all matched the base. No AWS resources were contacted or changed.

  • All 14 head checks pass. The CI run names this exact head. Its rollback job says: “No migration or handler descriptor changed, so there is no rollback to rehearse.” It does not validate the ALB rollback.

  • The preceding same-head reassessment independently passed all 57 tests across MCP, the server socket boundary, agent connections and infrastructure; that result is retained evidence, not a claim that all 57 were rerun here.

Rollback answers: passed.

The PR now says that a revert leaves host header preservation enabled, because removing the attribute from a template does not reset it. That matches CloudFormation's documented update semantics.

The reset instruction now uses the explicit setAttribute(..., "false") call, which this run confirmed synthesizes the required false value. Its warning that preserveHostHeader: false writes nothing also matches synthesis and the pinned CDK implementation. Retention behavior is inferred from the synthesized templates and documented update semantics; it was not exercised against AWS.

The previous-release compatibility answer remains supported: the MCP gate is the new incoming Host consumer; Clerk's session boundary replaces the incoming Host with the configured public origin, and serving uses that configured origin. No migration or incompatible stored shape is added. Retaining the attribute therefore does not require one-way. Removing the new door leaves its clients receiving the documented 404.

Not run

  • Live ALB deployment/rollback: this reassessment used offline synthesis only.
  • A fresh dev environment, real clients or interactive golden journeys: reused the prior same-head results preserved above. Find/open, tier 1 live sync, tier 2 tools and invite/join were not interactively exercised on their prescribed scenarios in that run; exact-head CI provides broader coverage.
  • A complete Codex model turn/tool invocation in the prior isolated configuration: no OpenAI login. MCP connection/listing completed; direct requests checked all four tool refusals.
  • Full pnpm verify, live Clerk suites and the broader 57-test focused set locally in this reassessment: relied on green exact-head CI and retained same-head results; the six infrastructure tests were repeated here.

Notes

  • PASS with notes preserves the coverage limits above. The earlier rollback-text failure is resolved, with no new behavioral failure found.
  • Applicable surfaces checked or retained from the same-head acceptance: MCP route/server wiring, work/build authentication and revocation, limits registry/rendered docs, analytics events, infrastructure, glossary/package layout and dev-loop documentation. No generated API contract, CLI command, migration, company-database caller or served-page change was introduced.
  • The author's code, branch, PR body and labels were left unchanged. This verdict concerns the stacked PR against mcp/850-consent-page, not a standalone deployment or merge approval.

Base automatically changed from mcp/850-consent-page to main October 23, 2026 15:00
…arer and holds people to their limits

A new capability package, packages/mcp, answers MCP at /mcp on 2026-07-28
statelessly and on 2025-11-25 and 2025-06-18 through initialize, with the
spec's status table. Host is the gate (421), a malformed or foreign Origin
is 403, only an agent connection's work token opens it (401 naming the
protected resource metadata and scope), failed checks are limited per
address after they fail, a body over 1 MiB and 64 KiB is 413 before
parsing, and each person's requests a minute are a token bucket. The four
tools are listed for everyone and refuse as not built until their tickets
land. Each request's event names the connection, revision, method and
tool, and never what the agent sent. ADR-0014 records one door.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… 413 however a body arrives, and counts every request

Sol round 1. The door takes an absolute-form target's authority and
refuses two Host fields; a trailing dot on either side is the same host;
an Origin's host must be a real reg-name, IPv6 or IPvFuture literal. A
chunked body is read on past the cap and dropped so its 413 arrives, and
an oversized request spends the person's minute. Mcp-Name is checked for
prompts/get and resources/read too, and a notification's event names its
revision, method and client.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rt a client sent, and refusals keep what a request said

Sol round 2. A chunked body is read to its end, keeping only the cap, so
its 413 reaches the client however long it runs. The load balancer now
preserves Host, port and duplicates included, and an absolute-form target
keeps its own port or its scheme's default. A refused request's event
still names its method, version and client.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…a limited tool call names its tool

Sol round 3. A request refused for its id still records its era, and an
initialize its offered version and client; a tool call refused by the
person's minute records which of the door's tools it called.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood merged commit b07f12c into main Oct 23, 2026
14 checks passed
@allisonmahmood
allisonmahmood deleted the mcp/851-door branch October 23, 2026 15:15
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).
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:docs Touches the docs area area:server Touches the server area size:xl Over 1,000 changed lines; review in multiple passes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The door at /mcp: revisions, request trust, the bearer and its limits

1 participant