MCP Gateway and MCP Security for AI Agents

An MCP gateway is a proxy between AI clients and the MCP servers they call. Formal's signs each user in, checks which servers and tools they can use, adds the credential you chose for that server and logs the call, for Claude, ChatGPT, Claude Code, Codex and Cursor.

sign-in · linear.gateway.acme.connectors.joinformal.comexample
AGENT  Claude Code: MCP request, no token
ERROR  401 Unauthorized, WWW-Authenticate: /.well-known/oauth-protected-resource
HUMAN  alice@example.com signs in to Formal and approves Claude Code
VERIFY access token bound to linear.gateway.acme.connectors.joinformal.com
INJECT Alice's linked Linear token, Formal token removed
ALLOW  tools/call forwarded to mcp.linear.app

The problem

Why do AI agents need an MCP gateway?

MCP is a connectivity protocol: it tells a model how to discover and call tools, which is how MCP differs from an API. As our CEO argued, it was never designed to be a security boundary. An MCP gateway moves MCP security onto the network path: identity, tool-level policy and a log in front of every server.

  1. Tokens that allow more than the task

    An agent with a GitHub or Linear token can call every tool that token allows, from whichever client the engineer installed. A token that can open a pull request can usually merge it too.

  2. The server sees the token, not the person

    Upstream tokens sit on laptops. The MCP server can't tell which employee started the agent, and the call leaves no record you control.

  3. Servers nobody approved

    An engineer can point an agent at any remote MCP server. Injected instructions in a tool result then reach every tool the agent is allowed to call.

today · no policy on the pathexample
01
claude-code · alicetools/call github.merge_pull_requestALLOWED
02
codex · token on alice-mbptools/call linear.create_issueALLOWED
03
cursor · leotools/call to an MCP server nobody approvedALLOWED

# Without a gateway, all three go through, and none is tied to a person.

Definition

What is an MCP gateway?

MCP gatewaynoun

An MCP gateway is a proxy between MCP clients (Claude, ChatGPT, Claude Code, Codex, Cursor) and the MCP servers they call. Clients connect to the gateway instead of the server. The gateway checks who is calling, decides whether each tool call is allowed, adds the credential the server expects and logs the call. You’ll also see it called an MCP proxy or MCP firewall.
  • On the Connector in your VPC

    In Formal, the MCP gateway runs on the Connector, the reverse proxy you deploy in your VPC. Each server you add to the Catalog gets its own address, such as https://linear.<connector-hostname>/mcp, so every tool call passes one control point.

  • Policies see MCP, not HTTPS

    Policies see the MCP method, the tool name and its parameters rather than an HTTPS request to a host.

  • Laptops keep the original URL

    On laptops, a network rule lets the Formal Endpoint forward MCP traffic from AI agents to the same gateway and add the user’s identity, so people keep the server’s original URL.

  • Every remote server, wherever the client runs

    The gateway covers every remote MCP server your clients reach over HTTPS, from a vendor’s cloud or from a laptop.

How it works

How the MCP gateway works

Four steps from a Connector to tool calls under policy. The MCP gateway docs cover each one.

  1. Step 1 of 4

    Add an MCP listener

    Create a listener on the Connector with a technology rule set to MCP, and a hostname whose DNS and TLS certificate cover every subdomain.

    CONNECTOR LISTENERexample
    • technology rule: MCP✓
    • DNS covers every subdomain✓
    • TLS certificate covers every subdomain✓
  2. Step 2 of 4

    Add servers to the Catalog

    Pick a template such as Linear or Notion, or enter a custom URL. Choose how Formal authenticates upstream: linked accounts, shared credentials or pass through.

    UPSTREAM AUTHENTICATIONexample
    • linear · templateLINKED ACCOUNTS
    • notion · templateSHARED CREDENTIAL
    • custom remote URLPASS THROUGH
  3. Step 3 of 4

    Connect clients

    Cloud apps such as Claude and ChatGPT use the server's Connector address; an admin adds each server once with Add to Claude or Add to ChatGPT. On a device running the Endpoint, clients keep the server's original URL.

    CLIENTSexample
    • Claude, ChatGPT: Connector address✓
    • Claude Code with the Endpoint: original URL✓
    • Codex without the Endpoint: Connector address✓
  4. Step 4 of 4

    Set access and review usage

    Choose who can use each server and which tools, add Rego policies where needed, and review every call in Logs and the server's Usage tab.

    TOOL CALLSexample
    • tools/call github.create_pull_requestALLOWED
    • tools/call github.merge_pull_requestBLOCKED
    • every call in Logs and UsageRECORDED

