# db-mcp-gateway [Health: Active]

**Category:** 🗄️ Databases  
**Repository:** https://github.com/developerz-ai/db-mcp-gateway  
**GitHub Stars:** 5  
**Views:** 2  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/db-mcp-gateway

## Description
Self-hosted MCP gateway: AI agents get audited, SSO-gated, read-only database access without ever holding a DB credential.

## Claude Desktop Quick Installation
Remote MCP endpoint (confidence: high). Install path detected from listing signals. Add as a URL/SSE server in your client:

```json
"mcpServers": {
  "db-mcp-gateway": {
    "url": "https://db.internal.acme.com/mcp"
  }
}
```

## Documentation

## 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:

```bash
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.

_Full upstream README: https://allmcps.com/mcp/db-mcp-gateway/readme_

