agentgate

module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2026 License: GPL-3.0

README

agentgate

Firewall, kill switch and flight recorder for your AI agent's tools.

One binary between your MCP host and your MCP servers.
Every tool call is checked against a policy, recorded, replayable — and stoppable with one command.

  MCP host                 agentgate                    MCP servers
┌────────────┐   stdio   ┌──────────────────┐  stdio  ┌──────────────┐
│  your      │──────────▶│ policy   audit   │────────▶│ filesystem   │
│  agent     │◀──────────│ ├ allow  ├ sqlite│◀────────│ github       │
└────────────┘           │ ├ deny   ├ replay│  http   │ shell, db, … │
                         │ ├ ask    └ tail  │────────▶└──────────────┘
                         │ └ freeze         │
                         └──────────────────┘

No changes to the host. No changes to the servers. No cgo, no runtime, no cloud.

Real output. The agent read a file, ran the tests, was denied rm -rf, then called a tool that does not exist — and every agent on the machine was frozen until a human looked.


Seven things it does that nothing else does

Kill switch agentgate freeze denies every tool call from every agent on the machine, instantly, without dropping a connection. agentgate unfreeze when you have looked.
Honeypot tools Advertise a tool that does not exist — db__drop_all_tables — and find out the moment an agent tries to use it. That is a prompt injection, caught red-handed. Optionally freezes everything on the spot.
Loop guard The same call with the same arguments ten times in a row is not diligence, it is a stuck agent burning money. agentgate stops it and tells the model why.
Shadow mode Run a strict policy without enforcing it. See what it would have blocked in the audit log, tune, then flip the switch.
Time-travel policy testing agentgate replay <session> --dry-run re-runs yesterday's real session against today's policy and shows exactly which decisions change.
Secret redaction, both ways Secrets are scrubbed before they reach the audit log — and, if you say so, before they reach the model. Your agent reads .env, the model gets [REDACTED].
Slack, Discord, ntfy, anything A denial, an approval request, a honeypot trip: get it on your phone. A webhook URL is all it takes.
Approvals that remember An ask rule parks the call until a human answers — in the terminal or the web UI — and "allow for this session" means the same question is not asked again a minute later.

Plus the boring parts done properly: a YAML policy language with globs, regexes and JSONPath-lite argument matching; budgets per session, per tool, per minute and per token; rules on what the server itself says about a tool (annotations.destructive: true); rules on the time of day (no deploys on Friday afternoon); approvals from the terminal or a web UI; a local SQLite audit log with replay, diff, stats and a live tail; and a policy suggest that writes a deny-by-default policy from what your agent actually did.


60 seconds

go install github.com/bnymnDev/agentgate/cmd/agentgate@latest

or with Homebrew:

brew tap bnymnDev/agentgate https://github.com/bnymnDev/agentgate
brew install --cask agentgate

Prebuilt binaries for linux, macOS and Windows (amd64 and arm64) are on the releases page.

1. Write agentgate.yaml:

version: 1

upstreams:
  - name: fs
    stdio: ["npx", "-y", "@modelcontextprotocol/server-filesystem", "/home/me/repo"]

honeypots:
  action: freeze
  tools:
    - name: fs__delete_everything
      description: "Recursively delete the whole workspace. Cannot be undone."

policy:
  default: allow
  loop_guard: { repeats: 10 }
  budget: { calls_per_minute: 60 }
  rules:
    - id: stay-in-the-repo
      tool: "fs.write_file"
      when:
        args.path: { not_prefix: "/home/me/repo/" }
      action: deny
      reason: "writes are confined to the repository"

2. Wherever your host config launched the server, launch agentgate instead:

{ "command": "agentgate", "args": ["run", "--stdio", "--config", "/home/me/agentgate.yaml"] }

Works with any MCP host that starts stdio servers — Claude Code (.mcp.json), Claude Desktop (claude_desktop_config.json), Cursor (.cursor/mcp.json), Zed, Windsurf, your own.