MCP security risks

What MCP security risks does a gateway address?

Most MCP server security problems come down to authentication and authorization: an agent acts with more access than the task needs, and nobody can say afterwards who asked for it. A gateway handles that access side. It doesn’t make a malicious server safe, and it doesn’t clean up what a tool returns. Protocol-level attacks such as confused deputy depend on how each server and OAuth proxy is built; the MCP specification’s security best practices cover them.

  • Over-broad tokens

    A GitHub token that can create pull requests can usually merge them too. A tool-level policy allows the PR and blocks the merge, the case our CISO walked through in the permission pitfall of MCP.

    Tool-level policy
  • Per-server authorization

    MCP authorization lets one server check its own OAuth tokens and scopes, but it can’t see what the same user does on other servers. The Connector is the OAuth protected resource for every Catalog server, so one set of tool-level rules and one log apply across them, while each server still checks its own upstream token.

    One rule set
  • Token passthrough

    The spec says a server must not accept tokens that weren’t issued for it. The Connector accepts only Formal tokens bound to that server’s address and removes them before the request goes upstream. Servers set to pass through forward the client’s own credential unchanged, and the upstream server validates it.

    Formal tokens only
  • Prompt injection through tool output

    A malicious issue, or a document a retrieval tool returns (RAG vs MCP compares the two paths), can tell the agent to call another tool. The injected instruction only reaches the tools the policy allows. The gateway doesn’t rewrite or mask the tool result: at the response stage, MCP policies can allow or encrypt it.

    Limited to allowed tools
  • Tool poisoning

    Instructions hidden in a tool’s description are a server problem the gateway can’t fix on the wire. The control is the Catalog: review a server before you add it, then allow only the tools the job needs.

    Catalog review
  • Tokens on laptops

    With linked accounts or shared credentials, the upstream credential stays with Formal.

    Held by Formal
  • Shadow MCP servers

    The Endpoint flags or blocks MCP servers outside your Catalog, the queue described on shadow AI detection.

    Flagged or blocked
  • No audit trail

    Every call through the gateway is logged with the user, server and tool.

    Every call logged

None of this applies to local MCP servers that run over stdio: their traffic stays on the laptop.

Authentication

MCP authentication and authorization: how do clients sign in?

Authentication happens on two sides, configured separately. Downstream, the client proves to the Connector who the user is. Upstream, the Connector sends the MCP server the credential it expects. Formal uses the downstream identity for policies, logs and picking the upstream credential.

Downstream

Every tool call carries a Formal identity

With Formal OAuth, the Connector acts as an OAuth protected resource, as the MCP authorization specification describes, and clients get a short-lived token bound to that server’s address. On a device, the Endpoint adds the identity in headers instead, so users keep the original server URL.

  • Formal OAuth: public clients that use PKCE S256 and a Client ID Metadata Document; the Connector validates tokens offline and removes them before the request goes upstream
  • Identity headers: a Formal-signed user token added by the Endpoint. Formal OAuth doesn’t support Dynamic Client Registration, so DCR-only clients go through the Endpoint instead
  • OAuth clients: policies can check which OAuth client is acting, for example to allow only clients you pre-registered
MCP gateway docs ›
connector · linearexample
claude for aliceFormal OAuth token bound to this serverALLOWED
claude-code for alice · EndpointFormal-signed identity headersALLOWED
codex · no tokentools/call linear.create_issueBLOCKED
Upstream

Upstream tokens stay off devices

You pick one of three options per server. With linked accounts or shared credentials, the Connector adds the credential to the request and users never see it.

  • Linked accounts: each user links their own account once. Formal stores the OAuth token encrypted and refreshes it when the server supports refresh
  • Shared credentials: one API key or service account token, stored as a native user. Selection rules can send different credentials to different people
  • Pass through: the client’s own credential goes upstream unchanged, so Formal can attribute the call only when it comes through the Endpoint. These servers get no Connector address
MCP resources docs ›
connector · upstreamexample
alice to linearAlice's linked OAuth tokenTOKEN INJECTED
alice to notionshared credential from a native userTOKEN INJECTED
alice to custom serverclient credential passed throughALLOWED

Tool-level access control

How do you control which MCP tools each person can call?

