|Architecture

MCP Gateway vs MCP Server: Architecture, Security, and When You Need Each

An MCP server exposes tools. An MCP gateway controls how clients reach them. Compare architecture, auth, permissions, operations, and production tradeoffs.

Andrei
Founder of datamcp

The short answer

A Model Context Protocol (MCP) server exposes tools, resources, or prompts to an AI client. An MCP gateway adds a control layer around one or more MCP connections: authentication, access policy, credential isolation, routing, rate limits, and audit history.

They are not competing implementations of the same thing. A gateway does not remove the need for an MCP server. It controls how clients reach the server and how the server reaches production systems.

For a local experiment, a direct MCP server is usually enough. For a team connecting Cursor, Claude, ChatGPT, or VS Code to production databases and APIs, a gateway becomes useful because the operational problem is no longer just “can the model call this tool?” It is “which user can call which tool, against which backend, with what credentials, and how do we review what happened?”

This guide compares both architectures and gives you a practical decision framework.

MCP server vs MCP gateway at a glance

QuestionDirect MCP serverMCP gateway
Primary jobExpose tools and contextControl access to tools and backends
Typical scopeOne capability or backendMultiple clients, links, users, or sources
AuthenticationOptional; implementation-dependentCentralized per user, client, or link
PermissionsUsually enforced inside the server or backendExplicit policy before backend execution
SecretsOften supplied to the server processKept behind the gateway control plane
RevocationChange server config or backend credentialsDisable one user or MCP link
Audit trailBuild it into each serverCentral activity history
OperationsRun and update each serverOperate one managed access layer
Best fitLocal development and trusted single-user useTeams, shared systems, staging, and production

The important distinction is not local versus remote. MCP servers can run locally over stdio or remotely over Streamable HTTP. A remote MCP server can implement strong OAuth authorization by itself. A gateway is valuable when you want those controls to be consistent across clients, users, and backend connections rather than rebuilt separately for every server.

What an MCP server does

MCP follows a client-server architecture. An AI application acts as the host, creates an MCP client, and connects that client to an MCP server. The server publishes capabilities such as:

  • Tools the model can call, such as get_schema, run_query, or create_issue
  • Resources the client can read, such as documentation or database metadata
  • Prompts that provide reusable interaction templates

The protocol defines how the client discovers and invokes those capabilities. It does not prescribe your database role design, approval workflow, logging retention, or team access model.

MCP currently supports two standard transport patterns:

  1. stdio, where the client launches a local server process and exchanges JSON-RPC messages through standard input and output
  2. Streamable HTTP, where an independently running server accepts HTTP requests and can serve multiple clients

For a developer connecting a local AI editor to a disposable database, a stdio server is simple and effective. The client starts the process, the process reads credentials from its environment, and no shared infrastructure is required.

For a hosted SaaS integration, a remote MCP server is usually the natural choice. It can authenticate clients, handle many connections, and avoid installing a runtime on every developer machine.

What an MCP gateway adds

An MCP gateway sits on the request path between the client and the backend-facing tools. Depending on the implementation, it can provide the MCP endpoint itself or proxy existing MCP servers.

The request path looks like this:

AI client → authenticated MCP link → gateway policy → MCP tool → database or API

The gateway is responsible for the controls that become repetitive or risky when implemented independently for every connection.

Central authentication

The official MCP authorization specification defines OAuth-based authorization for HTTP transports. A remote server can implement that flow directly. The gateway approach centralizes it so every backend integration does not need a separate authorization implementation.

This matters when the same PostgreSQL database is used from Cursor, Claude, ChatGPT, and VS Code. Instead of distributing one shared credential, you can issue separate MCP links or user grants and revoke them independently.

Permission policy before execution

A backend credential answers one question: what can this database user or API token do?

A gateway policy can answer a narrower question: what should this AI client, user, or project be allowed to do through this connection?

For PostgreSQL, that may mean:

  • schema discovery plus SELECT only
  • read-write access to specific tables
  • blocking DDL and destructive statements
  • hiding sensitive tables from tool discovery
  • using a separate policy for staging and production

The database role should still enforce least privilege. Gateway policy is an additional boundary, not a replacement for backend security.

Credential isolation

A local server often receives the backend connection string through environment variables or client configuration. That can be acceptable for a single trusted machine, but it becomes difficult to manage across a team.

With a gateway, the AI client receives an MCP endpoint and its own authentication method. The PostgreSQL password or upstream API token stays encrypted on the server side. Revoking one client does not require rotating the backend credential for everyone else.

Central audit history

Production questions are rarely limited to “did the database execute a query?” You also need to know:

  • which MCP link initiated it
  • which user authorized the link
  • which tool was called
  • whether policy allowed or rejected it
  • how long execution took
  • which environment was targeted

Database logs remain valuable, but they usually do not contain the complete AI-client context. A gateway can record that context at the point where identity, policy, tool invocation, and backend execution meet.

Routing and lifecycle management

As the number of connections grows, the gateway can become the stable public endpoint while backend sources and policies change behind it. Teams can add a database, rotate an upstream token, disable a link, or move a service without rewriting every client configuration.

Three architectures compared

1. Local direct server

Cursor → local stdio MCP server → development PostgreSQL

Best for: one developer, local or disposable data, fast experimentation.

Advantages: minimal infrastructure, no network transport, easy to debug locally.

Tradeoffs: runtime and credentials live on the machine; team-wide revocation and centralized logs require additional work.

2. Remote direct server

Claude → remote Streamable HTTP MCP server → SaaS API

Best for: a product owner exposing one service and willing to build authorization, policy, hosting, observability, and upgrades into that server.

Advantages: no local process; one service can support many clients; OAuth can be implemented directly.

Tradeoffs: the server team owns the full production surface, including transport security, token validation, rate limiting, deployment, monitoring, and incident response.

3. Managed gateway

Cursor / Claude / ChatGPT / VS Code
                 ↓
       authenticated MCP links
                 ↓
      gateway policy and audit
                 ↓
         PostgreSQL or API

Best for: multiple clients or users, production data, explicit permissions, and teams that do not want to build an MCP control plane.

Advantages: centralized access, isolated credentials, separate policies, immediate revocation, and shared activity history.

Tradeoffs: another infrastructure dependency, gateway pricing, and the need to evaluate the provider's security and reliability.

When a direct MCP server is enough

Choose a direct server when most of these are true:

  • one person controls the client and backend
  • the data is local, synthetic, or easily restored
  • one permission level is sufficient
  • placing credentials on that machine is acceptable
  • server-level or database-level logs are enough
  • you are comfortable operating the process or hosted service

Do not add a gateway only because the term sounds more production-ready. Every layer has cost and failure modes. For a local database used by one developer, a gateway may add complexity without reducing meaningful risk.

When you need an MCP gateway

A gateway becomes the stronger choice when one or more of these conditions apply:

  • Production systems are involved. The blast radius of a leaked credential or incorrect tool call matters.
  • Multiple people need access. Each person needs independent authorization and revocation.
  • Multiple AI clients are used. Cursor, Claude, ChatGPT, and VS Code should not all share one database secret.
  • Permissions differ by project. One repository needs analytics tables while another needs a limited write workflow.
  • Auditability is required. Security or compliance teams need attribution beyond raw database logs.
  • Backend credentials cannot reach developer machines. Clients should receive scoped MCP access rather than direct database access.
  • You operate several integrations. Rebuilding auth, policy, logging, and deployment for every MCP server becomes its own platform project.

Build vs buy: the real checklist

Building a remote MCP server is straightforward. Building a reliable multi-user control plane around it is a different scope.

Before choosing self-hosting, estimate the work required for:

  1. Streamable HTTP transport and protocol upgrades
  2. OAuth discovery, token validation, PKCE, and refresh behavior
  3. origin validation and HTTP transport security
  4. encrypted backend credential storage
  5. per-user and per-client permissions
  6. query or API-operation validation
  7. rate limits and abuse protection
  8. structured audit events and retention
  9. monitoring, alerts, backups, and incident response
  10. admin UI for access changes and revocation

If you need only a trusted internal server, most of that list may be unnecessary. If you need controlled production access for a growing team, it is the actual product you must build and maintain.

For a deployment-focused comparison that includes managed hosting, remote self-hosting, local stdio, Streamable HTTP, offline access, configuration drift, and total operating cost, read MCP Server Hosting: Hosted vs Self-Hosted vs Local. If the terminology is the confusing part, the MCP proxy guide separates transport forwarding from the broader gateway control layer.

A practical PostgreSQL example

Imagine six developers use AI coding tools against the same production PostgreSQL database.

With direct local servers, each machine needs a connection string. If one developer leaves, you must know which credentials were copied where and rotate anything shared. If Cursor executes a query, the database may record the role but not the person, editor, MCP link, or policy decision behind it.

With a gateway, PostgreSQL is connected once. You create separate read-only links for developers, a narrower link for an analytics project, and a temporary write-enabled link for a migration workflow. Each can be disabled without changing the database password used by the others.

That is the core gateway value: not “MCP, but more enterprise.” It is a smaller, attributable access path between an AI client and a backend that was never designed to trust autonomous tool calls.

How datamcp approaches the gateway layer

datamcp is a hosted Model Context Protocol gateway for PostgreSQL 12+, MySQL, and OpenAPI 3.x. You connect a supported backend once, then create separate remote HTTPS MCP links with their own client authentication and source-specific access policies.

The client gets a remote MCP URL. Backend credentials stay encrypted server-side. The gateway discovers schema or API operations and checks the link's permissions before execution. PostgreSQL and MySQL query activity is available for review; OpenAPI endpoint calls do not currently appear in the datamcp activity log.

Start with the secure MCP gateway product page, evaluate hosted PostgreSQL MCP or hosted MySQL MCP, or connect a client through the Cursor, Claude, ChatGPT, or VS Code integration guide. For shared project context instead of backend tools, use the separate hosted MCP memory server workflow.

The free tier supports one connection and one MCP link, which is enough to test the architecture with read-only access before expanding it to a team.

Final decision

Use a direct MCP server when the environment is trusted, the scope is small, and you are comfortable managing credentials and operations yourself.

Use an MCP gateway when identity, permissions, revocation, credential isolation, and auditability must remain consistent across users and AI clients.

The server makes a capability available. The gateway makes access to that capability governable.

For the protocol details behind this distinction, see the official MCP architecture overview, transport specification, and authorization specification.

MCPMCP gatewayAI toolsPostgreSQLsecurity

Ready to connect an AI client?

Create a hosted MCP link for a supported PostgreSQL, MySQL, or OpenAPI source.

Create MCP link

Questions? Read the docs or view pricing.