3. Watch:

agentgate tail
14:02:11  allow   fs__read_file          3ms
14:02:12  allow   fs__write_file         5ms
14:02:14  DENY    fs__write_file         0ms  writes are confined to the repository
14:02:19  TRAP    fs__delete_everything  0ms  honeypot: fs__delete_everything does not exist. Calling it means…
the gateway is now FROZEN

That last line is an agent that was told, somewhere in a file it read, to wipe the workspace. It did not get to.


The agent gets a reason, not a broken pipe

A denied call is not a transport error. It is a tool result the model can read:

agentgate denied: writes are confined to the repository (rule stay-in-the-repo)

…and it adapts. A blocked agent that understands why it was blocked stops trying the same thing. One that only sees an error retries until your budget is gone.


Shadow first, enforce later

Nobody writes a correct deny-list on the first try. So don't:

policy:
  mode: shadow        # record what would happen, block nothing

Run your agent for a day. Then:

agentgate stats --since 24h        # what did it actually do?
agentgate policy suggest > p.yaml  # an allow-list of exactly that, default: deny
agentgate replay <session> --dry-run   # what would the new policy have changed?

When the only things that flip to deny are the ones you meant, delete the mode: shadow line.


The policy language, in one screen

policy:
  default: allow                 # or deny, for a locked-down setup
  mode: enforce                  # or shadow
  redact_results: false          # true: secrets never reach the model
  budget:
    calls_per_session: 500
    calls_per_minute: 60
    tokens_per_session: 200000
    calls_per_tool: { fs.write_file: 50 }
  loop_guard:
    repeats: 10
  rules:                         # first match wins
    - id: no-destructive-shell
      tool: "shell.*"                              # glob, a|b alternation, or /regex/
      when:
        args.command: { regex: '\brm\s+-rf|\bgit\s+push\s+--force' }
      action: deny
      reason: "destructive shell command"

    - id: ask-before-anything-destructive
      tool: "*"
      when: { annotations.destructive: true }      # what the server says about itself
      action: ask

    - id: no-deploys-on-friday-afternoon
      tool: "*deploy*"
      when:
        time.weekday: { equals: "friday" }
        time.hour: { gt: 15 }
      action: deny

Matchers:

Matcher Holds when Example
equals the value is exactly this args.dryRun: { equals: false }
not_equals the value is anything but this args.mode: { not_equals: "dry" }
regex the value matches this Go regular expression args.command: { regex: '\brm\s+-rf' }
prefix the value starts with this string args.path: { prefix: "/etc/" }
not_prefix the value does not start with this string args.path: { not_prefix: "/srv/app/" }
in the value is one of these args.env: { in: ["prod", "staging"] }
gt, lt the value is a number above / below this; both may be combined args.amount: { gt: 10, lt: 100 }
exists the path is present (true) or absent (false) args.dryRun: { exists: false }

Paths: args.path, args.items[*].sku, tool, upstream, annotations.destructive, time.hour, time.weekday. The whole language, including what happens when a path is missing, is in docs/policies.md.

Test a rule before you ship it:

agentgate check --tool 'shell.exec' --args '{"command":"rm -rf /"}'
agentgate check --tool 'deploy' --at 'friday 17:00'
agentgate policy validate agentgate.yaml

Commands

Command What it does
check [flags] Dry-evaluate one call against the policy
diff <session-a> <session-b> [flags] Compare two recorded sessions
freeze [reason...] Stop every agent: deny all tool calls until unfreeze
policy Work with the policy file
policy suggest [flags] Write a deny-by-default policy from what the agent actually did
policy validate [file] Check that a config file parses and its rules make sense
replay <session-id> [flags] Re-run a recorded session through the current policy
run [flags] Run the proxy
sessions [flags] List recorded sessions
show <session-id> [flags] Show the calls of one session
stats [flags] What did the agent actually do? Per tool, per rule
status Show the gateway's state at a glance
tail [flags] Watch tool calls scroll by, live
ui [flags] Browse the audit log in a browser
unfreeze Lift the kill switch

