Skip to main content

Comparison

db-mcp-gateway next to the other ways an AI agent gets at a database: handing it a connection string, a hand-written MCP wrapper, an off-the-shelf MCP database server, and an infrastructure access gateway. Statements about other products describe their general shape as of writing; check their current docs before deciding on them.


Positioning​

db-mcp-gateway is an MCP server that holds the database credentials and puts SSO identity, per-group grants and a synchronous audit row in front of every tool call. It is not a connection pooler, not a SQL proxy, and not a general access platform.

db-mcp-gatewayConnection string in the agentMCP database server / toolboxAccess gateway (session broker)
Credential on the developer's machineNoneYesUsually yes (DSN in the client's config), unless you host it centrallyNo (brokered)
Interface the agent seesMCP toolsDriver / CLIMCP toolsDatabase wire protocol
Identity on each querySSO user or service:<name>The shared DB roleUsually the server's DB roleSSO user per session
Per-query audit row before the resultYes, synchronousNoDepends; usually logs at bestSession/query recording, varies by product
Read-only by defaultYes (role + read-only transaction + statement guard)Only if the role isVaries (some run reads in a read-only transaction)Only if the role is

vs a connection string in the agent​

# The credential now lives on a laptop, in shell history and in the agent's context
DATABASE_URL="postgres://user:password@prod-db:5432/app"
# No credential on the laptop; the first call triggers browser SSO
claude mcp add --transport http db-gateway https://db.internal.acme.com/mcp
AspectConnection stringdb-mcp-gateway
Credential exposureHigh: laptops, logs, agent contextNone: the gateway holds it
AttributionThe shared roleEach SSO user, per call
Audit trailWhatever the database logsOne audit_calls row per call, committed before the response
Revoking one personRotate the shared password, redistribute it to everyone elseRemove them from the IdP group, or revoke-sessions; replicas converge within SESSION_CACHE_TTL_SECONDS (30 s), grant changes within PERMISSIONS_CACHE_TTL_SECONDS (60 s) at worst
SetupMinutesHours: deploy, IdP app, roles, permissions
LatencyDirectOne extra hop plus two synchronous audit writes — measured

Pick the connection string for personal or throwaway databases where nobody needs to know who ran what. Pick the gateway when the database matters and the agent should never hold its credential.


vs a hand-written MCP wrapper​

A wrapper is quick to write:

@app.post("/query")
async def run_query(sql: str):
return await database.execute(sql)

What it costs depends on how much of the following you end up rebuilding — we have not measured it and will not publish a number:

CapabilityCustom wrapperdb-mcp-gateway
OIDC login + session handling + MCP OAuthYou build and maintain itShips
Per-query identity in an audit rowYou build and maintain itShips
Read-only enforcement that survives a clever queryYou build and maintain itShips
Statement timeouts, row caps, cancellation on disconnectYou build and maintain itShips
A second database engineRebuild per engineAdd a servers: entry (Postgres, YugabyteDB, MongoDB, Redis-protocol)
Keeping all of the above correct as agents changeYoursUpstream's

If none of those rows matter to you, a wrapper may be cheaper — evaluate it.


vs MCP database servers and toolboxes​

There are many MCP servers that expose a database to an agent: per-engine servers (the original reference Postgres server, community MySQL / Mongo / Redis servers), multi-database servers such as DBHub, and configurable toolboxes such as Google's MCP Toolbox for Databases, where an operator declares parameterised SQL tools in a file.

They solve "give the agent tools for this database". The usual shape is a process the developer runs locally (stdio) with a DSN in its config, or a shared server running as one database role. What they typically leave to you:

ConcernTypical MCP DB server / toolboxdb-mcp-gateway
Where the credential livesClient config or the server's envOnly the gateway, never in a response, log or error
Who the caller isThe process; sometimes an auth layer you addSSO user via OIDC, or a named service token
Per-group, per-database permissionsUsually none, or tool-levelgroup × server × database × action grants with constraints
AuditOptional loggingSynchronous audit row per call; failed audit write fails the call
Free-form SQL vs fixed toolsVaries — toolboxes favour predeclared queriesFree-form run_query behind grants, plus fixed introspection tools

A toolbox of predeclared queries is a narrower blast radius than free-form SQL. If the questions your agents ask are known in advance, that is a real advantage; you can also run such a toolbox behind your own auth. The gateway is for when engineers need ad-hoc debugging queries and you need to know who ran each one.


vs infrastructure access gateways​

Teleport (database access), StrongDM, HashiCorp Boundary and similar products broker human (and machine) access to databases: SSO login, short-lived or injected credentials, session recording and, in some products, query-level logs. They speak the database wire protocol, so psql and drivers work through them.

ConcernAccess gatewaydb-mcp-gateway
InterfaceDB wire protocol (any client)MCP tools only
ScopeServers, Kubernetes, databases, moreDatabases for AI agents, nothing else
Agent-specific limits (row caps, result-size caps, reason_required, statement guard)Generally notBuilt in
Audit granularitySession and, depending on product, queryOne row per tool call, with reason, row count and outcome
OperationsA platform to run (or buy)One container + one Postgres
CostCommercial tiers for most enterprise featuresOpen source (MIT)

If you already run one of these for humans, it is a good way to give the gateway its network path to the databases. They complement each other: the access gateway governs connections, db-mcp-gateway governs what an agent may run and records it. Some access gateways have started adding MCP-facing features; compare those directly against the table above.


Not the same layer: poolers and data governance​

  • Connection poolers (PgBouncer, pgcat, ProxySQL, RDS Proxy) reduce connection count. They do not authenticate people or audit queries. The gateway can sit in front of one — see the pooler contract for what it needs from it.
  • Data governance platforms (catalogs, masking, column-level policy across a warehouse) are broader. The gateway does no masking and no column-level policy; table and column scoping is the target-DB role's job (spec 06).

Decision matrix​

ScenarioFit
Engineers' agents need ad-hoc read access to production, attributed per persondb-mcp-gateway
Unattended agents (CI, runners) need audited, scoped DB accessdb-mcp-gateway with service tokens
Agents only ever need a fixed set of known queriesAn MCP toolbox of predeclared queries (optionally behind your own auth)
Humans need psql through SSO with session recordingAn access gateway
Too many connections to PostgresA pooler
Personal or disposable databaseConnection string
Masking or column-level policyA governance product or database-native features

Migrating to the gateway​

  1. Run it next to existing access. Point one team's agents at it; nothing else changes.
  2. Recreate permissions as grants. Map each existing role or wrapper rule to group × server × database × action; keep table scoping in the database roles.
  3. Switch agent configs to https://<gateway>/mcp and remove DSNs from client configs and secrets on laptops.
  4. Rotate the old credentials once nothing uses them, so the copies that leaked onto laptops stop working.

Effort depends on how many roles, agents and databases you have; we have no representative sample and will not invent an estimate.