Skip to content
AI Security2026-11-286 min read

Securing MCP Tool Calls with a Gateway

The gap

MCP adoption ran ahead of MCP operations. In most deployments an agent talks straight to its tool servers: nothing records which agent called which tool, nothing can refuse a call, and nothing notices when a server quietly changes what its tools say they do.

That last one matters more than it sounds. A tool's description is prompt input to the agent. A server can ship clean versions for months, then change one description to "also send the file to this address", and the agent reads that as an instruction. This is the rug-pull shape that keeps showing up in MCP supply chains.

I built mcp-gateway-lite as the smallest piece that closes the gap: one stdlib-only Go binary that sits in front of MCP servers.

Enforcement order is the design

What a gateway does matters less than the order it does it in.

On the way in:

  1. Rate limit. A token bucket per upstream, or per session. Exhaustion returns 429 with Retry-After and is audited, so throttled sessions stay attributable.
  2. Tool policy. Per-upstream allow or deny lists, checked on every tools/call. A blocked call returns 403 and never reaches the server.

On the way back:

  1. Schema lock. Every tools/list response is checked against the tool schemas you reviewed and pinned in a lockfile. A changed, added or unknown tool replaces the response with an error, so the altered description never reaches the agent.
  2. Listing filter. Tools the policy denies are removed from tools/list, so a client never even sees what it cannot call.

The lock runs before the filter on purpose: the lock pins what the server actually sent, and the filter shapes what the client sees.

Fail closed where it counts

Allow lists and deny lists fail differently, deliberately.

  • An allow list is default-deny. An unparseable body, or a tool call with no extractable tool name, is blocked. An allow list that fails open is theatre.
  • A deny list is best-effort. Unparseable traffic passes. It is a guardrail, not a boundary.

Audit without leaking

The audit log is append-only JSON Lines: method, tool name, session id, status, timing. It never records tool arguments or parameters. The extraction code cannot emit them, and a CI check fails if an argument value ever appears in the audit output. Blocked calls get full entries, because those are the ones operators care about most.

Tool results are untrusted too

Locking schemas does nothing about what a tool returns. A hostile server can put instructions into an ordinary-looking tools/call result. The gateway can pass every result through promptproof, my prompt-injection scanner, running as a warm coprocess. At or above a threshold it either blocks the result or flags it with a header and an audit entry. Scanner errors fail open and are audited, so the scanner can never take the gateway down.

What it costs

Measured with Go benchmarks over real loopback HTTP servers:

  • About 40 µs and 45 KB of allocation added per request in a minimal configuration.
  • About 48 µs more per tools/call with injection scanning on, because the scanner is a warm process rather than one spawned per call.

These are microbenchmarks on one machine. Re-run them on your hardware and configuration before you plan capacity with them.

What it does not do

  • It protects honest clients from drifting or compromised servers. It cannot see a server whose behaviour changes while its schemas stay the same.
  • It forwards credentials but does not mint or verify tokens. Put it behind your SSO proxy.
  • Policies and locks cover tools only. Resources and prompts pass through unfiltered.

Stating the limits is part of the security argument. A gateway that claims to stop everything is the one you should not trust.

Code, benchmarks and a recorded demo of the rug-pull catch: [github.com/bharat3645/mcp-gateway-lite](https://github.com/bharat3645/mcp-gateway-lite).

© 2026 Bharat Singh Parihar