Each Catalog server’s Access Controls set who can use it and which tools they can call, and Formal saves them as a policy named MCP access controls: <server-name>. The Connector blocks requests from anyone outside the allowed users and groups, and blocks tools/call for tools outside the list. Clients may still list those tools, but calls fail with the block message.

  • Allow everyone, specific users and groups, or no one
  • Allow all tools or a selected list, filtered by each server’s read-only and destructive hints
  • For finer rules, write Rego on input.mcp.tool_name and input.mcp.tool_params, at the session, request and response stages
  • At the request stage, a policy can allow, block or rewrite the call before the server sees it
MCP policy docs ›
policy · githubrego
package formal.v2

import future.keywords.if

default request := {"action": "allow"}

request := {"action": "block", "type": "block_with_formal_message"} if {
  input.mcp.tool_name == "merge_pull_request"
}

Governance

MCP governance: approved servers, shadow MCP and access requests

MCP governance starts with a list of what’s approved. The Catalog is your private registry of MCP servers and skills, and it lives in the shared control plane with policies and logs.

Catalog and Access Requests

A private registry of approved MCP servers

Employees use the Catalog at catalog.formal.ai to browse servers, follow setup steps for their client, link accounts and request access. Access Requests close the loop: an employee asks for a new server, for access to one in the Catalog, or for an exception to a policy that blocked them, and an admin approves it in the Control Plane.

  • Exceptions: one-time, time-bound (30 minutes to 7 days) or permanent
  • Setup steps: each server’s page shows setup steps for over 40 clients, adjusted for whether the device runs the Endpoint
Catalog ›
catalog.formal.aiexample
mayabrowse approved servers: github, linear, notionALLOWED
mayaaccess to a server outside the CatalogREQUESTED
admintime-bound exception, 7 daysAPPROVED
Shadow MCP

Catch MCP servers that aren't in the Catalog

Servers outside the Catalog fall to Guardrails, which allow and log them for review, or block them with a list of approved alternatives. Only the Endpoint sees servers with no Formal Resource, so Guardrails apply on devices running it in Transparent Mode on macOS or Linux.

  • Shadow AI queue: unknown servers the Endpoint intercepted, refreshed every 15 minutes. Finding them in the first place is covered on shadow AI detection
  • Approved alternatives: a blocked agent receives the approved MCP servers and how to request the one it tried
Guardrails docs ›
endpoint · guardrails: unknown MCPs = blockexample
cursor for leotools/call to a server with no Formal ResourceBLOCKED
endpointapproved instead: github, linear, notion
shadow ai queueserver listed for reviewREVIEW

Clients and servers

Which MCP clients work with the gateway?

Cloud apps (Claude, ChatGPT, Dots, Cursor Cloud Agents, Grok Bot) and devices without the Endpoint call the server’s Connector address. On a device with the Formal Endpoint, clients keep the server’s original URL, such as https://mcp.linear.app/mcp. Claude and ChatGPT call MCP servers from Anthropic’s and OpenAI’s clouds, so the Connector’s listener must be reachable from the internet, and the Endpoint never sees those calls. Claude Code and Codex connect with claude mcp add or codex mcp add, and Cursor Cloud Agents take the Connector address as a custom MCP server. On the server side, the Catalog starts you with 80+ MCP server templates, such as GitHub, Linear, Notion, Slack and Sentry, and takes any custom remote server.

Client setup in the MCP gateway docs ›

Audit

MCP audit logging: what does each tool call record?

MCP audit logging

Know who called which tool, on which server

Every tool call through the gateway appears in Logs with the user, the server and the tool name. Each server’s Usage tab breaks requests down by tool and by user, and the MCPs page lists the tools agents call against the tools each server offers.

  • MCP observability: log integrations forward the same records to AWS S3, Google Cloud Storage, Azure Blob Storage, Datadog, Splunk or Panther, next to your other security data
Log integrations docs ›
logs · mcpexample
security@acme.com> technology = mcp, user = alice@example.com
clientservertooldecision
Claude Codelinearcreate_issueallow
Claude Codegithubcreate_pull_requestallow
Claude Codegithubmerge_pull_requestblock
3 rowsRECORDED

How it fits

Endpoint and Connector, configured from one Control Plane

The Formal Endpoint runs on laptops and Linux machines, the Connector runs in your VPC, and the Control Plane holds the policies, the Catalog and the logs for both. A tool call from Claude in Anthropic’s cloud and one from Claude Code on a laptop meet the same MCP policy and land in the same log. The same Endpoint, Connector and policies carry the rest of AI agent security, such as coding agents and cloud agents.

MCP gateway flow: Claude and ChatGPT call the MCP gateway on the Formal Connector, Claude Code and Codex reach it through Formal Endpoint, and the gateway checks identity, adds the upstream credential and logs every tool call to remote MCP servers.
Cloud apps and laptop agents reach remote MCP servers through one gateway.

