Skip to content

Approval gate (#68)

Tools flagged "requiresApproval": true in spec/registry-manifest.json (today: fs.write_file) do not run until a host approves the call. The model never approves anything: no approval tool exists in the catalog, tools/list or MCP. The gate is on by default (approval.mode: 'required'); opt out explicitly with approval: { mode: 'off' }.

Pipeline order: resolve → enabled (TOOL_DISABLED wins) → approval → dispatch → envelope.

Flow

  1. The model calls the tool. The runtime answers ok: false, error.code = APPROVAL_REQUIRED, with meta.approvalId and meta.approvalExpiresAt.
  2. The host approves or denies out of band:
  3. SDK: kit.approve(id) / kit.deny(id) (Node, .NET Approve/Deny, Python approve/deny).
  4. Callback: runtime.approval.onRequest(req) → true|false (sync or async in Node/.NET, sync in Python). It gets { approvalId, tool, argsHash, expiresAt }. An exception or any value other than true means deny (fail closed). When a callback is set, no pending id is issued.
  5. MCP stdio (Node and Python): JSON-RPC method wartools/approval with params { id, decision: 'approve'|'deny', token }. It only exists when WARTOOLS_ADMIN_TOKEN is set; otherwise it returns -32601. A wrong token returns -32001.
  6. MCP SSE (Node): POST /approvals/{id} with Authorization: Bearer $WARTOOLS_ADMIN_TOKEN and body { "decision": "approve"|"deny" }.
  7. Workbench: executeWarTool('workbench/approval', { approvalId, decision }, config). This is a host-only operation and is not in the catalog.
  8. The model retries with identical arguments plus approvalId. The id is single-use and bound to tool + argsHash + sessionId. argsHash = sha256 of the canonical JSON of the args without sessionId/approvalId, first 16 hex chars; it is identical in all SDKs.

While the gate is active, tools/list adds an approvalId property to the input schema of gated tools and a retry hint to their description.

Error codes

Code recoverable Meaning
APPROVAL_REQUIRED yes No approvalId given; a pending approval was created (meta.approvalId, meta.approvalExpiresAt).
APPROVAL_PENDING yes The id exists but the host has not decided yet.
APPROVAL_DENIED no The host or onRequest denied the call, or the callback threw.
APPROVAL_EXPIRED yes The TTL elapsed (default 300000 ms, approval.ttlMs).
APPROVAL_MISMATCH no The id belongs to another tool or different arguments.
APPROVAL_INVALID no Unknown id, already used (replay), or a different sessionId.

Configuration

  • Node: WarTools.create({ runtime: { approval: { mode, ttlMs, onRequest }, policyStore, policyScope } }).
  • Python: WarTools.create(runtime={"approval": {...}, "policyStore": ..., "policyScope": ...}).
  • .NET: new WarToolsOptions { Runtime = new RuntimeOptions { Approval = new ApprovalOptions { ... }, PolicyStore, PolicyScope } }.
  • CLI: --approval required|off (default required); env WARTOOLS_ADMIN_TOKEN enables the out-of-band MCP approval channel.

Approval state lives in a PolicyStateStore (in memory by default), separate from KvStore. It never appears in snapshots, checkpoints, kv.* or traces; restoring a checkpoint cannot revive a used approval. Runtimes that share approvals (such as the workbench, which builds one runtime per call) must share a policyStore and a fixed policyScope.

Contract cases live in spec/contracts/runtime.json. Runners map config.runtime.approval.onRequest: "approve" | "deny" | "throw" to a host callback.