13 min read INS Security Team

Setting Up an MCP Security Gateway: Architecture and Deployment Guide

A security gateway is the most effective way to protect AI agents using Model Context Protocol. This guide covers the architectural decisions, deployment patterns, and configuration steps involved in deploying an MCP security gateway in production.

Model Context Protocol (MCP) is rapidly becoming the standard interface between AI agents and external tools. As of early 2026, thousands of organizations run MCP servers in production, connecting agents to databases, APIs, file systems, and cloud services. Most of these deployments have no security layer between the agent and the tools it accesses.

The risks are well-documented: tool poisoning, prompt injection through tool responses, data exfiltration, PII leakage, credential exposure, and unauthorized access. OWASP's Top 10 for Agentic Applications, published in early 2026, highlights many of these as critical vulnerabilities. Yet the MCP specification itself includes minimal security guidance -- it defines a protocol for tool interaction, not a framework for securing it.

An MCP security gateway fills this gap. It sits between AI agents (MCP clients) and MCP servers, inspecting every request and response in real time. This guide walks through the architecture, deployment options, and configuration of such a gateway, with specific guidance on using INS to get production-ready in hours rather than months.

Why a Gateway Architecture

There are fundamentally three approaches to securing MCP communications: embed security logic in the agent, embed it in the MCP server, or externalize it in a gateway. Each has trade-offs, but the gateway approach wins on almost every dimension that matters in production.

The Agent-Side Approach (and Why It Fails)

You could instruct the agent itself to validate tool responses, detect PII, and enforce access policies. The problem is that agents follow instructions -- including malicious ones. A prompt injection attack can instruct the agent to disable its own security checks. Agent-side security is fundamentally bypassable because the agent's behavior is determined by its prompt, and the prompt can be manipulated.

The Server-Side Approach (and Its Limitations)

You could implement security controls within each MCP server. This works for servers you control, but fails for third-party servers, open-source servers, and servers maintained by other teams. You also end up with fragmented security policies -- different servers implement different controls at different quality levels, and there is no centralized view of what is happening across your MCP infrastructure.

The Gateway Approach

A security gateway operates as a transparent proxy. Agents connect to the gateway instead of directly to MCP servers. The gateway forwards requests to the appropriate server, inspects both the request and the response, evaluates policies, and returns the result to the agent. Neither the agent nor the server needs to know the gateway exists -- the security layer is entirely transparent.

This provides several critical properties:

  • Tamper-proof: Security policies cannot be bypassed by prompt injection because they execute outside the agent's context.
  • Centralized: All MCP traffic passes through a single point where policies are enforced consistently.
  • Observable: Every tool call is logged and available for audit, forensics, and compliance.
  • Vendor-agnostic: Works with any MCP client and any MCP server without modification.

Core Architecture Components

A production MCP security gateway consists of several components working together. Understanding each component helps you make informed deployment decisions.

The Proxy Layer

The proxy layer handles MCP protocol translation and routing. It accepts connections from MCP clients, maintains connections to MCP servers, and routes tool calls to the correct server. For SSE-based MCP transports, this layer manages long-lived HTTP connections. For stdio-based transports, it manages subprocess communication. The proxy must add minimal latency -- every millisecond of delay in tool calls compounds across multi-step agent workflows.

The Security Engine

The security engine is the core of the gateway. It runs a pipeline of detectors against every request and response:

  • Prompt injection detection: Identifies instruction-like content in tool parameters and responses.
  • Tool poisoning detection: Scans tool descriptions for embedded malicious instructions.
  • PII detection: Identifies personally identifiable information across 13+ types (emails, SSNs, credit cards, phone numbers, etc.).
  • Secret detection: Catches leaked API keys, tokens, and credentials from 20+ platforms.
  • Data exfiltration detection: Identifies patterns suggesting data extraction across tool calls.
  • Rug pull detection: Compares tool descriptions against stored SHA-256 hashes to detect unauthorized changes.

In INS, the security engine runs these detectors in priority order -- prompt injection runs first because it represents the highest-risk threat. The engine is designed so detectors can be added, removed, or reordered without code changes.

