MnemoPay
How-to · MCP & approvals

Human approval for AI agent actions, in code and over MCP

Published 2026-11-04 · J&B Enterprise LLC · Apache-2.0 project

A policy gate, an approval queue and an audit trail around agent payments and other consequential actions, run for real against 1.15.2.

Two ways to put a human between an agent and a risky action: call the policy and approval modules from code, or let an MCP client use the MnemoPay server’s approval tools. Both were run against @mnemopay/sdk@1.15.2 (Node v25.9.0, 2026-11-04); outputs below are real.

Option A: policy, approval queue and audit chain in code

evaluateAction() checks an action against rules and returns allowed, blocked or needs approval. routeVerdict() opens an approval request when needed. A human decides. Each step is emitted to the audit chain.

import {
  compilePolicy, evaluateAction, InMemoryApprovalStore, routeVerdict,
  AuditChain, verifyBundle,
} from "@mnemopay/sdk/governance";

const policy = compilePolicy({
  id: "refund-bot-policy",
  version: 1,
  rules: [
    { id: "cap-per-action", applies_to: ["payment"], hard_cap_usd: 500 },
    { id: "human-above-25", applies_to: ["payment"], approval_threshold_usd: 25 },
  ],
});

const approvals = new InMemoryApprovalStore();
const chain = new AuditChain();

async function attempt(action) {
  const verdict = evaluateAction(policy, action);
  chain.emit("policy.evaluated", { action, verdict: stripLatency(verdict) });
  const routed = routeVerdict(approvals, action, verdict);
  return { verdict, routed };
}
const stripLatency = ({ latency_ns, ...rest }) => rest;

// 1. small payment: allowed straight away
let r = await attempt({ kind: "payment", target: "refund:A-1001", estimated_usd: 10 });
console.log("$10  ->", r.routed);

// 2. mid-size payment: needs a human
r = await attempt({ kind: "payment", target: "refund:A-1002", estimated_usd: 40 });
console.log("$40  ->", r.routed);
const id = r.routed.approval_id;
console.log("pending:", approvals.pending().map((a) => a.id === id));

// 3. a human decides; the decision is recorded as an event
const decided = approvals.decide(id, "approve", "ops@example.com", "customer verified by phone");
chain.emit("approval.decided", { approval_id: id, status: decided.status, by: decided.decided_by, notes: decided.notes });
chain.emit("action.executed", { target: "refund:A-1002", usd: 40 });

// 4. over the hard cap: blocked, no approval path
r = await attempt({ kind: "payment", target: "refund:A-1003", estimated_usd: 900 });
console.log("$900 ->", r.routed);

const bundle = chain.toBundle({ system: "refund-bot" });
console.log(bundle.events.map((e) => e.kind).join(" | "));
console.log("bundle:", verifyBundle(bundle));

Output (reformatted onto one line per result; the approval id is a UUID and differs per run):

$10  -> { allowed: true }
$40  -> { allowed: false, blocker: 'pending', approval_id: '0506fe77-6805-4a62-a635-9a403e6a7c8d' }
pending: [ true ]
$900 -> { allowed: false, blocker: 'blocked', reason: 'hard_cap_usd' }
policy.evaluated | policy.evaluated | approval.decided | action.executed | policy.evaluated
bundle: { ok: true }

Notes on what this is. InMemoryApprovalStore is a reference store; the ApprovalStore interface (open, get, pending, decide, expire) is meant to be implemented over Redis, Postgres or a Slack flow. The store is not wired to a notification channel for you, and your code must refuse to execute until decide(..., "approve", ...) has run. The policy engine is synchronous and does no network I/O.

Option B: the MCP server

The MnemoPay MCP server is installed with npx -y @mnemopay/sdk (for Claude Code: claude mcp add mnemopay -s user -- npx -y @mnemopay/sdk). By default it exposes only 14 “essentials” tools (memory, wallet, transactions). The approval and governance tools are opt-in:

MNEMOPAY_TOOLS=hitl,governance npx -y @mnemopay/sdk
# or: npx -y @mnemopay/sdk --tools=hitl,governance

With that setting the server reported 17 tools, including charge_request, charge_approve, charge_reject, policy_set, policy_evaluate, action_begin, action_end, audit_bundle_export and audit_bundle_verify. A real call sequence over stdio JSON-RPC:

charge_request  { amount: 40, reason: "refund order A-1002" }
  -> { "requestId": "cr_...", "status": "pending_approval", "expiresIn": "10 minutes" }
charge_approve  { requestId: "cr_..." }
  -> { "status": "charged", "txId": "1", "amount": 40, "rail": "mock", ... }
action_begin    { agentId: "refund-bot", intent: "refund order A-1002", risk: "medium" }
action_end      { actionId: "<id>", status: "completed", result: "refunded $40" }
audit_bundle_export { meta: { system: "demo" } }
  -> events: action.begin, action.end   (2 events)
audit_bundle_verify { bundle }            -> { "ok": true }
...after editing one event:                 -> { "ok": false, "reason": "root_mismatch" }

Read this before relying on it. In our run rail was "mock": no money moved. The exported bundle came from the action ledger (action_begin/action_end) and contained only those two events; the charge_request/charge_approve decision was not in it. If you need the approval decision in the evidence, record it as an action or use Option A. The approval request expires after 10 minutes. Live Stripe settlement is only verified against mocks and an opt-in test-mode test.

Which to choose

Code (Option A)MCP (Option B)
Who decidesYour code and storeThe MCP client’s user, via tool calls
Approval in the audit chainYes, if you emit it (shown)Not automatically (see note)
SetupWrite the glueOne env var

Next

Related

Want help wiring this into a real agent workflow? We run a small number of design-partner pilots. The SDK itself stays free and open source.