Policy gate for agent tool calls. It evaluates each call against a rule set before the call reaches the tool, and writes an audit record for every decision.
The target is the operator's own agent sessions and MCP fleet. See THREAT_MODEL.md for scope and attacker model.
agent_gate/
policy.py rule model and verdict evaluation
gate.py evaluate_call entry point with optional audit hook
audit.py append-only JSONL decision log with secret redaction
proxy.py MCP stdio proxy (newline-delimited JSON-RPC)
cli.py `agent-gate check|proxy|audit-tail`
tests/ pytest suite
Policies are JSONL files, one rule per line:
{"id": "no-eval", "tool": "eval_*", "action": "deny", "reason": "code exec"}
{"id": "fs-roots", "tool": "fs_*", "action": "allow",
"paths_under": ["/home/me/projects"], "max_arg_bytes": 65536}
{"id": "review-rest", "tool": "http_*", "action": "ask"}First matching rule wins. Unmatched calls are allowed. Rules support
glob tool patterns and path confinement under paths_under, plus
argument size caps. Hidden-Unicode arguments are denied by default.
Relative paths containing .. are denied under confinement.
file:// URIs are unwrapped before the check.
Check a single call:
agent-gate check --server github --tool write_file \
--args '{"path":"x","content":"y"}' --policy rules.jsonl
Exit codes: allow is 0, deny is 1, ask is 3. Usage or policy errors exit 2.
Gate a live MCP stdio server:
agent-gate proxy --policy rules.jsonl --audit audit.jsonl -- \
python3 my_mcp_server.py
The proxy forwards all JSON-RPC traffic except tools/call. Denied
calls get a synthesized isError tool result and never reach the
server. ask verdicts resolve through --on-ask (default deny)
since a proxy cannot prompt.
Tail the audit log:
agent-gate audit-tail --audit audit.jsonl -n 50
python3 -m pytest tests/