Appearance
0006. Agent tokens and a person's approval for sensitive tools
Status: accepted. Supersedes the confirm step of ADR 0003. Applies to crates/doors (MCP tokens, the sidecar JWT verifier), crates/api-mcp, the agents module, the inbox's approval.decided contract, and the web app's approval queue. Closes issue #13.
Context
Contract rule 2.10: agents may draft and recommend; approve, reject, payroll locks, pay changes and bulk updates need a person. ADR 0003's confirm step proved only that the caller made a second call. An agent holding a person's token could make that call itself, or skip the step by sending the same token to /graphql or the CLI. So no real sensitive tool (leave.approve, payroll) could be offered over MCP.
Constraints: the sign-in sidecar (services/auth) is not changed here. It issues one kind of token (EdDSA, audience orbit, 15 minutes) for the web app and the CLI.
Decision
1. MCP tokens, issued by Orbit
- A person signed in to the web app calls
POST /mcp/tokenwith their sidecar token and gets an MCP token for their agent: HS256, issuerorbit, audienceorbit-mcp, claimssub(the Orbit actor),tid(the tenant) andagt(a fresh agent id), valid for one hour. - The signing key is
ORBIT_MCP_KEY(at least 32 bytes;deploy/gen-env.shgenerates one) when set. When it is not, it is derived with HKDF fromORBIT_AUDIT_KEYunder the versioned labelorbit-mcp-token-v1(AuditKey::subkey), which HKDF's info separates from every tenant's digest key. Either way it is held outside Postgres. Changing it signs out every agent. - The MCP door accepts MCP tokens only; every other door accepts sidecar tokens only. An MCP token on
/graphqlor the CLI isUNAUTHENTICATED(wrong algorithm and audience), and so is a sidecar token on/mcp./mcp/tokenrefuses an MCP token, so an agent cannot mint itself another. The sidecar's audience may not beorbit-mcp. - The actor stays the person (
Actor::Person) on doormcp: Cedar decides with the person's role, the bus checks their membership on every call (a removed person's token stops working at once), and the base policy forbids every sensitive action on doormcpunless it is confirmed. The token's agent id travels with the principal. - Each issue writes an audit row (
doors.mcp_token.issue, doorweb, the agent id and expiry, never the token) and is capped at 10 per person per hour. - Revocation. A person can revoke every agent token they hold in the tenant (
POST /mcp/token/revokewith their sidecar token; the "Revoke all" button in the web app). It stores a per-personnot_before(doors.mcp_revocations, reached only throughorbit_doorsfunctions) and the MCP door refuses tokens issued at or before it. Audited (doors.mcp_token.revoke) and capped with token issues. Removing the person from the tenant also stops their tokens: the bus refuses every call, andtools/listis empty.
2. Out-of-band approval (agents module)
- Ask. A sensitive tool's first call runs nothing. The MCP door deserialises the input into the handler's type and serialises it again (its canonical form: ids in one spelling), checks that its module is enabled, then dispatches
agents.request.createwith the agent id, the tool and those canonical arguments. The request (pending, 30 minutes) goes to the person through the inbox (agents.approval.requested: the agent asks, the person approves), which notifies them. - Decide. The person opens the request in the web app's approval queue, which shows the tool and its real arguments and, for a leave or attendance decision, the application or request it decides (employee, type, dates, days, status) from the owning module's own query. If that record cannot be shown, Approve is not offered. The person approves or rejects it (
agents.request.approve/.reject). Cedar forbids both on doormcp, on doorcli(and the CLI has no verb for them) and for any principal that is not a person, and the handler finds only the caller's own requests in the caller's tenant (another person, or another tenant, getsNOT_FOUND). A decided or expired request cannot be decided again. - Redeem. The second call, with the same arguments plus
confirm: trueand the request id, dispatchesagents.request.redeem. It succeeds once, only for an approved, unexpired request of the same person, agent token, tool and arguments (compared as JSON, so key order does not matter). Then, and only then, the MCP door runs the tool withDoors::dispatch_confirmed. Refusals areCONFLICTwith a reason (not_approved,rejected,expired,used,mismatch) orNOT_FOUND. If the tool itself then fails (the leave was decided meanwhile), the approval is used up and the result says so (approval: "used"): the agent must ask again and the person approve a new request.
Bounds. A person has at most 20 undecided requests (each keeps an inbox item open); each create first closes the person's expired ones (status expired, inbox item cancelled), under a per-person advisory lock so the cap is exact. One agent token may create 20 requests an hour. The inbox stores each item's expiry: an expired pending item reads as cancelled at once and the hourly inbox.expire job closes it. Whether a decided requester is notified is derived (only a person in the tenant is), never taken from the payload.
create and redeem are allowed on door mcp only, and only the MCP door's own code dispatches them (they are not tools). The door's per-actor rejection limit applies, so refused redemptions are capped like any denial. A tool that takes personal fields cannot be marked sensitive: its arguments would be stored and shown in plain text.
3. Audit
Every step is a bus command, so the audit log has: the request (agents.request.create, the confirmation request), the decision (agents.request.approve, or .reject), each refused redemption (agents.request.redeem, failed: the refused confirmation), the redemption (agents.request.redeem, allowed) and the action itself with confirmed = true.
What it proves now
An action marked sensitive ran over MCP only after the person the agent acts for, signed in to the web app with their own session, approved that exact call (tool and arguments) less than 30 minutes earlier, and it ran once.
Alternatives considered
- Sidecar-issued agent tokens (a second audience, or
Actor::Agentwithon_behalf_ofin the token): needs changes toservices/auth, which another task owns. The MCP token can move there later without changing the approval flow. Actor::Agent { on_behalf_of }as the bus actor: every module policy would need to learn the new principal to let an agent do what its person may. Keeping the person as the actor and the door as the boundary reuses every policy as it is.- MCP elicitation for the approval: the client renders and answers it, so the server cannot tell a person's answer from the agent's (ADR 0003).
Consequences
- Sensitive tools need the
agentsmodule compiled in and enabled for the tenant; without it they are refused. The inbox must be enabled to notify the person. - The approval step is in the web app only: the MCP and CLI doors are refused. What it does not stop yet: an agent that reads the person's sidecar token from disk (the CLI's credentials file) can call
/graphqldirectly, which is not labelled CLI; and an agent that drives the person's signed-in browser can click Approve. A web-only step-up proof (a fresh re-authentication, or a passkey assertion bound to the request) is future work. leave.approve,leave.reject,attendance.request.approveandattendance.request.rejectship as sensitive MCP tools.- ADR 0003's
mcp.confirmationstable and functions are dropped (api-mcpmigration 0002). - Shortcuts: revocation is per person, not per token. A token created in the very second of a revocation would be refused, so issuing waits that second out. The
inbox.expireschedule reads the tenants with the inbox enabled when the scheduler starts (as attendance's does); a tenant that enables it later is swept after a restart, and its expired items read as cancelled meanwhile. The token-issue cap is per process, like the other limits.