Let the agent draft, make a human send: approval gates for MCP tools that touch the real world
Read-only MCP tools are easy to trust. search_notes can't hurt anyone. The trouble starts with tools that do things: send an email, post to a channel, refund an order, trigger a workflow. An agent that can call send_ema
Read-only MCP tools are easy to trust. search_notes can't hurt anyone.
The trouble starts with tools that do things: send an email, post to a channel, refund an order, trigger a workflow. An agent that can call send_email will, sooner or later, call it with the wrong recipient, the wrong tone, or twice. Prompt instructions like "always ask before sending" help, but they live in the model's context, and anything in the context (a pasted email, a web page, a tool result) can argue with them.
The fix I keep coming back to is boring and reliable: split every side-effecting action into a draft step the agent can do and a commit step only a human can unlock. The rule is enforced by the server, not by the prompt.
The pattern in one picture
agent ββdraft_email(to, subject, body)βββΆ server stores draft, returns draft_id + preview
human ββreviews preview, approvesβββββββΆ server issues one-time approval code for that draft
agent ββsend_draft(draft_id, code)ββββββΆ server checks code, hash and expiry, then sends once
Three properties make this work:
- The approval is bound to the exact content. The server hashes the draft. If anything changes after approval, the code no longer matches.
- The approval is single-use and short-lived. One code, one send, a few minutes.
- The code never passes through the model. The human approves in a channel the agent can't write to: a web page behind the same OAuth login, a push notification, or the MCP client's own elicitation prompt.
Step 1: a draft tool that can't send
server.registerTool(
'draft_email',
{
title: 'Draft email',
description: 'Prepare an email for the user to review. Does NOT send. Returns a draft_id and a review link.',
inputSchema: z.object({
to: z.array(z.string().email()).min(1).max(10),
subject: z.string().min(1).max(200),
body: z.string().max(20_000)
}),
annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: false }
},
async ({ to, subject, body }, ctx) => {
const owner = ownerOf(ctx);
const draft = { to, subject, body };
const id = crypto.randomUUID();
await kv.put(`draft:${owner}:${id}`, JSON.stringify({ ...draft, hash: await sha256(draft) }), { ttlSeconds: 86_400 });
return text({ draft_id: id, review_url: `${BASE_URL}/review/${id}`, preview: draft });
}
);
Note the annotations. openWorldHint: false is honest here: drafting touches nothing outside your own storage. Clients use these hints to decide how loudly to warn the user, so don't lie in them.
Step 2: approval happens off the model's path
The review page sits behind the same OAuth sign-in your MCP server already uses. It shows the stored draft (from storage, not from whatever the agent claims) and an Approve button. Approving creates a code bound to that draft's hash:
async function approve(owner: string, draftId: string) {
const draft = JSON.parse(await kv.get(`draft:${owner}:${draftId}`) ?? 'null');
if (!draft) throw new Error('draft not found or expired');
const code = randomCode(8);
await kv.put(`approval:${owner}:${draftId}`, JSON.stringify({ codeHash: await sha256(code), draftHash: draft.hash }), { ttlSeconds: 600 });
return code; // shown to the human only
}
The human then pastes the code into the chat ("approved, code K7Q2-M9XD"), or, if your client supports MCP elicitation, the server asks for it directly with a form the model never fills in.
Step 3: the commit tool checks everything, then sends once
server.registerTool(
'send_draft',
{
title: 'Send approved draft',
description: 'Send a draft the user approved. Requires the approval code the user received. Never guess a code.',
inputSchema: z.object({ draft_id: z.string().uuid(), approval_code: z.string().min(6).max(20) }),
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: true }
},
async ({ draft_id, approval_code }, ctx) => {
const owner = ownerOf(ctx);
const draft = JSON.parse(await kv.get(`draft:${owner}:${draft_id}`) ?? 'null');
const approval = JSON.parse(await kv.get(`approval:${owner}:${draft_id}`) ?? 'null');
if (!draft || !approval) return text('Not approved yet. Ask the user to review the draft.');
if (approval.draftHash !== (await sha256({ to: draft.to, subject: draft.subject, body: draft.body })))
return text('Draft changed after approval. Ask the user to approve again.');
if (approval.codeHash !== (await sha256(approval_code))) return text('Approval code does not match.');
await kv.delete(`approval:${owner}:${draft_id}`); // burn it first: a retry can't double-send
const result = await mail.send(draft, { idempotencyKey: draft_id });
return text({ sent: true, message_id: result.id });
}
);
Two details worth stealing:
- Burn the approval before the side effect. If the send times out and the agent retries, the second call fails closed instead of sending twice. Pair it with an idempotency key on the provider side (most email and payment APIs take one) so a real network retry is still safe.
- Return plain-language refusals. "Not approved yet. Ask the user to review the draft." steers the model back to the human far better than a stack trace.
Where this belongs (and where it doesn't)
Use the gate for anything that is visible to other people, costs money, or can't be undone: outbound messages, payments, deletes, publishing, permission changes. Don't gate reads or private scratch writes; approval fatigue is real, and people who click "approve" forty times a day stop reading what they approve.
A good rule of thumb: if you'd want an undo button and there isn't one, put a human in front of it.
Why not just rely on the client's confirmation dialog?
Some MCP clients already ask "allow this tool call?" Keep that, but don't depend on it:
- Users click "always allow" within a day.
- The dialog shows tool arguments, not the rendered email, so people approve JSON they didn't read.
- It's per-client. Your server can be called from Claude, Cursor, ChatGPT, or a script, and only some of them ask.
A server-side gate holds no matter who connects.
Wrap-up
Let the agent do the 90% that's tedious: finding the thread, writing the draft, picking the recipients. Keep the last 10%, the irreversible click, behind a check the model can't talk its way past. It's about 60 lines of code, and it turns "I'm scared to give the agent a send tool" into "the agent drafts, I tap approve."
If you're building a remote MCP server and don't want to hand-roll the OAuth 2.1 half first, I packaged my TypeScript and Python template (OAuth 2.1 + PKCE, dynamic client registration, scoped tools) as the Remote MCP Connector Kit.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.