The Policy Engine

The policy engine evaluates rules against each request to determine the action: allow, deny, require approval, log only, rate limit, or mask the response. Policies are defined as combinations of conditions that match on fields like agent identity, tool name, MCP server, time of day, day of week, and request parameters.

For example, a policy might specify: "If agent type is 'support-bot' and tool is 'delete_customer' and time is after 18:00, then require approval." This level of granularity is essential for production deployments where different agents have different risk profiles.

The Audit Pipeline

Every request that passes through the gateway generates an audit event containing the agent identity, tool called, parameters, response summary, policy decisions, and any threat detections. These events must be stored immutably for compliance and forensic analysis. INS records audit events asynchronously off the critical request path, so logging never adds latency to tool calls.

The Session Store

Session correlation requires maintaining state across multiple requests. The session store tracks active agent sessions, cumulative data access metrics, and behavioral baselines. This must be fast — every tool call queries the session store — so it should be optimized for sub-millisecond lookups that do not add meaningful latency to the request path.

Deployment Patterns

The right deployment pattern depends on your infrastructure, team size, and compliance requirements. Here are the three most common approaches.

Pattern 1: Centralized Gateway

All MCP traffic from all agents routes through a single gateway deployment. This is the simplest pattern and the right starting point for most organizations.

Agent A ──┐
Agent B ──┼──> [INS Gateway] ──┬──> MCP Server 1
Agent C ──┘                    ├──> MCP Server 2
                               └──> MCP Server 3

Pros: Single deployment to manage, centralized policy and audit, easy to monitor.
Cons: Single point of failure (mitigated with HA), potential bottleneck at scale.
Best for: Teams running fewer than 50 agents, initial deployments, compliance-focused organizations.

Pattern 2: Sidecar Gateway

Each agent gets its own gateway instance deployed as a sidecar container. This is the Kubernetes-native approach and provides the strongest isolation.

Pod 1: [Agent A + INS Sidecar] ──> MCP Servers
Pod 2: [Agent B + INS Sidecar] ──> MCP Servers
Pod 3: [Agent C + INS Sidecar] ──> MCP Servers

Pros: Per-agent isolation, no shared bottleneck, failure of one sidecar does not affect others.
Cons: Higher resource usage, distributed policy management, more complex monitoring.
Best for: Large-scale deployments, multi-tenant environments, organizations with strict isolation requirements.

Pattern 3: Regional Gateway Cluster

Multiple gateway instances behind a load balancer with shared state for sessions and audit storage. This provides high availability and horizontal scaling.

                    ┌──> [INS Instance 1] ──┐
Agents ──> [LB] ──> ├──> [INS Instance 2] ──┼──> MCP Servers
                    └──> [INS Instance 3] ──┘
                              │
                       [Shared State]

Pros: High availability, horizontal scaling, no single point of failure.
Cons: Requires shared state infrastructure, more complex deployment.
Best for: Production deployments with uptime requirements, organizations running 50+ agents.

Configuration Walkthrough

Getting a security gateway operational involves four configuration areas: MCP server registration, agent identity setup, policy definition, and monitoring integration.

Step 1: Register MCP Servers

Register each MCP server that your agents need to access. During registration, the gateway connects to the server, retrieves its tool list, and computes SHA-256 hashes of all tool descriptions. These hashes serve as the baseline for rug pull detection -- any future change to a tool description will be flagged.

POST /api/v1/mcp-servers
{
  "name": "Customer CRM",
  "url": "https://crm.internal:8443/mcp",
  "transport": "SSE",
  "description": "Customer relationship management tools",
  "tags": ["production", "customer-data"]
}

The gateway will automatically scan all tools on this server for poisoning patterns, tool shadowing (duplicate names across servers), and suspicious description content.

Step 2: Register Agent Identities

Each agent that connects through the gateway should have a registered identity. This identity determines what tools the agent can access, what rate limits apply, and what policies are evaluated.

