Give an AI agent a shell, a filesystem and a database, and it has every
permission you have — and no idea which of them are dangerous. It will
git push --force because a plan said so. It will rm -rf a path it
misread. It will run a DELETE whose WHERE clause it guessed. Not out of
malice. Because nothing told it not to, and nothing was watching.
And the tools talk back. The model reads every tool description as
instructions, and a server can change its descriptions long after you
installed it. A web page the agent fetches can carry orders in characters no
person can see. The agent reads your .env for a perfectly good reason, and
three calls later its contents are in a request body — base64-encoded, so
nothing that looks for secrets would notice.
The Model Context Protocol turned "give the model real tools" into a one-line
config change. It says nothing about what the model may do with those tools,
does not notice when the tools themselves change, keeps no record of what
happened, and has no way to stop it mid-flight. So far the choice has been
binary: trust the model and every server it talks to, or do not install them.
agentgate is the third option. A small proxy that sits between the agent
and its tools, speaks MCP on both sides, and does three things:
Stop
A policy in plain YAML decides what gets through. Deny rm -rf. Ask before anything the server itself calls destructive. Send nothing anywhere once the session has read a page with hidden instructions in it. Start from reviewed packs, approve from your phone, and freeze every agent on the machine with one command.
Detect
Tripwires for what no policy anticipates. Tool definitions pinned in a lockfile, so a rug pull is held back before the model reads it. Poisoned descriptions caught by a scan. Fake credentials that are caught on their way out, however they are encoded. Decoy tools that no honest agent would ever call.
Prove
Every call — arguments, result, decision, reason — in a local log that is hash-chained, so an edit shows. Replay yesterday's session against tomorrow's policy, turn it into an offline test fixture, send it to your tracing, fail a CI job on it.
No changes to the agent. No changes to the tools. No cgo, no runtime, no
cloud. One binary, one YAML file, and agentgate init does the wiring.
Every recording on this page is real output from the binary, replayed from a
transcript in docs/demo/. Nothing is mocked.
A web page tells the agent to leak your AWS keys. The keys are a canary,
planted with one command. The agent reads them with its own file tool —
agentgate never sees that — fetches an issue whose page hides an instruction
in invisible Unicode, and mails the keys out, base64-encoded. The canary is
caught on its way out, the session can no longer send anything anywhere, and
the log proves what happened.
A server you trusted ships an update. Its search tool now tells the model
to read ~/.ssh/id_rsa — in Unicode tag characters, which render as nothing
at all. The tool was pinned the day it was trusted, so the change is held
back before the model ever reads it, and the hidden text is spelled out.
An agent gets to work. Then it gets ideas. It reads a file, runs the
tests, is denied on rm -rf, and then calls a tool that does not exist — a
honeypot. Every agent on the machine is frozen until a human looks.
Test tomorrow's policy on yesterday's session. Three new rules, one
command, and you know exactly which of the seven calls would now be stopped —
without sending anything anywhere.
Let the log write the policy. Run a strict policy in shadow mode — it
records what it would have done and blocks nothing — look at the numbers,
then let policy suggest turn what the agent actually did into a
deny-by-default allow-list.
Ask before you ship a rule.check evaluates a single call against the
policy — at any time of day you like, with any budget already spent — and
exits non-zero on a deny, so it works as a test in CI.
60 seconds
brew tap bnymnDev/agentgate https://github.com/bnymnDev/agentgate
brew install --cask agentgate
or go install github.com/bnymnDev/agentgate/cmd/agentgate@latest, or a
prebuilt binary for linux, macOS or Windows from the
releases page, or the
container image ghcr.io/bnymndev/agentgate. Then:
agentgate init # finds your MCP hosts, shows what it would change
agentgate init --yes # puts agentgate in front of every server they use
init knows Claude Desktop, Claude Code, Cursor, Windsurf, VS Code and
Gemini CLI. For each host it writes a config with the host's servers carried
over, the baseline, secrets and lethal-trifecta packs, tool pinning and
a honeypot — in shadow mode, so everything is recorded and nothing is
blocked yet — and it keeps the original entries byte for byte.
agentgate uninstall puts them back.
Restart the host, and watch:
agentgate tail -c ~/.agentgate/cursor.yaml # every call, live
agentgate doctor -c ~/.agentgate/cursor.yaml # is everything in order?
When the shadow decisions look right, set policy.mode: enforce.
That works with any MCP host that starts stdio servers — Claude Code,
Claude Desktop, Cursor, Zed, Windsurf, your own — and agentgate run --http
serves the ones that connect over HTTP.
What's in the box
Stop
A policy in YAML
Rules on the tool, its arguments, what the server says about it, the time of day, the host, and what the session has done so far. First match wins. A denied call comes back to the agent as a reason it can read.
Packs
Reviewed rule sets, switched on by name: baseline, secrets, lethal-trifecta, git-safety, github, database, filesystem, shell-strict, read-only, ask-destructive, business-hours. Your own rules always come first.
Session labels
Facts a session picks up on its way — read a web page, touched production, read a secret — and rules that ask about them. That is how "never post anything after reading untrusted content" becomes one line.
Approvals on your phone
An ask rule parks the call and asks everywhere at once: the terminal, the web UI and your phone, with Allow, Allow for session and Deny buttons. First answer wins.
Kill switch
agentgate freeze denies every tool call from every agent on the machine, instantly, without dropping a connection.
Loop guard and budgets
The same call ten times in a row is a stuck agent burning money. Per session, per tool, per minute, per token: hard caps no rule can lift.
Offer less
tools: [get_issue, "list_*"] on an upstream: a tool that is not offered cannot be called, and its description never reaches the model.
Detect
Tool pinning
Every tool definition is pinned in a lockfile on first sight. A server that later changes what a tool says is reported — or, with enforce, the tool is held back until you trust it. agentgate lock shows the diff.
Poisoning scan
Instructions hidden in invisible Unicode, text addressed to the model instead of describing the tool, pointers at ~/.ssh and agent configs, one server's tool steering another's.
Canaries
agentgate canary new plants a fake AWS, GitHub, OpenAI or Stripe key. Nothing legitimate ever sends it anywhere, so a call that does is stopped — in plain text, base64, hex, URL-encoded or reversed.
Injection in results
A result with hidden text or instructions aimed at the model labels the session injection-suspected; strip_invisible takes the hidden characters out before the model reads them.
Honeypots
A decoy tool — db__drop_all_tables — that nothing legitimate calls. Calling it is a prompt injection caught red-handed, and can freeze everything on the spot.
Live view
agentgate tail in any terminal, and a web UI with a live page, the approvals inbox, the pinned tools and a trust button.
Prove
A hash-chained audit log
Every call with its arguments, result, decision, reason and duration, in local SQLite, secrets scrubbed. Each call is chained to the one before it: agentgate verify proves nothing was edited, removed or reordered.
Replay and diff
agentgate replay <session> --dry-run runs a real session through the current policy and shows exactly which decisions change.
Mock servers
agentgate mock <session> serves a recorded session as an MCP server — the same tools, the recorded answers, nothing real behind it. A repeatable, offline fixture.
OpenTelemetry
One trace per session, one span per call, over OTLP to Jaeger, Tempo, Honeycomb, Datadog or anything else that speaks it.
Policy tests
agentgate test runs the calls a policy must stop and the ones it must let through — with the session each is made in — and fails CI when a change to a rule or a pack breaks one. --from <session> turns a recorded session into a test, so a good day of work becomes the regression suite.
CI
A GitHub Action that installs, lints and runs the policy tests, and one that writes what the agent did to the job summary and fails the job on a canary, a honeypot or a quarantined tool.
Webhooks
Slack, Discord, ntfy or plain JSON, for denials, questions, honeypots, drift, exfiltration and injection.
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?
agentgate policy lint # rules that never fire, allows that let too much through
agentgate test # and the calls it must never let through, as tests
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
packs: # reviewed rule sets; your rules come first
- baseline
- lethal-trifecta
- name: filesystem
with: { workspace: /home/me/repo }
budget:
calls_per_session: 500
calls_per_minute: 60
tokens_per_session: 200000
loop_guard:
repeats: 10
labels: # facts a session picks up on its way
- label: tests-passed
tool: "shell.test"
when: { result.is_error: false }
rules: # first match wins
- id: no-destructive-shell
tool: "shell.*" # glob, a|b alternation, or /regex/
when:
"args.{command,cmd}": { regex: '\brm\s+-rf|\bgit\s+push\s+--force' }
action: deny
reason: "destructive shell command"
- id: deploy-only-after-green-tests
tool: "shell.deploy"
when: { session.label.tests-passed: false }
action: deny
reason: "run the tests, and make them pass, before deploying"
- 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' }
not_regex
the value does not match this regular expression
args.sql: { not_regex: '(?i)\bwhere\b' }
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 }
includes
one of the values — or one item of a list among them — is exactly this
session.labels: { includes: private-data }
excludes
no value, and no item of a list among them, is this; also holds when there is none
session.called: { excludes: shell.test }
Paths: args.path, args.items[*].sku, "args.{command,cmd}", tool,
upstream, annotations.destructive, time.hour, host.name,
session.label.<name>, session.called. The whole language, including what
happens when a path is missing, is in docs/policies.md.
Test a rule before you ship it — once, with check:
Transparent by default. With one upstream and no matching rule, bytes
in equal bytes out. Tool schemas and results are never rewritten, except by
the two options that say so and are off by default.
Every decision has a reason. Allow, deny and ask are typed values with
a human-readable reason and the id of the rule that decided. No booleans.
Evaluation is pure. Same policy, same call, same session history, same
decision — no clock, no filesystem, no network inside the evaluator. That
is what makes replay trustworthy.
Fail closed, audit best-effort. A frozen gateway denies; a broken audit
store never blocks a call. The two are not symmetric on purpose.
One binary. No cgo, no daemon, no Node, no cloud, no account.
Kill switch, honeypots, tool pinning, the poisoning scan, canaries, injection, the lethal trifecta, approvals, the hash chain — how each works and when to use it
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
Contributions are welcome; see CONTRIBUTING.md for the
workflow and SECURITY.md for how to report a vulnerability.
Changes between releases are listed in CHANGELOG.md.
Status
v0.4. 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).
Next: approvals answered straight from a Slack message, and shared lockfiles
for popular servers, so a definition can be checked against what everyone
else pinned.
Package packs holds the policy packs that ship with agentgate: named, reviewed rule sets for the servers people actually run — shells, git, GitHub, databases, filesystems — that a policy switches on by name.
Package packs holds the policy packs that ship with agentgate: named, reviewed rule sets for the servers people actually run — shells, git, GitHub, databases, filesystems — that a policy switches on by name.
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.
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.
Package telemetry exports every tool call as an OpenTelemetry span, over OTLP/HTTP with JSON encoding, so agentgate's decisions show up next to the rest of your traces in Jaeger, Tempo, Honeycomb, Datadog or anything else that speaks OTLP.
Package telemetry exports every tool call as an OpenTelemetry span, over OTLP/HTTP with JSON encoding, so agentgate's decisions show up next to the rest of your traces in Jaeger, Tempo, Honeycomb, Datadog or anything else that speaks OTLP.