All posts
3 min read

How Mont Works: A Fail-Closed Firewall for AI Agent Traffic

An architecture tour of Mont: how every REST and MCP tool call from an AI agent is evaluated against route and payload rules and decided ALLOW, REQUIRE_APPROVAL or BLOCK — all on your own infrastructure.

#architecture#mcp#ai-agents#security

Autonomous AI agents — LLM tool-calling agents, MCP clients, workflow bots — can call production APIs in loops, issue refunds or delete data without anyone watching. Mont is a control point that sits in front of those APIs. This post walks through how it is put together.

The core idea: every request gets a decision

Mont evaluates each agent request against route and payload rules — method, path and the request body — and makes one of three decisions:

Decision Behavior
ALLOW Forwarded to your API (and logged).
REQUIRE_APPROVAL Held until a human approves (expires after 24 h).
BLOCK Refused with 403 and logged.

There are also two dry-run modes, SHADOW_BLOCK and SHADOW_APPROVAL, which forward the request but log what the rule would have done, so you can test rules on live traffic.

Fail-closed by default

Mont is default deny: a request that matches no rule is blocked. The same applies to MCP — tools you haven't listed are blocked.

Three ways to deploy

Mont ships as one npm package, agent-gateway-sdk, and runs in three modes.

1. Express middleware

If your API is already an Express app, mount the gateway in front of your routes:

ts
import express from "express";
import { createAgentGateway } from "agent-gateway-sdk";

const app = express();
const gateway = createAgentGateway({ port: 3000 });
await gateway.ready;                                // database open and migrated

app.use(gateway.discoveryRouter);                   // GET /.well-known/agent.json
app.use(gateway.approvalCallbackRouter);            // signed Approve / Reject links
app.use("/api/agent-admin", gateway.adminRouter);   // admin API (mount BEFORE the gateway)
app.use("/api", gateway.agentGateway);              // the firewall

Two details matter: await gateway.ready before serving, and mount adminRouter before agentGateway.

2. Standalone no-code reverse proxy

For any backend, in any language, run Mont as a proxy:

bash
npx agent-gateway-sdk start --target https://api.mystore.com
# agents call      http://127.0.0.1:8080/api/...
# admin console    http://127.0.0.1:3000/agent-admin/

The agent-facing listener defaults to port 8080. The admin console listens on 127.0.0.1:3000 by default.

3. MCP proxy

Mont governs MCP tools/call requests over stdio, Streamable HTTP and legacy HTTP+SSE, using the same rules and approval flow as HTTP traffic:

bash
# stdio: use this as the server "command" in your MCP client config
npx agent-gateway-sdk mcp-stdio --data-dir ~/.mont -- npx -y @modelcontextprotocol/server-filesystem /data

# Streamable HTTP in front of a remote MCP server
npx agent-gateway-sdk mcp-http --upstream http://127.0.0.1:9000/mcp

MCP tool rules use the pseudo-method MCP, for example MCP /api/mcp/tools/refund_order.

Human-in-the-loop approvals

When a rule says REQUIRE_APPROVAL, the request is held and a human decides:

  • Zero-Tunnel phone approvals — approve or deny from Telegram inline buttons (outbound long-polling) or Slack Socket Mode. No public URL, ngrok or open port.
  • Edit & Approve — patch a held request's payload (for example, a refund amount) before approving it. The rule is re-checked against the edited payload.

Guardrails against runaway agents

  • Rate limits and duplicate-action protection stop agents that get stuck in loops.
  • Spending budgets cap the total an agent can move on its own, globally or per agent.
  • Emergency Lockdown is one switch that refuses every agent request; Approval-only mode holds every write.

A tamper-evident audit ledger

Every request is logged to an audit trail whose rows are SHA-256 hash-chained. Any edit, deletion, insertion or truncation breaks the chain and is detectable.

Storage: one embedded SQLite file

All state — rules, approvals, audit logs — lives in an embedded SQLite (WAL) database. There is no Redis, Postgres or cloud account to run, and Mont sends no telemetry. Licenses are offline Ed25519 keys, so nothing phones home.

Multi-tenant workspaces

Each client or project can get its own isolated workspace, with its own rules, budgets, upstream URL, emergency switch, approval chat and mws_… API key.

Running it in production

Terminate TLS at Nginx or Cloudflare, forward to Mont's agent-facing port on localhost, and set TRUST_PROXY=true (only behind exactly one reverse proxy). Keep the admin listener on a private interface.

nginx
location / {
  proxy_pass http://127.0.0.1:8080;
  proxy_set_header Host $host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header X-Forwarded-Proto $scheme;
}

Mont needs Node.js 20.17+ or Docker (docker compose up -d).