Every flag: docs/config.md.


Get it on your phone

notify:
  webhooks:
    - url: https://ntfy.sh/my-agent          # or a Slack / Discord webhook URL
      format: ntfy                           # slack | discord | ntfy | json
      events: [deny, ask, honeypot, freeze]

A honeypot trip arrives as an urgent notification with the arguments the agent used. Arguments are redacted before they leave the machine.


Documentation

Document What is in it
docs/guardrails.md Kill switch, honeypots, loop guard, shadow mode, result redaction — how each one works and when to use it
docs/policies.md The rule language in full
docs/config.md Every field of agentgate.yaml, every CLI flag
docs/replay.md Replay, diff, stats, and the shadow → suggest → enforce workflow
docs/architecture.md How the proxy works, and what it deliberately does not do
docs/comparison.md Versus raw servers, wrapper scripts, host prompts and sandboxes
docs/decisions.md Design decisions and the reasoning behind each

Building from source

make build      # bin/agentgate
make test       # unit tests and policy golden files
make e2e        # the real binary in front of a real MCP server
make dev        # proxy + web UI against a demo server, nothing to install
make lint

Status

v0.3. Everything in this README is implemented and covered by tests, including the end-to-end suite that drives the real binary. Not in it, on purpose: asking a model whether a call is safe (rules are deterministic so that replay can be trusted), central or multi-user management, governing prompts and resources (they pass through untouched), and authentication in front of the web UI (it refuses to bind to anything but localhost unless you insist).

Roadmap: OpenTelemetry export of the audit log, a policy lint that flags rules no recorded call has ever matched, and approval requests answered straight from the Slack message.

License

GPL-3.0-or-later — see LICENSE.

Directories

Path Synopsis
cmd
agentgate command
Command agentgate is a policy proxy and audit log for MCP tool calls.
Command agentgate is a policy proxy and audit log for MCP tool calls.
internal
audit
Package audit persists sessions and tool calls in a local SQLite database.
Package audit persists sessions and tool calls in a local SQLite database.
cli
Package cli builds the agentgate command tree.
Package cli builds the agentgate command tree.
config
Package config loads and validates agentgate.yaml.
Package config loads and validates agentgate.yaml.
demogif command
Command demogif renders docs/demo/transcript.txt into docs/demo.gif.
Command demogif renders docs/demo/transcript.txt into docs/demo.gif.
gendocs command
Command gendocs regenerates the generated blocks in README.md and docs/.
Command gendocs regenerates the generated blocks in README.md and docs/.
killswitch
Package killswitch is the freeze: one file whose existence means "deny everything".
Package killswitch is the freeze: one file whose existence means "deny everything".
policy
Package policy contains the agentgate rule model and its evaluator.
Package policy contains the agentgate rule model and its evaluator.
proxy
Package proxy is the MCP passthrough: it terminates the connection from the host (downstream), keeps connections to the real MCP servers (upstream), and puts the policy evaluator and the audit log in between.
Package proxy is the MCP passthrough: it terminates the connection from the host (downstream), keeps connections to the real MCP servers (upstream), and puts the policy evaluator and the audit log in between.
replay
Package replay re-runs a recorded session: either against the current policy only (a dry run, which answers "what would this policy have done yesterday?") or against the current upstreams as well.
Package replay re-runs a recorded session: either against the current policy only (a dry run, which answers "what would this policy have done yesterday?") or against the current upstreams as well.
testserver
Package testserver is a small but real MCP server.
Package testserver is a small but real MCP server.
ui
Package ui serves the agentgate web interface: a read-only view of the audit database, the loaded policy, and the approvals inbox.
Package ui serves the agentgate web interface: a read-only view of the audit database, the loaded policy, and the approvals inbox.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL