Hierarchical MCP Gateways: Zero-Trust Proxy
Design and deploy hierarchical Zero-Trust MCP Gateways to enforce role-based access control (RBAC), rate limits, and DLP redactions across enterprise agents.
Generate & Validate Multi-Client MCP Config
One-click export with environment variables & path locators for Claude Desktop, Cursor, Windsurf, and OpenAI Codex CLI.
Hierarchical MCP Gateways: Zero-Trust Proxy
Direct, unmediated connections between AI agent clients and sensitive backend systems represent an unacceptable enterprise risk. An unconstrained autonomous agent with a PostgreSQL MCP connection can inadvertently run destructive DDL statements, expose PII in training contexts, or exhaust database connection pools.
To solve this, enterprise security architectures employ Hierarchical Zero-Trust MCP Gateways.
A Zero-Trust MCP Gateway sits between client hosts (Claude Desktop, Cursor, internal agent fleets) and upstream MCP servers. It intercepts all JSON-RPC 2.0 frames, authenticates agent identity via mTLS/OIDC, enforces Role-Based Access Control (RBAC), masks sensitive parameters, and redacts PII before payload returns to the model context.
1. Gateway Architecture & Inspection Pipeline
┌────────────────────────────────────────────────────────┐
│ AI AGENT CLIENTS │
│ Developer Claude, Internal Slackbots, Batch SRE │
└──────────────────────────┬─────────────────────────────┘
│ mTLS / Bearer JWT
▼
┌────────────────────────────────────────────────────────┐
│ ZERO-TRUST MCP GATEWAY (ENVOY) │
├────────────────────────────────────────────────────────┤
│ 1. OIDC / SAML Identity Verification │
│ 2. Tool-Level RBAC Policy (Allow/Deny Matrix) │
│ 3. SQL / Command Sanitizer (Block DROP, TRUNCATE, RM) │
│ 4. DLP Engine (Regex Redact SSN, API Keys, Credit Card)│
│ 5. Rate Limiter (Token Bucket per Agent ID) │
└──────────────────────────┬─────────────────────────────┘
│ Verified Internal RPC
┌───────────────────┼───────────────────┐
▼ ▼ ▼
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Upstream MCP │ │ Upstream MCP │ │ Upstream MCP │
│ Production DB│ │ AWS Cloud │ │ Internal HR │
└──────────────┘ └──────────────┘ └──────────────┘2. Policy Definition Schema
Enterprise gateways enforce declarative access control policies defined in YAML:
# mcp-gateway-policy.yaml
version: "2026.1"
policies:
- role: "junior-developer-agent"
allowed_servers:
- "postgres-staging"
- "github-readonly"
tool_rules:
- server: "postgres-staging"
action: "allow"
tool: "query"
constraints:
disallowed_keywords: ["DROP", "ALTER", "TRUNCATE", "DELETE", "GRANT"]
max_row_limit: 100
- server: "postgres-staging"
action: "deny"
tool: "execute_ddl"
- role: "sre-incident-agent"
allowed_servers:
- "postgres-prod-readonly"
- "datadog-mcp"
- "k8s-mcp"
dlp_rules:
mask_fields: ["email", "password_hash", "credit_card", "ssn"]
action: "replace_with_hash"3. Implementing Gateway Proxy Middleware in TypeScript
Here is a lightweight Node.js/Cloudflare Workers proxy implementation verifying MCP tool calls against security policies:
// mcp_zero_trust_proxy.ts
import { Request, Response } from "express";
interface JsonRpcRequest {
jsonrpc: string;
id: string | number;
method: string;
params?: any;
}
const FORBIDDEN_SQL_PATTERNS = [/drop\s+table/i, /truncate\s+table/i, /delete\s+from/i];
export async function handleMcpProxy(req: Request, res: Response) {
const agentRole = req.headers["x-agent-role"] as string;
const rpcBody: JsonRpcRequest = req.body;
// Intercept tools/call execution
if (rpcBody.method === "tools/call") {
const { name, arguments: args } = rpcBody.params || {};
// 1. RBAC check
if (agentRole === "junior-developer" && name.includes("admin")) {
return res.status(403).json({
jsonrpc: "2.0",
id: rpcBody.id,
error: { code: -32001, message: "Policy Denied: Role lacks administrative tool permissions." }
});
}
// 2. SQL injection and destructive keyword check
if (args?.sql) {
for (const pattern of FORBIDDEN_SQL_PATTERNS) {
if (pattern.test(args.sql)) {
return res.status(400).json({
jsonrpc: "2.0",
id: rpcBody.id,
error: { code: -32002, message: "Security Violation: Destructive query keywords rejected by Gateway." }
});
}
}
}
}
// 3. Forward verified request to upstream MCP server
const upstreamRes = await forwardToUpstream(rpcBody);
// 4. Data Loss Prevention (DLP): Redact sensitive data in return payloads
const sanitizedRes = redactSensitiveData(upstreamRes);
return res.json(sanitizedRes);
}
function redactSensitiveData(data: any): any {
let str = JSON.stringify(data);
// Redact API keys and secrets
str = str.replace(/ghp_[a-zA-Z0-9]{36}/g, "[REDACTED_GITHUB_TOKEN]");
str = str.replace(/sntrys_[a-zA-Z0-9]{40}/g, "[REDACTED_SENTRY_TOKEN]");
return JSON.parse(str);
}
async function forwardToUpstream(body: any) {
// Upstream fetch logic here...
return { jsonrpc: "2.0", id: body.id, result: { content: [{ type: "text", text: "Safe query result" }] } };
}4. SOC 2 and Audit Logging
Every intercepted frame generates a structured audit log containing:
- ▸
timestamp: ISO-8601 UTC string. - ▸
agent_identity: OIDC subject claim. - ▸
tool_name: Invoked MCP tool. - ▸
arguments_digest: SHA-256 hash of tool parameters. - ▸
policy_decision:ALLOWorDENY.
By routing autonomous agent traffic through Hierarchical Gateways, organizations achieve SOC 2 and ISO 27001 compliance while granting developers full access to modern MCP capabilities.
Build your full agent toolstack in the Visual Generator
Combine Hierarchical MCP Gateways: Zero-Trust Proxy with databases, search APIs, and memory graphs in a single configuration file.
Did this setup guide work with your AI host?
Real-time developer votes ensure configurations stay current across client updates.
Hierarchical MCP Gateways: Zero-Trust Proxy FAQ
What is the Hierarchical MCP Gateways: Zero-Trust Proxy?
Design and deploy hierarchical Zero-Trust MCP Gateways to enforce role-based access control (RBAC), rate limits, and DLP redactions across enterprise agents.
How do I configure Hierarchical MCP Gateways: Zero-Trust Proxy in Claude Desktop or Cursor?
You can copy the configuration JSON from our guide or launch the interactive MCP Codex Config Generator at https://mcp-codex.com/generator to export valid configs in 1 click.
Can I use Hierarchical MCP Gateways: Zero-Trust Proxy with the OpenAI Codex CLI?
Yes, OpenAI Codex CLI supports Model Context Protocol. You can add it directly to ~/.codex/config.toml or pass arguments to codex mcp add.
Specializing in Model Context Protocol (MCP) integrations, autonomous AI agent orchestration, and distributed developer toolchains. Researches and benchmarks production MCP client-server architectures across OpenAI Codex, Claude, and Cursor.
Related Guides
Speculative Tool Execution in MCP Runtimes
Accelerate autonomous agent loops by 3x using speculative pre-execution of Model Context Protocol tool calls and optimistic concurrency control.
EnterpriseA2A and MCP: Multi-Agent Protocol Federation
How the Agent-to-Agent (A2A) protocol and Model Context Protocol (MCP) combine into a unified, decentralized enterprise multi-agent architecture.
EnterpriseDevOps and Cloud SRE Tooling with Scoped MCP Agents
Building production DevOps and SRE tools with Model Context Protocol (MCP): Kubernetes cluster diagnosis, AWS CloudWatch log triage, and Terraform state inspection.