agent-action-gate
by dwadlane
README.md
# agent-action-gate
Let AI agents do real work without letting them do anything unreviewed: every write is proposed, approved, run once and logged.
```mermaid
sequenceDiagram
participant Agent
participant Gate
participant Human
participant System
Agent->>Gate: propose_action
Gate-->>Agent: action id + plain-English preview
Gate->>Gate: check policy (auto, ask a person, or block)
Gate->>Human: waiting for approval (two people if high risk)
Human->>Gate: approve_action (named approver)
Agent->>Gate: execute_action
Gate->>System: write, exactly once
System-->>Gate: result
Gate->>Gate: append to audit log (PII redacted)
Gate-->>Agent: result (a second execute returns the same result)
```
## Why This Exists
Agents retry, so they double-send the same message or create the same record twice.
Agents guess, so they write the wrong record and nobody sees it until a client does.
Agents see everything, so patient details end up in logs and chat transcripts.
We put one gate in front of every write, so a person stays in charge and every change can be traced and undone.
Targets MCP protocol 2025-11-25 via the official TypeScript SDK (`@modelcontextprotocol/sdk` 1.32.2, the newest release). Every tool carries MCP annotations (`readOnlyHint`, `destructiveHint`, `idempotentHint`).
## Quick Start
```bash
git clone https://github.com/dwadlane/agent-action-gate && cd agent-action-gate
npm install
npm run demo # a scripted agent session, no accounts needed
npm test # 39 tests, including a real stdio MCP client
npm run build
```
Add it to any MCP client (Claude Desktop, Claude Code, Cursor):
```json
{
"mcpServers": {
"agent-action-gate": {
"command": "node",
"args": ["/path/to/agent-action-gate/dist/index.js"],
"env": { "AAG_POLICY": "/path/to/policy.json", "AAG_AUDIT_LOG": "/path/to/audit.jsonl" }
}
}
}
```
The server runs on mock backends (a CRM and a clinic patient-records store with fictional data), so it works with zero accounts.
| Tool | What it does |
| --- | --- |
| `propose_action` | Returns an action id and a plain-English preview. Changes nothing. |
| `list_pending` | Everything waiting for a person. |
| `approve_action` | A named person approves. High risk actions need two different people. |
| `reject_action` | A named person turns it down for good. |
| `execute_action` | Runs an approved action once. A second call returns the first result. |
| `undo_action` | Reverses an action that registered an undo step. |
| `pause_all` / `resume` | The kill switch. |
| `audit_log` | Reads the append-only log and checks its hash chain. |
Use it as a library too:
```ts
import { Gate, AuditLog, PolicyEngine, parsePolicy, registry } from "agent-action-gate";
const gate = new Gate({
registry: registry([myKind]), // your own write, with a preview and an undo
policy: new PolicyEngine(parsePolicy(policyJson)),
audit: new AuditLog("audit.jsonl"),
});
const { action } = gate.propose({ kind: "crm.update_contact", params });
gate.approve(action.id, "Priya Shah");
await gate.execute(action.id);
```
## The Policy
`policy.json` decides what an agent may do alone, what needs a person, and what is never allowed.
```json
{
"highRiskApprovers": 2,
"defaults": { "mode": "approval" },
"actions": {
"crm.create_deal": { "mode": "auto", "autoIf": { "field": "value", "lte": 1000 } },
"crm.update_deal_stage": { "mode": "auto" },
"crm.delete_contact": { "mode": "block", "reason": "Agents never delete contacts." },
"clinic.update_patient": { "mode": "approval", "risk": "high" }
},
"rateLimits": {
"global": { "perMinute": 30 },
"perAction": { "crm.update_deal_stage": { "perMinute": 10 } }
},
"businessHours": {
"timezone": "Australia/Melbourne",
"days": [1, 2, 3, 4, 5],
"start": "08:00",
"end": "18:00",
"appliesTo": ["clinic.update_patient"]
}
}
```
Anything without a rule waits for a person. Set `defaults.mode` to `block` and anything without a rule is refused.
## The Demo
`examples/demo.ts` runs five proposals: two auto-approved by policy, one that waits for two people and is approved, one blocked by policy, and one retry whose duplicate execute is ignored. Then a person undoes one. Full output in [`examples/demo-output.md`](examples/demo-output.md).
```text
10:30:01 agent proposed act_0001: Create a new deal "Kitchen rewire" worth $800 for Sarah Nguyen.
10:30:02 policy act_0001 auto-approved: value 800 is within the 1000 limit.
10:30:03 gate act_0001 ran once
...
10:30:07 agent proposed act_0003: Change patient record Jordan Ellis (p_101): phone from "0400 123 456" to "0400 999 888".
10:30:08 policy act_0003 needs 2 approvers (high risk)
10:30:09 gate act_0003 refused: act_0003 still needs 2 more approval(s).
10:30:10 Dr Chen approved act_0003 (1 of 2)
10:30:11 Priya approved act_0003 (2 of 2)
10:30:12 gate act_0003 ran once
10:30:13 agent proposed act_0004: Delete contact Tom Alvarez (c_002) permanently.
10:30:14 policy act_0004 blocked: Agents never delete contacts. A person does that in the CRM.
10:30:16 agent proposed the same change again (act_0001), gate recognised it
10:30:17 gate act_0001 already ran, duplicate ignored, first result returned
10:30:18 Priya undid act_0002, deal is back to quoted
```
In the audit log that patient change is stored as `phone from "[PHONE]" to "[PHONE]"`. The real numbers never touch the disk.
## When It Stops
The gate refuses, and tells the agent why in plain English, when:
- the action is not approved yet, or still needs a second person
- the policy blocks it, or a person rejected it
- the person who proposed it tries to approve it, or the same person approves twice
- the kill switch is on (`pause_all`), which stops every execute and undo until `resume`
- a rate limit is hit, or the action is outside business hours
- it already ran (the agent gets the first result back, nothing runs twice)
- the details don't fit the action, or the record it points at doesn't exist
Audit entries are redacted for emails, phone numbers, Medicare-style numbers and dates of birth, then chained by hash. Edit or delete a line and `audit_log` reports the chain as broken.
Know the limits. Pending actions and the pause switch live in memory in v0.1, so a restart clears them (the audit log is the durable record). Redaction is pattern based, so treat it as a strong safety net, not a guarantee for free text.
## Fits Any Stack
The gate does not care what is behind the write. An action is a name, a schema, a plain-English preview, an `apply` function and an optional undo. Write one per system.
- GoHighLevel: put it in front of contact edits, pipeline moves and messages. See [gohighlevel-mcp-safe](https://github.com/dwadlane/gohighlevel-mcp-safe), which does the same dry-run-then-confirm idea for GoHighLevel.
- CRMs: deal changes, contact merges and deletes.
- EHRs and clinic systems: patient detail changes with two-person approval and redacted logs.
- Ad APIs: budget and bid changes with a spend threshold for auto-approval and a hard block above it.
- Data pipelines: bulk writes that need a person to read the preview first.
For a read-side example of the same plain-English approach, see [owner-morning-brief](https://github.com/dwadlane/owner-morning-brief).
---
Built by Gaps2Gains. [Book a Free Discovery Call](https://gaps2gains.com/diagnosis)
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues