DEV Community

developerz.ai
developerz.ai

Posted on

Secure AI-Driven Database Access with db-mcp-gateway

Secure AI-Driven Database Access with db-mcp-gateway

Introduction

AI agents often need to query production databases, but exposing connection strings creates a serious security risk. db-mcp-gateway solves this problem by acting as a trusted intermediary that never reveals credentials to the agent. The gateway is self-hosted, runs in a single Docker container, and supports PostgreSQL and MongoDB back-ends.

Credential Isolation

All database passwords are stored only inside the gateway. An AI agent sends a request using the MCP protocol, the gateway authenticates the request, executes the query, and returns only the result set. No log line or error message ever contains a connection string. This design eliminates credential leakage from laptops, CI pipelines, or the agents themselves.

SSO-Driven Authentication

The gateway integrates with popular SSO providers such as Okta, Google Workspace, Entra, Authentik and Keycloak. Authentication happens via a browser-based flow; no embedded browsers are required. Permissions are granted per group, and the gateway validates the user in real time for each request.

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

The YAML file lives in version control, allowing audit-ready reviews and GitOps workflows.

Audit Trail

Every query is recorded with the SSO user, group, grant, timestamp and the executed SQL. The audit logs are stored in a PostgreSQL table inside the gateway, providing a tamper-proof history that can be exported for compliance reporting. Although the gateway is not itself certified, the detailed logs support SOC 2, HIPAA, ISO 27001 and other frameworks.

Config-as-Code Permissions

Permissions are defined as code, reviewed through pull requests, and applied without a UI. This approach reduces human error and ensures that changes are tracked in the same repository as the gateway configuration.

Deployment

Deploying the gateway is straightforward:

# 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

The container starts a single HTTP endpoint that implements the MCP protocol. The gateway state and audit logs are persisted in a PostgreSQL database.

Conclusion

db-mcp-gateway provides a security-first bridge between AI agents and production databases. By keeping credentials inside the gateway, enforcing SSO authentication, and logging every query, it meets the needs of Platform/SRE teams, backend developers and security officers. Try it today and protect your data without sacrificing AI productivity.

GitHub repository

Top comments (0)