← Back to Learn
mcp-safetyexplainerguardrails

What is an MCP gateway?

Authensor

An MCP gateway is a proxy server that mediates all communication between an AI agent and the MCP (Model Context Protocol) servers it connects to. Instead of the agent talking directly to tool servers, every request passes through the gateway where it is evaluated against safety policies.

The problem with direct MCP connections

MCP lets AI agents discover and call tools from external servers. A filesystem MCP server exposes file read/write tools. A database MCP server exposes query tools. When an agent connects directly, it can call any tool the server exposes with any arguments.

This creates risk:

  • A compromised MCP server could expose dangerous tools
  • A prompt injection could cause the agent to misuse legitimate tools
  • There is no log of what tools were called or with what arguments
  • There is no way to require approval for specific operations

What a gateway adds

The gateway runs as an MCP server itself. You point your agent at the gateway, and the gateway connects to the upstream MCP servers on the agent's behalf.

Agent → MCP Gateway → [Policy Check] → Upstream MCP Server
                    → [Content Scan]
                    → [Audit Log]

On every tool call, the gateway:

  1. Scans the arguments for prompt injection and content threats
  2. Evaluates the call against your YAML policy
  3. Forwards allowed calls to the upstream server
  4. Blocks or escalates calls that violate policy
  5. Scans the response before returning it to the agent
  6. Generates a hash-chained receipt

Gateway vs application-level guards

You can also enforce policies in your application code using the SDK. The gateway approach has different tradeoffs:

Gateway advantages: Works with any MCP client without code changes. One enforcement point covers all connected agents. Easy to deploy as infrastructure.

SDK advantages: More control over escalation handling. Lower latency (no extra network hop). Can access application context.

In many deployments, both are used together. The gateway provides a baseline, and the SDK adds application-specific rules.

Tool discovery

The gateway exposes the same tools as the upstream servers. Tool discovery (the listTools call) passes through unchanged. The agent sees the full tool catalog. Filtering happens at call time, not discovery time.

This is a deliberate design choice. If the agent cannot see a tool, it cannot explain to the user why an action is not available. By letting the agent see all tools but blocking calls that violate policy, the agent can provide useful error messages.

Deploying a gateway

The Authensor MCP gateway supports stdio and SSE transports. For production, run it as a persistent service and configure your agents to connect to it instead of directly to upstream servers. See the setup guide for instructions.

Keep learning

Explore more guides on AI agent safety, prompt injection, and building secure systems.

View All Guides