← Back to Learn
mcp-safetyreferencedeployment

MCP gateway vs direct MCP connection

Authensor

When connecting an AI agent to MCP servers, you have two options: connect directly or route through a gateway. Each approach has different security, performance, and operational characteristics.

Direct connection

The agent connects directly to each MCP server:

Agent → MCP Server A (filesystem)
Agent → MCP Server B (database)
Agent → MCP Server C (web search)

Advantages:

  • Simpler architecture (fewer moving parts)
  • Lower latency (no proxy hop)
  • Easier local development

Disadvantages:

  • No centralized policy enforcement
  • No content scanning on tool calls
  • No audit trail (unless each server implements its own)
  • No approval workflows
  • Cannot inspect or modify traffic between agent and server
  • Each server must implement its own security

Gateway connection

The agent connects to the gateway, which connects to the MCP servers:

Agent → MCP Gateway → MCP Server A
                    → MCP Server B
                    → MCP Server C

Advantages:

  • Centralized policy enforcement on all tool calls
  • Content scanning on both requests and responses
  • Hash-chained audit trail across all servers
  • Approval workflows for escalated actions
  • Behavioral monitoring across all tool usage
  • Tool description validation
  • Single point for credential management

Disadvantages:

  • Additional infrastructure to deploy and maintain
  • Small latency increase per tool call (typically under 5ms)
  • Single point of failure (mitigated with redundancy)

When to use which

Use direct connections when:

  • You are in local development
  • The agent only connects to one trusted MCP server
  • Latency is critical and every millisecond matters
  • You implement safety at the application level using the SDK

Use a gateway when:

  • The agent connects to multiple MCP servers
  • You need centralized policy enforcement
  • You need compliance-grade audit trails
  • You use third-party or community MCP servers
  • You need to scan tool descriptions for injection
  • Multiple agents share the same MCP servers

Hybrid approach

Use the SDK for application-level safety and the gateway for infrastructure-level safety:

// Application level: SDK guard
const guard = createGuard({ policy: applicationPolicy });

// Infrastructure level: route through gateway
const mcpConfig = {
  servers: {
    gateway: { url: 'sse://gateway.internal:3000' }
  }
};

The SDK enforces application-specific rules. The gateway enforces organization-wide rules. Both generate receipts that form a complete audit trail.

Performance

The gateway adds one proxy hop per tool call. In practice, this is 1-5ms of additional latency. For most agent workloads, LLM inference takes 500ms to 5 seconds. An additional 5ms is negligible.

If latency is critical, co-locate the gateway with the agent on the same machine or in the same data center. The policy engine runs in microseconds; the latency is primarily network overhead.

Keep learning

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

View All Guides