All projects
AI Infrastructure

ToolGate

Security gateway for AI agents (MCP)

An MCP server that gives AI assistants governed access to the four systems above through one door: scopes, approvals, rate limits, a kill switch and a tamper-evident audit log.

Source code
PythonModel Context ProtocolFastAPIPostgreSQLGitHub ActionsDockerpytest

29

policy decision cases

33 ms

median overhead

52 ms

p95 overhead

137

automated tests

The problem

Once AI agents can call internal tools, someone has to decide which agent may call what, with which arguments, and keep a record nobody can quietly edit.

Architecture

  1. AI assistant
  2. Token check
  3. Policy decide()
  4. Approval (if required)
  5. Downstream tool
  6. Hash-chained audit

How it works

  • Deny-by-default scopes per client; a deny rule always beats an allow rule.
  • Approvals bound to the exact call (hash of the arguments), so an approval cannot be reused.
  • Every decision appended to a hash-chained audit log.
  • An evaluation regression gate fails CI when a prompt or model change makes any project worse.

Safety & reliability

  • DNS-rebinding protection kept on in production.
  • Downstream tool output wrapped and marked as untrusted data.

What I learned

The policy engine is a pure function, so 29 table-driven cases cover it completely and it decides in about 15 microseconds.