Secure AI‑Powered Database Access with db-mcp-gateway: Credential Isolation, SSO, and Auditing
TL;DR – db-mcp-gateway is a self‑hosted MCP gateway that lets AI agents query production databases without ever exposing credentials. It integrates with popular SSO providers, enforces fine‑grained,‑based permissions, and records a complete audit trail for every query.
Introduction
Modern AI agents increasingly need direct access to production data to generate accurate insights, but exposing database URLs and passwords to these agents creates a massive security risk. db-mcp-gateway solves this problem by acting as a trusted intermediary that isolates credentials, enforces identity‑based access control, and logs every interaction.
Core Security Principles
Credential Isolation
- Never expose database URLs – credentials live only inside the gateway.
- AI agents receive query results, never connection strings.
- No credential leakage appears in logs, errors, or responses.
Identity & Access Control
- SSO‑driven authentication supporting Okta, Google Workspace, Entra, Authentik, Keycloak.
- Browser‑based SSO flow (no embedded browsers needed).
- Group‑based permission management with real‑time user validation.
Audit Trail
- Every query is recorded with user, group, grant, and optional reason.
- Auditable logs are stored in PostgreSQL for downstream compliance reporting.
Feature Overview
| Feature | Description |
|---|---|
list_databases |
Lists databases available for querying through the gateway. |
describe_schema |
Returns table structure and relationships. |
sample_table |
Provides a preview of data before executing a full query. |
run_query |
Executes SELECT queries safely with row limits and schema constraints. |
explain |
Offers query optimization and analysis. |
get_query_history |
Retrieves the audit trail and query history. |
All permissions are expressed as YAML grants, making them version‑controlled and reviewable via pull requests.
Sample Grant Configuration
grants:
- group: backend-devs
databases: [production_postgres]
actions: [query_read]
constraints:
schemas: [public, analytics]
row_limit: 1000
require_reason: true
This grant allows the backend-devs group to run read‑only queries on the production_postgres database, limited to the public and analytics schemas, with a maximum of 1,000 rows per query and a mandatory reason field.
Deployment in Minutes
# 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
The gateway runs as a single Docker container, stores its state and audit logs in PostgreSQL, and supports PostgreSQL and MongoDB back‑ends (MySQL/MSSQL are rejected at boot).
Use Cases
- Platform / SRE Teams – Provide AI agents with database access without risking credential leakage.
- Backend Developers – Query production data safely from CI/CD pipelines or debugging tools.
- Security & Compliance Officers – Gain complete attribution and auditability for every database request.
Why db-mcp-gateway?
- Security First – Credentials never leave the gateway.
- Compliance Ready – Full audit trails and SSO integration support compliance initiatives (no certifications claimed).
- GitOps Friendly – Permissions live as code, enabling peer review and change tracking.
Getting Started
Visit the GitHub repository for documentation, example configurations, and community support:
🔗 https://github.com/developerz-ai/db-mcp-gateway
Conclusion
db-mcp-gateway offers a pragmatic, security‑first approach to granting AI agents database access. By combining credential isolation, SSO‑driven authentication, and an immutable audit trail, it helps Platform/SRE teams, backend developers, and security officers protect sensitive data while still enabling powerful AI‑driven workflows.
Happy securing!
Top comments (0)