Skip to main content

Use Cases

Real-world scenarios where db-mcp-gateway solves specific problems for AI agent infrastructure teams.


Use Case 1: AI Agent Database Access for Development Teams​

Problem: A development team wants to integrate Claude Code agents with their production databases for debugging and analysis, but giving agents direct database credentials is unacceptable from a security perspective.

Solution: Deploy db-mcp-gateway as a secure intermediary. Agents connect via MCP with SSO authentication, and all database access is logged and attributed to individual users.

Implementation​

The permissions: section of the gateway YAML. One grant names one server, one database (or "*") and one action; every server and database must be declared under servers: (config reference).

permissions:
- group: backend-team
grants:
- server: production
database: app_db
action: query_read
constraints:
row_limit: 1000
statement_timeout_ms: 5000
require_reason: true
- server: production
database: analytics_db
action: query_read
constraints:
row_limit: 1000
statement_timeout_ms: 5000
require_reason: true

Benefits​

  • Security: No database credentials ever leave the gateway
  • Audit trail: Every query is logged with user identity and reason
  • Granular control: Row limits and timeouts prevent runaway queries
  • SSO integration: Team members use existing Google/Okta/Microsoft accounts

Workflow​

  1. Developer adds gateway to Claude Code via claude mcp add
  2. First query triggers SSO login (browser-based)
  3. Agent queries are automatically attributed to developer's identity
  4. Audit log captures every SQL statement for compliance review

Use Case 2: Analytics Without Direct Database Access​

Problem: Data and analytics engineers want their agents to query analytical databases, but managing an individual database account per person is operationally expensive.

Solution: Their agents (which turn questions into SQL — the gateway has no natural-language layer of its own) query through db-mcp-gateway, which enforces read-only access and resource limits. This is for engineers running agents, not for end users or business staff: see non-goals.

Implementation​

permissions:
- group: analytics-users
grants:
# query_read includes schema_read, so describe_schema works too.
- server: data-warehouse
database: sales_metrics
action: query_read
constraints:
row_limit: 10000
- server: data-warehouse
database: user_analytics
action: query_read
constraints:
row_limit: 10000

Schema scoping (only public and analytics, say) is not a grant setting: grant the database role USAGE and SELECT on exactly those schemas, and the database enforces it for every statement.

Benefits​

  • Self-service: Engineers ask their agent; no per-person database account
  • Safety: Read-only enforcement prevents accidental data modification
  • Performance: Resource limits prevent expensive analytical queries from impacting production
  • Compliance: Every tool call is logged — SQL, reason, row count, outcome, identity. The prompt and the agent's answer are not; the gateway never sees them

Example Interactions​

Analyst: "What was user growth over the last 6 months?"
Agent: [queries through gateway, returns chart-ready data]

Analyst: "Show me the top 10 countries by user count"
Agent: [generates SQL, applies limits, returns results]

Use Case 3: Multi-Database AI Workflows​

Problem: Complex AI workflows need to query across multiple databases (PostgreSQL, MongoDB, Redis) with consistent security and auditing across all systems.

Solution: db-mcp-gateway acts as unified access layer, supporting multiple database types with consistent permission model and audit trail.

Implementation​

permissions:
- group: workflow-automation
grants:
- { server: postgres-primary, database: app_db, action: query_read }
- { server: postgres-primary, database: user_profiles, action: query_read }
# "*" covers every database configured on the server.
- { server: postgres-analytics, database: "*", action: query_read }
- { server: mongo-documents, database: content_store, action: query_read }

Benefits​

  • Unified security: Single SSO login across all database types
  • Consistent auditing: All queries logged regardless of database backend
  • Agent-friendly: MCP interface works seamlessly across different databases
  • Operations: One gateway instance manages all database access

Workflow Example​

Agent Workflow:
1. Query user profiles from PostgreSQL
2. Cross-reference with the analytics Postgres event logs
3. Fetch related documents from MongoDB
4. Generate unified report

All queries go through same gateway with:
- Consistent authentication (SSO)
- Unified audit trail
- Per-query resource limits

Use Case 4: Production Debugging with Compliance​

Problem: On-call engineers need production database access for debugging incidents, but compliance requirements mandate individual attribution, reason logging, and strict time limits.

Solution: db-mcp-gateway enforces the compliance requirements on every call the on-call engineer's agent makes during incident response.

Implementation​

permissions:
- group: oncall-engineers
grants:
# query_read covers run_query, explain, sample_table and describe_schema.
- server: production
database: app_db
action: query_read
constraints:
require_reason: true
statement_timeout_ms: 10000
row_limit: 500

Restricting access to business hours is not supported yet — a time_window constraint is on the roadmap, and the parser rejects it today. Who is on call is your IdP's group membership.

Benefits​

  • Compliance: Every query requires reason (incident ticket, user story)
  • Safety: Time limits and row caps prevent production impact
  • Attribution: All queries linked to individual SSO accounts
  • Audit: Complete incident timeline captured automatically

Incident Response Flow​

1. Alert triggers at 2 AM
2. On-call engineer asks: "Show me recent errors for user ID 12345"
3. Gateway refuses the call with `reason_required`; the agent asks the engineer for one
4. Engineer answers: "Investigating incident INC-2024-0142"; the agent retries with it
5. Query executes with enforced limits
6. Audit log captures: user, SQL, reason, timestamp, row count, outcome (never the result rows)

Use Case 5: Gradual Migration from Direct Database Access​

Problem: Organizations with existing direct database access want to migrate to safer AI agent workflows without disrupting current operations.

Solution: Deploy db-mcp-gateway alongside existing access patterns, gradually migrating teams to AI agent interface while maintaining full compatibility.

Migration Strategy​

permissions:
# Phase 1: Pilot with read-only analytics
- group: analytics-pilot
grants:
- { server: production, database: analytics_db, action: query_read }

# Phase 2: Expand to development teams
- group: dev-team-early-adopters
grants:
- { server: staging, database: app_db, action: query_read }

# Phase 3: Production debugging (compliance-approved)
- group: oncall-production
grants:
- server: production
database: app_db
action: query_read
constraints:
require_reason: true

Benefits​

  • Low-risk migration: Direct access continues during transition
  • Gradual adoption: Teams migrate when ready, not all-at-once
  • Improved security: Each migration step reduces credential exposure
  • Workflow continuity: Existing operations continue uninterrupted

Target Audiences​

Platform/SRE Teams​

  • Why: You own production databases and need to enable AI agent access safely
  • Value: Self-service access for developers without credential management
  • Benefit: Complete audit trail for compliance and security reviews

Backend Development Teams​

  • Why: You need production data for debugging and analysis
  • Value: Your agent writes and runs the SQL; you never hold the credential
  • Benefit: Faster incident response with compliance built-in

Data Analytics Teams​

  • Why: You need data access but don't want to manage database accounts
  • Value: Self-service analytics without learning every database's SQL dialect
  • Benefit: Consistent interface across PostgreSQL, YugabyteDB, MongoDB and Redis

Security/Compliance Teams​

  • Why: You need to control and monitor all database access
  • Value: Centralized audit log with SSO attribution and resource limits
  • Benefit: Compliance requirements enforced automatically, not culturally

AI/ML Platform Teams​

  • Why: You're building AI agent infrastructure that needs real data access
  • Value: Production-ready MCP interface with enterprise security features
  • Benefit: Deploy agents faster without building custom database integrations