MCP security best practices

MCP security best practices: what should you look for in an MCP gateway?

The questions we’d ask of any MCP gateway, ours included.

  1. Per-user identity on every call

    A shared service token can’t say who asked. Each call should name the person behind the agent.

  2. Tool-level authorization

    Allow or deny per server is too coarse. The check belongs on each tools/call.

  3. Upstream credentials kept off devices

    The proxy adds them after policy allows the call.

  4. Coverage for cloud apps and local agents

    Claude and ChatGPT call MCP servers from their vendors’ clouds, so a check that only runs on laptops never sees those calls.

  5. A path for unknown servers

    Discovery, a default action and an approval flow.

Deployment

An enterprise MCP gateway that uses the systems you already run

Runs in your environment today: your VPC, your devices, your cloud.

Formal Connector in your VPC

Linux on AMD64 or ARM64: AWS ECS Fargate behind a Network Load Balancer, or Helm on EKS, GKE, AKS or on-premises Kubernetes. In production, run 2 or more nodes behind a load balancer (deployment docs).

Formal Endpoint on laptops

Transparent Mode on macOS and Linux; roll it out to Macs with your MDM. Existing clients keep working without a base URL change (Endpoint docs).

AWS PrivateLink to the Control Plane

On AWS, the Connector can reach the Formal Control Plane over AWS VPC PrivateLink.

Your identity provider

People sign in with SSO, and SCIM keeps users and groups in sync. Policies use the groups you already manage.

Policy and configuration as code

Policies are written in Rego. Manage Formal with Terraform, Pulumi or the Kubernetes Operator.

Audited controls

Formal holds SOC 2 Type II and ISO/IEC 27001. The reports are on security.formal.ai.

In production

Technologies secured
10+
Resources secured
1,000+
Logs per week
40M+
Sessions per week
600K+
“We've limited the amount of data that those cloud agents can access and we're able to tie that back to the specific user who is using that cloud agent, which is a feature that I'm only aware of Formal having.”
Roy Xu
Roy Xu
Software Engineer, Security, Cursor
Read the Cursor story ›

FAQ

Questions about MCP gateways

Buying and fit

Do I need an MCP gateway?

You need one once agents call MCP servers with company credentials and you have to answer who called which tool. Without a gateway, each client holds its own token and each server sees only that token. A gateway is where MCP security controls live: identity, tool-level access and an audit trail.

What is the difference between an MCP server and an MCP gateway?

An MCP server exposes tools, such as GitHub’s or Linear’s. An MCP gateway sits in front of many servers and decides who may call which tool. The server enforces its own token scopes; the gateway adds the MCP security controls a single server can’t: per-user identity, tool-level policy and one audit log across servers.

What is the difference between an API gateway and an MCP gateway?

An API gateway typically matches HTTP routes on path, method and API key. MCP traffic sends every call to one endpoint as JSON-RPC. Since the 2026-07-28 spec, clients also copy the method and tool name into Mcp-Method and Mcp-Name headers, but the tool arguments stay in the body (MCP vs API covers what else differs). Formal treats MCP as its own resource technology and puts the method, tool name and parameters in the policy input.

Is MCP a security risk?

MCP itself is a protocol for discovering and calling tools. The risk is in what an agent reaches through it: a token broader than the task, a server nobody approved, or a tool result carrying injected instructions. MCP authentication in the spec lets each server check its own tokens; tying every call to a person across servers and keeping one log of it is what a gateway adds. The risk list above says where it helps and where it stops.

Is there an open source MCP gateway?

Yes. As of November 2026, several open source MCP gateways are published, some under the MIT license. Formal is a commercial, enterprise MCP gateway: you deploy the Connector in your own environment and manage servers, policies and logs from Formal’s Control Plane.

Does Formal work as an MCP registry?

As a private one. The Catalog holds only the MCP servers and skills you add, from a template or a custom URL (MCP vs skills covers how the two differ). The Catalog page covers templates, the employee view and access requests.

Product

Does the MCP gateway work with local stdio MCP servers?

No. A client starts a stdio server as its own subprocess and talks to it through stdin and stdout, so the traffic never reaches the network and the gateway doesn’t see it. To put those tools under policy, run the server remotely over HTTPS and add it to the Catalog as a custom server.

Govern every agent tool call

One MCP gateway for cloud apps and laptop agents, with per-user identity, tool-level policy and one audit log.