A confirmation token cannot prove consent
We ran a public MCP server for about six months before it had a single irreversible action in it. MCP, the Model Context Protocol, is how an AI agent discovers and calls the tools a server exposes. Ours offered reads, drafts and scheduling, all recoverable.
Then we added one that takes a person off a running automated campaign, a state flip nobody can undo from the UI.
I wanted a confirmation step in front of it. I built one. Then I spent an afternoon proving to myself that it does not do what the phrase "requires user confirmation" implies, and the rest of the week working out what it does do instead.
The short version is that a model reads every byte your server returns. If one of those bytes is a confirmation token, the model holds the confirmation. Nothing in the protocol stops it from calling the preview, reading the token out of the result, and calling the write with that token in the same turn, with no human in between. The token is in the model's context, and the model's context belongs to the model.
No client is doing anything wrong. That is just what happens when the confirmation travels back down the same channel the model reads.
The menu of guardrails, and why each one was empty
Before writing anything I went through what MCP and the host apps that embed the model offer. Four mechanisms, none of which survived contact.
Tool annotations. MCP tools carry hints: readOnlyHint, destructiveHint, idempotentHint, openWorldHint. They apply to a whole tool, not to one action inside it. Our write tool already routes about a dozen actions through a single name, picked by an argument, and was already flagged destructive for an unrelated one. Adding an irreversible action told a client nothing it did not already know. Worse, the spec tells clients to treat annotations as untrusted unless the server is trusted, and binds destructiveHint to no client behaviour at all. It is a label, and the label was already on.
Host permission rules. The "always allow" option in the hosts we care about matches on server name plus tool name. There is no argument matching. A user who approves a harmless create action on a multiplexed write tool has pre-approved every other action behind that same name, including the one that deletes things. This is the strongest argument I know of against routing many actions through one tool, and I only saw it once I had a destructive action hiding behind a benign sibling.
The tool manifest. This is where I was wrong, and the part I would want someone else to check in their own repo. Our tool manifest had category: 'destructive' and defaultEnabled: false on the entries that mattered. Several of us believed that meant it was off by default until an admin turned it on.
I went looking for the enforcement path and grepped for the function that was supposed to read those fields. It had exactly one occurrence in the whole repo, which was its own definition. Zero call sites.
The preference resolver that actually ran at request time was opt-out rather than opt-in, initialized its disabled sets to empty, never imported the manifest, and failed open on error. So the field that looked like a gate was documentation with a type annotation. Everything was enabled for everyone, and had been since the first deploy.
Elicitation. This is the one protocol feature that would round-trip a real question to the human. The server asks the client, the client asks the person, the answer comes back. It was unreachable for us, and not because of the protocol.
We run stateless streamable HTTP to fit a serverless runtime: no session id, plain JSON responses, and GET /mcp returning 405. Without a session there is no channel to push a server-initiated request down, so those requests get dropped on the floor inside send(). A hosting decision made months earlier, for reasons that had nothing to do with safety, had quietly removed the only safety option that could have worked.
What we shipped instead
One action, with an optional confirmationToken argument.
Call it without the token and it resolves the targets, returns a preview of who would be affected and what would happen to each, writes nothing, and mints a token that fingerprints that plan. Call it with the token and it re-resolves the targets from scratch, checks the token against the freshly resolved plan, and only then writes.
The property I can defend is not that a human saw the preview. I cannot prove that. What I can prove is that the second call cannot act on anyone who was not in the first call's plan. That is a claim about the plan rather than about a person, and it is what the tool description says, word for word.
The token, and why it is unkeyed
The handler runs in a Lambda with no state store attached. Adding one for a value that lives ten minutes meant a table and an eviction policy nobody wanted to own. So the token describes itself. It is a SHA-256 digest over a canonical string built from a version tag, the calling user, the parent object, the sorted target keys and the issue time. The issue time also travels in the clear, so the verifier can enforce a ten-minute expiry with a minute of tolerance for clock skew.
It is not a keyed hash, and that is deliberate. An HMAC would have needed a secret in the secrets manager and a new IAM statement on the function role, and a safety control that stops working when secret provisioning goes wrong is worse than one with no secret to provision. The threat model here is an agent widening its own scope between two calls, not a forger. A forger already holds the OAuth credentials to call the write directly. The code comment says this outright, because the next person to read it will otherwise assume it is an authorization boundary.
It is also two digests rather than one, so a failure can name its own cause. A token minted for a different caller or a different parent object fails as confirmation_invalid, which is usually someone pasting the wrong thing. A token whose target set no longer matches fails as plan_changed, which is the case that matters.
Replay is allowed within the ten minutes. There is no store to consume the token in, so a second confirm with the same token goes through. That is only safe because both legs re-resolve before writing, and the underlying write only applies to a target that has not already flipped, so the second attempt is a no-op. The safety comes from re-resolution rather than from single use, and I would rather say that than pretend otherwise.
The bug that nearly made the digest meaningless
Target keys in our system embed a raw email address, something like d:someone@example.com#0. My first canonicalization joined the sorted keys with a comma.
A comma is legal inside a quoted email address, in the part before the @ sign, and so is a hash. So one crafted address can produce a canonical string identical to two real keys joined together. A one-target preview, with that target supplied by whoever is driving the agent, could mint a digest that validates a two-person write. If two different target sets can produce the same canonical string, the token's promise about who is in the plan is worth nothing.
The fix is boring and worth stating anyway.
// Wrong: separator characters can appear inside a key.
const canonical = keys.slice().sort().join(',');
// Right: JSON.stringify escapes any character that could blur the key boundary.
const canonical = JSON.stringify(keys.slice().sort());
JSON.stringify escapes what it needs to, so the string determines the array uniquely. Any time you hash a joined list, the join is the security boundary, and a separator is only a boundary if it cannot appear inside an element.
The test I care most about asserts that a token minted for targets [a, b], presented with [a, b, c], fails as plan_changed with zero writes. Reordering must pass. Case differences in the email part must pass. If any of those three go the other way the control is either useless or so brittle that users will route around it.
The upstream lies about success, so you verify after writing
Once the write goes out you hit a second problem. The API you are calling will tell you it worked when it did not. Ours does this in four different shapes.
A field allowlist silently drops out-of-scope fields and returns 200 with the object unchanged. A 204 means both "cancelled" and "was already cancelled", so you cannot tell your own write apart from someone else's. A bulk endpoint returns the list of rows that matched before the write, discarding no-op results, so it happily echoes back people it never transitioned. And the count field you would reach for to confirm the change never moves, because removal is a state flip and not a delete.
So the confirm leg, the second of the two calls, re-reads afterwards and asserts the target's state, never its absence. Absence is not observable here. That read has to be the admin-scoped variant, the one that also returns targets belonging to other users in the workspace. Otherwise an admin removing someone else's target reads back nothing and gets a frightening error about a write that in fact succeeded.
That confirm leg is also capped at ten targets per call, concurrency three, an eight-second per-call timeout, and an eighteen-second wall-clock budget against a twenty-seven second handler deadline. It tracks "never dispatched" separately from "aborted in flight", because a call that was never sent has a known effect and is safe to retry.
Order the checks so the preview is not a free oracle
The feature gate runs before the token check. That ordering is not cosmetic. The preview leg resolves and returns a list of people, so if the token check ran first, a caller the gate would have blocked could learn who is on a campaign by calling with no token and reading the preview. Any call that reads before it writes is a way for someone to enumerate what they cannot otherwise see. The cheapest fix is to put authorization at the top of the handler and keep it there through refactors.
Measure self-approval instead of pretending to prevent it
Since I cannot enforce that a human saw the preview, I measure how often one plausibly did.
The server emits a structured event on both legs with a correlation id. The metric I watch is the confirm-to-preview ratio and the gap between the two. A healthy distribution has a ratio below one, because people abandon, and gaps in the tens of seconds, because people read. A ratio sitting at 1.0 with sub-second gaps is a model approving itself, in volume, and that is a dashboard I can alert on. It tells me afterwards that self-approval happened. It does not stop it.
The last piece is the server-level instructions, returned once in the initialize response. The spec puts no obligation on a client to show them to anyone on any given turn. Ours say that the original request is not consent, that the other destructive actions commit immediately with no preview and no token, and that the model must never tell a user a change is still pending once it has been made. I have no way to enforce any of that. I write it anyway, because the models that read it mostly follow it.
"Requires user confirmation" is a claim about a human being. The only thing I can ship is a claim about a plan.