Securing AI-Driven Database Access with db-mcp-gateway
Securing AI-Driven Database Access with db-mcp-gateway In environments where AI agents need to query production databases, exposing credentials is a major risk. The db-mcp-gateway addresses this by acting as a self-hosted MCP (Model Context Protocol) gateway that isolates credentials and enforces s

In environments where AI agents need to query production databases, exposing credentials is a major risk. The db-mcp-gateway addresses this by acting as a self-hosted MCP (Model Context Protocol) gateway that isolates credentials and enforces strict access controls.
All database passwords and connection strings reside only inside the gateway container. AI agents send queries through the MCP protocol and receive only result sets. No log line, error message, or response ever contains a URL or password, eliminating accidental leaks.
Authentication is delegated to enterprise SSO providers such as Okta, Google Workspace, Entra, Authentik, and Keycloak. Users authenticate via a browser flow, and the gateway maps the SSO identity to groups defined in a YAML configuration. Permissions are expressed as grants, for example:
grants: - group: backend-devs databases: [ production_postgres ] actions: [ query_read ] constraints: schemas: [ public, analytics ] row_limit: 1000 require_reason: true Enter fullscreen mode Exit fullscreen mode Each query is attributed to the SSO user, the group, and the specific grant, providing full traceability.
Every request is recorded in a PostgreSQL audit log. The log includes the user, group, database, query text, timestamp, and outcome. The get_query_history endpoint allows teams to retrieve this history for compliance reviews or incident investigations.
The gateway supports multiple SSO providers without requiring embedded browsers. After authentication, the gateway validates the user in real time, ensuring that revocation or group changes take effect immediately.
Permissions are stored as YAML files that live in version control. Changes are reviewed through pull requests, promoting a GitOps workflow. There is no in-band admin UI, reducing the attack surface.
Deploying the gateway is straightforward: a single Docker container and one YAML configuration file are required. The gateway runs a lightweight PostgreSQL instance for state and audit logs and supports PostgreSQL and MongoDB as backend databases.
# Pull the latest image docker pull ghcr.io/developerz-ai/db-mcp-gateway:1.1.1 # Run with your config Docker run -p 8080:8080 -v $( pwd ) /config.yaml:/app/config.yaml ghcr.io/developerz-ai/db-mcp-gateway:1.1.1 Enter fullscreen mode Exit fullscreen mode Who Should Use It? Platform/SRE Teams can provide AI-driven database access without credential exposure. Backend Developers gain safe, natural-language query capabilities.
Security Officers receive a complete audit trail and fine-grained access control. Conclusion The db-mcp-gateway offers a security-first approach to AI-driven database access. By keeping credentials inside the gateway, integrating with enterprise SSO, and providing immutable audit logs, it helps teams meet compliance objectives while enabling powerful AI workflows.
The project is open source and available at https://github.com/developerz-ai/db-mcp-gateway.