POST /api/v1/agents
{
  "name": "Support Bot",
  "type": "support",
  "description": "Customer support automation agent",
  "permissions": ["crm:read", "tickets:read", "tickets:write"],
  "rateLimits": {
    "requestsPerMinute": 60,
    "requestsPerHour": 500
  }
}

Step 3: Define Security Policies

Policies are the rules that govern what agents can do. Start with broad deny-by-default policies and add specific allow rules for each agent-tool combination. A policy consists of conditions (what to match) and actions (what to do when matched).

POST /api/v1/policies
{
  "name": "Restrict production writes after hours",
  "description": "Require approval for write operations outside business hours",
  "rules": [
    {
      "conditions": [
        { "field": "tool", "operator": "contains", "value": "write" },
        { "field": "mcp_server", "operator": "equals", "value": "production-db" },
        { "field": "time", "operator": "not_in", "value": "09:00-18:00" }
      ],
      "action": "REQUIRE_APPROVAL"
    }
  ]
}

INS supports six policy actions: ALLOW, DENY, REQUIRE_APPROVAL, LOG_ONLY, RATE_LIMIT, and MASK_RESPONSE. Conditions can match on 14 different fields including tool name, agent identity, MCP server, time, day of week, and specific parameter values.

Step 4: Configure Monitoring

The gateway exposes Prometheus metrics at /actuator/prometheus for integration with your existing monitoring stack. Key metrics to track:

  • Request throughput: Total tool calls per second, broken down by agent and MCP server.
  • Threat detections: Count and type of threats detected, grouped by threat category.
  • Policy actions: How many requests are allowed, denied, rate-limited, etc.
  • Latency: Gateway processing time (p50, p95, p99) to ensure the security layer is not degrading agent performance.
  • Active sessions: Number of active agent sessions and their cumulative data volume.

INS also provides a built-in dashboard for real-time monitoring without requiring external tooling. The dashboard shows active threats, recent policy violations, agent activity, and audit logs with full drill-down capability.

Production Hardening Checklist

Before going live, ensure these items are addressed:

TLS everywhere: All connections between agents, gateway, and MCP servers should use TLS. The gateway should validate server certificates and optionally require client certificates for mutual TLS.
JWT authentication: Agents should authenticate to the gateway using JWTs signed with RS256 or ES256. Rotate signing keys regularly and validate token expiration on every request.
Rate limits configured: Set per-agent and per-tool rate limits based on expected usage patterns. Start conservative and loosen as you understand normal traffic patterns.
Audit log retention: Configure audit log retention based on your compliance requirements. Most regulations require 1-7 years. Ensure audit logs are stored in a tamper-evident manner.
Alerting configured: Set up alerts for high-severity threat detections, unusual agent behavior, and infrastructure issues (high latency, connection failures, disk full).
Failover tested: If using a clustered deployment, test failover by killing instances and verifying that traffic continues to flow. Decide on your fail-open vs. fail-closed policy -- if the gateway is unavailable, should agents be blocked (safer) or allowed to connect directly to MCP servers (more available)?
Deny-by-default policies: Start with a default-deny policy and explicitly allow specific agent-tool combinations. This ensures new tools or agents do not accidentally have unrestricted access.

Getting Started with INS

Building an MCP security gateway from scratch involves implementing protocol proxying, a threat detection engine, a policy evaluation system, session management, an audit pipeline, and a monitoring dashboard. For a small team, this is months of engineering work.

INS provides all of this as a ready-to-deploy solution. The gateway handles MCP protocol translation, runs 300+ detection patterns against every request and response, enforces policies with four configurable action types, correlates sessions in real time, and generates full audit logs. It deploys as a single container, integrates cleanly with your existing infrastructure, and exposes standard metrics for your monitoring stack.

The typical deployment path is: start with a centralized gateway in a staging environment, register your MCP servers, configure policies in log-only mode to understand traffic patterns, then gradually enable enforcement. Most teams go from first deployment to production enforcement in under a week.

Deploy Your MCP Security Gateway

INS is the fastest path to a production-ready MCP security gateway. Join the waitlist to get access to the platform, documentation, and deployment guides.

Join the Waitlist

Related Posts