DB MCP Gateway logo

DB MCP Gateway

Self-hosted MCP gateway for audited, SSO-authenticated, read-only access to PostgreSQL and MongoDB databases.

Install DB MCP Gateway

Pick your client, then add it in one click or paste the config.

Streamable HTTP (Remote)
Server URL
https://db.internal.acme.com/mcp

Remote servers are added in the app, not the config file: Customize → Connectors → Add custom connector, then paste this URL.

Claude Code command
claude mcp add --transport http db-mcp-gateway https://db.internal.acme.com/mcp

Run in your terminal, then run /mcp in Claude Code to sign in if the server asks.

Overview

db-mcp-gateway places database credentials behind a self-hosted MCP gateway, so agents connect through one HTTPS endpoint rather than receiving connection strings. It authenticates users with an OIDC provider, applies YAML-defined grants, enforces read and resource limits, and records each request in an append-only audit log before returning results. Agents can inspect schemas, run queries, explain plans, review history, and monitor database activity against supported PostgreSQL and MongoDB targets. Reach for it when production database access needs SSO attribution, pull-requested permissions, and centralized credential handling.

Use cases

  • Give agents production database access without distributing credentials
  • Require SSO and reasons for sensitive database queries
  • Review database permissions through pull requests
  • Audit agent queries with user, SQL, timing, and outcome
  • Limit query rows and execution time across supported targets

Key features

  • OIDC browser-based SSO
  • YAML-defined, least-privilege grants
  • Read-only access by default
  • Synchronous append-only query auditing
  • PostgreSQL and MongoDB query targets
  • Query limits and cancellation tools

Security & health

What it can reach and how reliably it runs — from our own checks, not the maintainer’s claims.

ActiveLast checked

Recent health check succeeded.

5/5 checks healthy over the last 22d

Adoption & maintenance

Factual signals from GitHub, npm, and our automated checks — not a rating.

GitHub stars5Stargazers on the source repository.
Last commit5d agoMost recent push to the default branch.
Directory activity2 viewsConfig copies, upvotes, and views on AllMCPs.

How DB MCP Gateway works

What db-mcp-gateway does

db-mcp-gateway gives AI agents a controlled MCP interface to databases while keeping target database credentials inside the gateway. Developers configure their MCP client with the gateway URL; the client does not receive a database URL or credential. The gateway connects to configured query targets using database roles and returns tool results to the authenticated user.

PostgreSQL and MongoDB are supported as query targets. PostgreSQL is also used for the gateway's own state, including sessions, grant metadata, and audit records. MySQL and MSSQL are not query targets; configurations using either kind are rejected during startup.

Access is read-only by default. A query_write grant can allow INSERT, UPDATE, and DELETE, but it cannot enable schema changes. Database-side roles remain responsible for table and schema scope, while gateway grants define access across groups, servers, databases, and actions.

How it works

An agent sends MCP requests over HTTPS to the gateway. The first request starts an OIDC browser login with the configured identity provider, such as Okta, Google Workspace, Entra, Authentik, or Keycloak. The gateway uses the resulting identity and group membership to evaluate the applicable YAML grants.

Before a result is returned, the gateway checks the request, executes it against the target database, and writes an audit record. Records include the user, SQL, reason, row count, duration, and outcome. Audit writes are synchronous: if the audit write fails, the request also fails. Retention is controlled by a configurable TTL and an hourly pruning process. Audit events can additionally be sent to stdout or syslog.

Statement timeouts and row limits can be enforced at both the gateway and database layers. Grants may require a reason and set row or timeout constraints. The gateway stores its sessions and audit data in a separate Postgres state database rather than exposing that store to agents.

Setup and configuration

Deployment uses an OCI container, one YAML configuration file, and a Postgres instance for gateway state. The image is published on GHCR for linux/amd64 and linux/arm64; the :latest tag follows the newest release, while production deployments can pin a release tag.

On the client side, configure the gateway as an HTTP MCP endpoint. For Claude Code, the documented command is:

Terminal
claude mcp add --transport http db-gateway --scope project https://db.internal.acme.com

The first call opens authentication in a real browser rather than an embedded webview. A local quickstart can also provide a disposable target database for an end-to-end trial. Permissions are managed through YAML and reviewed through the team's normal pull-request workflow; there is no in-band administration UI.

Tools and capabilities

The MCP tool surface includes:

  • list_servers and list_databases for discovering configured resources.
  • describe_schema, sample_table, and table_stats for database inspection.
  • run_query for permitted SQL execution and explain for query plans.
  • get_query_history for reviewing recorded requests.
  • db_activity for database activity information.
  • cancel_query for stopping an in-progress query.

The gateway supports OIDC SSO, per-database least-privilege roles, configurable grant constraints, synchronous auditing, and optional stdout or syslog audit sinks.

Limitations and notes

MySQL and MSSQL adapters for agent query targets are not available, and configurations selecting either are rejected at boot. Write grants cover data mutations only; they do not permit schema changes. Table- and schema-level restrictions must be implemented by roles in the target database rather than by gateway grants.

The gateway is not an agent runtime, query builder, or credential vault operated as a separate service. Audit archiving to object storage and OTLP streaming are planned capabilities rather than shipped features. The project is licensed under MIT.

Written by AllMCPs with AI assistance from the project’s README and listing data. How we build listings

Reviews

No reviews yet — be the first to share how it worked for you.

Frequently Asked Questions about DB MCP Gateway

db-mcp-gateway is an MCP server that connects AI agents to supported PostgreSQL and MongoDB databases without exposing database credentials. It authenticates users through OIDC SSO, applies YAML-based grants, and provides tools for schema inspection, sampling, querying, explaining plans, reviewing history, checking activity, and canceling queries.

Install it as an OCI container from GHCR, configure one YAML file and a Postgres state database, then point an MCP client at its HTTPS endpoint. Claude Code can use the documented `claude mcp add --transport http` command, and the first request starts browser-based OIDC login.

It supports PostgreSQL and MongoDB as agent query targets. PostgreSQL also stores gateway state. MySQL and MSSQL cannot be used as query targets; configurations selecting either database type are rejected during startup.

Yes, but only when a grant explicitly enables the `query_write` action. That grant permits `INSERT`, `UPDATE`, and `DELETE`; schema changes remain disallowed. Read-only access is the default, and target database roles control table and schema scope.

It writes an audit record before returning the query result. Each record can include the SSO user, SQL statement, reason, row count, duration, and outcome. Records are retained in the gateway's Postgres state database, with configurable TTL pruning and optional stdout or syslog sinks.

Related MCP servers

Add a badge to your READMEShow it’s listed — live SVG, Markdown or HTML.

AllMCPs Directory Badge

Full Badge Customizer

Showcase your server listing on GitHub or your project documentation. Embed this dynamic SVG badge to highlight official listing status and live engagement.

Badge Style:
Live Dynamic SVG PreviewDB MCP Gateway AllMCPs Directory Badge
Markdown (GitHub README)
[![AllMCPs](https://allmcps.com/api/badge/db-mcp-gateway?style=directory)](https://allmcps.com/mcp/db-mcp-gateway)
HTML Embed
<a href="https://allmcps.com/mcp/db-mcp-gateway"><img src="https://allmcps.com/api/badge/db-mcp-gateway?style=directory" alt="DB MCP Gateway on AllMCPs" /></a>