Repository navigation
Description
Part of #730.
Question
How does a person connect a worker agent, and how do they, their admin or Patchy take it away again: the authorization server, consent, token lifetimes and refresh, and every reverse state?
Context
Fixed at charting: build and work token purposes, neither opening the other's door; one token per device or client; agent access off until an admin turns it on; a connection is one grant as the person. The prototype (#727) built Patchy's own OAuth 2.1 authorization server: protected resource and server metadata, dynamic client registration, PKCE, a consent page on the browser session, one use machine token per client, and reconnecting replaces the old token. Clerk is the identity provider today; ADR-0008 covers machine tokens. The authorization research supplies the facts.
To decide
- Whose authorization server: Patchy's own or Clerk's.
- Registration: Client ID Metadata Documents, dynamic registration or both; what Patchy keeps about a client, how long unused registrations live, how its name is shown, and the limits on fetching a client's metadata document (Patchy fetching a URL a stranger names).
- What a connection is. The prototype replaces a person's earlier token for the same OAuth client when they reconnect. With metadata documents every install of a client shares one client id, so connecting a second laptop would disconnect the first, against the fixed one-token-per-device decision. Decide what tells two connections apart and which one a reconnect replaces.
- Lifetimes and refresh: access token lifetime, refresh tokens and rotation, what an expiry looks like to a person mid-task, and how this sits with machine tokens' existing expiry.
- Consent: what the page tells the person (which company, that the agent acts as them, what it can reach); being signed in as someone else; denying.
- Reverse states, each with how it's seen and what the agent is told (in the MCP surface ticket's refusal shape): disconnecting on Your machines; deactivation and reactivation; agent access turned off and on again; an admin removing someone's connection; someone leaving the company; revoke-all after a lost device. Each covers the whole grant, not only live tokens: pending authorization codes (the prototype leaves them redeemable after a reactivation), refresh token families, and calls already admitted. ADR-0008's rule that reactivation needs fresh authorization holds.
- ADR-0008: the amendment for a second token purpose.
- Dev instances: keep the loopback token endpoint found in testing, or a cleaner equivalent.
Resolves when
Connecting and disconnecting are written as decisions ready for the spec, with the auth glossary's terms updated (agent connection, the work purpose).
Activity
allisonmahmood commentedon Oct 17, 2026
Handed over from The MCP surface on the latest revision:
isError: true, text saying what happened and then what to do, andstructuredContent: { error: { code, from, message, details?, retryAfterSeconds? } }. Never a 403.Access-Control-Allow-Origin: *without credentials. The consent page stays outside CORS.GET /dev/sign-in?as=<email>(packages/auth/src/DevPersonas.ts) switches the dev persona on a plain GET, so any page the developer visits can change who they are signed in as locally. The proposed fix is to make persona switching a protected POST and to requireSec-Fetch-Site: same-originon the dev instance's browser routes, consent included.allisonmahmood commentedon Oct 21, 2026
Resolution
Decided with Allison on 2026-10-21 over two rounds. GPT 6.1 Sol checked the recommendations before she answered, and four changed as a result: the refresh grace, the idle clock, cancelling consents when agent access goes off, and device logins awaiting their poll. Sol then checked this resolution, and its eight precision fixes are folded in. The facts come from the authorization research and the MCP surface. Everything below is written to go straight into the spec.
Patchy is its own authorization server. Clerk only signs the person in on the consent page. MCP clients speak OAuth's authorization code flow with PKCE, not device login. Consent still keeps device login's rules:
Clerk was ruled out because it can't list or end one person's grant, its refresh tokens never expire, it has no hook for agent access, and its OAuth price is unpublished.
Clients name themselves only through metadata documents. Patchy advertises Client ID Metadata Documents with the
noneauth method and offers no dynamic registration./callback. A custom callback URL, or--oauth-client-registration dcr, can't connect.none. ChatGPT's single field saysprivate_key_jwtwhile its list includesnone; Claude's documents have only the single field.client_idis exactly the https URL fetched and its required fields are valid. The requested redirect must be one the document lists. Grant types Patchy doesn't offer are ignored (Claude's document lists a JWT bearer grant).An agent connection is one consent.
Lifetimes.
invalid_grantanswer./mcp; refreshing alone doesn't count. It has no absolute lifetime, which no MCP or OAuth MUST requires, so consent lasts until something ends it./mcp). Not every client offers one; an unverified report says ChatGPT desktop doesn't. Acceptance checks each client's recovery, and the docs say how to reconnect by hand.The consent page must say these things; the mocks ticket draws it.
[email protected], with Use another account. An answer from a page left open across an account switch is refused and asked again.access_deniedto the client and records nothing.Reverse states. An ended connection answers HTTP 401
invalid_token, so the client runs its own reconnect, and the consent page explains anything that still blocks it. A live connection refused by policy gets the surface's refusal shape over HTTP 200. Neither case is ever a 403.agent_access_offfrompatchy: "Agent access is off at Acme. Ask an admin to turn it on: Priya Shah, Sam Ortiz." Initialize, the tool list and refresh keep working, and refused calls count as useAdmins have two levers and nothing aimed at one person's agent: the agent access switch and deactivation. There is no admin view of connections, and the switch shows no count. Machine tokens and agent connections both stay the person's alone. Allison: "admin can switch. they dont oversee connections of individuals. they deactivate the users account."
Dev instances.
127.0.0.1, because Claude Code sends credentials over plain http only tolocalhostor127.0.0.1.pnpm dev mcp-tokenmints agent connections straight into the dev database for launchers that take a pasted token, with a long-lived access token. Only the dev runner can mint one; no route exists for it.GET /dev/sign-in?as=) is refused when the browser says the request came from another site (Sec-Fetch-Site: cross-siteorsame-site), so a page you visit can't change who you're signed in as. This replaces the same-origin POST agreed in round one, which would have broken every dev tool that switches persona with that GET (pnpm dev open,shot,film,compare, the rollback rehearsal and the documented curl recipe). Those tools sendnoneor no header and keep working unchanged.ADR-0008, amended in place and retitled Every bearer is somebody: machine tokens and agent connections. Its opening and its control paragraph become:
The device login, browser sign-out, dead-row and human-owner paragraphs stay as they are.
Vocabulary for the glossaries, written in with the spec. "Connection" and "disconnect" already belong to Integrations (a company's Postgres or PostHog source), so this one is always an agent connection.
buildis a machine token's and opens the CLI's API;workis an agent connection's and opens only Patchy MCP. A credential used at the wrong door is refused as unknown. Avoid: scope (OAuth's word), token type.buildcredential).For the tickets
/mcpand metadata document fetches.pnpm dev mcp-tokenskips consent and the document fetch;localhostincluded.resourceis bound through the code exchange and refresh.scope="patches", and the 401 addserror="invalid_token"when a token was sent.isson every redirect, andHEAD /mcpanswered likeGET.invalid_grant.redirect_uriis optional at the token endpoint, and checked when sent.