Features
Comprehensive feature breakdown of db-mcp-gateway with technical benefits and implementation details.
๐ Credential Securityโ
Credentials Never Leave the Gatewayโ
- What it does: Database credentials are stored exclusively in the gateway's configuration and never exposed to clients or logs
- How it works: Clients receive JWT tokens via SSO, gateway authenticates to databases using its own credentials
- Security benefit: No database URLs, passwords, or connection strings ever reach AI agents or developer laptops
- Audit benefit: Credential rotation only required at gateway, not across every developer's machine
Token-Based Authenticationโ
- What it does: Clients authenticate via SSO and receive short-lived gateway-signed session JWTs (8h default) plus a refresh token
- How it works: Generic OIDC authorization-code flow with PKCE against any IdP whose ID token carries a verified
emailand a groups claim โ see the IdP guides - Security benefit: No shared passwords, tokens expire automatically, no credential cleanup required
- Operations benefit: SSO integration leverages existing corporate directory and group memberships
๐ค Identity and Attributionโ
End-to-End User Identityโ
- What it does: Every database query is attributed to the specific SSO user who initiated it
- How it works: The session (stored in the state DB, referenced by the JWT) carries the user identity and the group snapshot taken at login; both land on every audit row
- Security benefit: Complete attribution for compliance and security investigations
- Operations benefit: No more "who ran this query?" investigations
Group-Based Authorizationโ
- What it does: Database access granted via group memberships defined in YAML configuration
- How it works: Users inherit grants from all groups they belong to, evaluated per-query
- Security benefit: Access control follows organizational structure (teams, departments)
- Operations benefit: User onboarding/offboarding handled via SSO, not database permissions
๐ก๏ธ Query Safety and Resource Limitsโ
Read-Only Enforcementโ
- What it does: All queries default to read-only access unless explicitly granted write permissions
- How it works: On Postgres, every read runs as the database's read-only role inside a
READ ONLYtransaction, and a statement guard rejects writes and DDL first; Mongo and Redis targets run only allowlisted read commands - Security benefit: AI agents cannot accidentally modify data, even if prompted incorrectly
- Operations benefit: Production data protection without monitoring every agent conversation
Statement Timeoutsโ
- What it does: Every query has an execution time limit โ 30,000 ms by default, which is also the ceiling; a grant's
statement_timeout_mscan only tighten it - How it works: A gateway-side deadline on every backend, plus
SET LOCAL statement_timeouton Postgres andmaxTimeMSon Mongo (Redis has only the gateway deadline) - Performance benefit: Prevents runaway queries from impacting database performance
- Operations benefit: No more "who locked up production?" incidents
Row Limitsโ
- What it does: Result sets are truncated at the effective row cap (grant
row_limit, callerlimit, else 1000 rows) or at a result-size cap, and flaggedtruncated: true - How it works: The gateway stops returning rows at the cap โ it never rewrites your SQL to add a
LIMIT. On Postgres a read the adapter cuts (row cap or the 32 MiB budget) is cancelled; one cut only by the caller'smax_byteshas already finished, and shaping just drops rows. A write with truncatedRETURNINGrows runs to completion and commits โ unless it is adry_run, which always rolls back โ so the cap limits what the agent sees, never how many rows a write changes - Performance benefit: Prevents large result sets from overwhelming network or agent context
- Operations benefit: Cost control on databases that charge per query byte
Schema and Table Scopingโ
- What it does: Which schemas and tables a caller can read is decided by the target-DB role the grant connects as โ there is no
allowed_schemas/denied_tablesgrant constraint - How it works: Grant each read-only role exactly the tables it may
SELECT(GRANT SELECT ON โฆ); the database enforces that for every statement, including through views, functions andsearch_path, which a gateway-side SQL parser cannot see through (spec 06) - Security benefit: Multi-tenant databases expose only the schemas the role was granted
- Operations benefit: A single database server can serve multiple security domains, one role per domain
๐ Permissions and Configurationโ
YAML-Based Configurationโ
- What it does: Permissions defined in human-readable YAML reviewed via PR โ or, when enabled, through the SSO-gated, synchronously audited admin API
- How it works: Config file maps groups โ servers โ databases โ actions with constraints
- Operations benefit: No admin UI to maintain; YAML changes tracked in git history, admin-API changes in
permissions_audit - Security benefit: Changes require code review, not ad-hoc admin panel clicks
Granular Grant Systemโ
- What it does: Four-tier permission structure: group ร server ร database ร action
- How it works: Each grant names one action:
schema_read,query_read,query_write(each implies the one before it) or the standalonehistory_read - Flexibility benefit: Can grant schema-only access to analysts, full access to DBAs
- Security benefit: Principle of least privilege enforced at technical level
Constraint Systemโ
- What it does: Each grant can specify constraints:
require_reason,row_limit,statement_timeout_ms. When several grants match, the most restrictive value of each wins - How it works: Constraints evaluated per-query before execution
- Compliance benefit: Production queries automatically require incident ticket numbers
- Operations benefit: Different constraints for development vs. production environments
๐ Audit and Complianceโ
Synchronous Audit Logโ
- What it does: Every database query logged before result returned to client
- What it captures: User identity, SQL statement, reason (if required), row count, duration, outcome
- How it works: Append-only log in gateway's state database, with a configurable retention TTL and an hourly pruner
- Compliance benefit: Complete query history for security reviews and compliance audits
Query History APIโ
- Status: Shipped via #169. The
get_query_historyMCP tool reads from the same audit log; users see only their own queries. - What it does: Lets a user retrieve their own recent queries (SQL, timestamp, duration, row count, outcome) for a configured
(server, database). - How it works: Reads
audit_callsrows scoped byuser_sub = $1 AND server_name = $2 AND database_name = $3(the SSO-verified identity, never a client-supplied field). Requires the standalonehistory_readgrant. - Privacy benefit: Users see their own history, not teammates' queries
- Operations benefit: Self-service audit access reduces support burden
Retention (hot tier + stdout/syslog streams shipped; archive and OTLP/Kafka on the roadmap)โ
- What it does today: Audit logs live in the gateway's Postgres with a configurable TTL (default 90 days) and an hourly pruner that deletes past it. Operators can also mirror every full audit row out to
stdoutor a syslog receiver vialogging.stream: [{kind: stdout}, {kind: syslog, host: ..., port: ...}]โ see SIEM Integration below. - Not shipped: Cold-tier archive (S3/GCS/Azure) and the remaining streaming sink kinds (
otlp,kafka) are roadmap Phase 4 โ there is noarchiveconfig key yet, and the parser rejects the unshippedstreamkinds. - Operations benefit: Hot data stays fast today; cold-tier retention lands when Phase 4 ships.
๐ค MCP Integrationโ
Complete MCP Tool Surfaceโ
- What it does: Ten MCP tools cover all database interaction patterns
- Tools included:
list_servers- Enumerate target servers visible to the callerlist_databases- Enumerate available databases on a serverdescribe_schema- Get table/column metadata with typessample_table- Preview data with configurable sample sizerun_query- Execute SQL with safety limitsexplain- Get query execution plansget_query_history- Retrieve a user's own recent queries from the audit logtable_stats- Table and index sizes, row estimates, scan and vacuum statisticsdb_activity- The caller's own statements the gateway is running right now (run_scoped: true: refuse unless narrowed to the caller's run)whoami- Your identity, groups, session expiry and grantscancel_query- Cancel one of the caller's own running statements byrequest_id(samerun_scoped)
Multi-Database Supportโ
- What it does: Single gateway instance fronts PostgreSQL, YugabyteDB (YSQL, as a Postgres target), MongoDB and Redis-protocol targets (Redis, Dragonfly, Valkey, KeyDB). MongoDB and Redis are read-only; MySQL/MSSQL are rejected at boot โ see multi-db
- How it works: Abstracted database drivers with unified MCP interface
- Operations benefit: One deployment serves mixed database environments
- Workflow benefit: AI agents can cross-reference data across database types
Claude Code Optimizationโ
- What it does: Dedicated integration patterns for Claude Code (Anthropic's AI coding agent)
- Features: Project-scoped configs, automatic SSO flow, query attribution in conversations
- Developer benefit:
claude mcp addand start querying, no manual authentication
๐๏ธ Deployment and Operationsโ
Small Deployment Footprintโ
- What it does: Gateway runs as a single Docker container with one Postgres dependency (plus your IdP)
- How it works:
docker pull+ YAML config + Postgres state database - Operations benefit: No complex multi-service deployments or Kubernetes clusters required
- Testing benefit: Easy to run locally for development and testing
Health and Readiness Endpointsโ
- What it does:
/readyzendpoint for load balancer health checks (state-DB reachable + not shutting down);/healthzis a plain liveness probe (200 if the binary is up) - How it works:
/readyzreturns 200 when the gateway's state DB answersSELECT 1within 2 s, 503 otherwise or while shutting down. It does not probe target databases โ a target outage shows asunavailableon tool calls, not as an unready pod - Operations benefit: Standard load balancer integration for high availability
Tested Release Imagesโ
- What it does: Every
v*git tag publishes the multi-arch image CI already built and tested for that commit - How it works: The release re-tags the tested per-arch images (amd64 + arm64) by digest; it rebuilds only when no tested image exists. Builds are pinned (
--locked, digest-pinned base images) but not bit-for-bit reproducible - Security benefit: Pin production to an exact version tag or digest; the moving
latest,XandX.Ytags only ever move forward (releasing) - Operations benefit: Consistent behavior across development, testing, and production
๐ Enterprise Integrationโ
SSO Integrationโ
- What it does: SSO via any OIDC-compliant identity provider โ the gateway speaks generic OIDC, not provider-specific integrations
- Security benefit: No user accounts to manage, leverage existing corporate directory
- Operations benefit: User onboarding/offboarding handled centrally, not per application
SIEM Integration (stdout/syslog shipped; OTLP/Kafka on the roadmap)โ
- What it does today:
logging.stream: [{kind: stdout}]emits every full audit row as a distincttarget: "audit_stream"tracing event โ separate from the gateway's own operational logs (application logs are JSON-per-line to stdout too, but that's an operational log, not an audit export, and doesn't satisfy this on its own).logging.stream: [{kind: syslog, host: ..., port: ...}]sends the same row as an RFC 5424 message over UDP, fire-and-forget โ a broken or unreachable receiver never delays or fails the agent's request. - Not shipped:
otlpandkafkasink kinds โ the config parser rejects them; roadmap Phase 4. This list mirrors the retention spec'sStoragetable.
Multi-Cloud Archive (roadmap, not shipped)โ
- What it will do: Archive audit logs to S3, Google Cloud Storage, or Azure Blob Storage past the hot-tier retention window
- Status: No archive exporter is implemented and there is no
archiveconfig key; roadmap Phase 4.
๐ฏ Platform Featuresโ
Time Windows (roadmap, not shipped)โ
- What it will do: Let a grant apply only within a time range (e.g. business hours)
- Status: No
time_windowconstraint exists yet โ the parser rejects it; see the roadmap
Reason Requirementโ
- What it does: Production grants can require human-readable reason per query
- How it works: Gateway rejects queries without reason, reason stored in audit log
- Compliance benefit: Every production query tied to incident ticket or user story
- Operations benefit: Audit reviews can quickly understand query context
Constraint Evaluationโ
- What it does: All constraints evaluated before query execution, fast rejection
- How it works: Grant match, action and
require_reasonare checked before the database is touched; row limits and timeouts bound the query as it runs - Performance benefit: Invalid queries rejected without database round-trip
- Operations benefit: Clear error messages help users understand permission boundaries
๐ซ Security by Designโ
No Admin UIโ
- What it does: Permissions change only through reviewed YAML or the SSO-gated admin API โ there is no web interface
- Security benefit: Every admin-API change commits a
permissions_auditrow in the same transaction, or does not happen - Operations benefit: YAML changes have code review and git history; API changes have an audit row naming the admin
No Credential Exposureโ
- What it does: Database credentials never appear in logs, error messages, or API responses
- Security benefit: Logs can be safely shared without redaction
- Operations benefit: Debugging and support without credential exposure risks
No Self-Elevationโ
- What it does: Agents cannot grant themselves additional permissions
- How it works: Permission evaluation happens server-side, agents cannot modify gateway config
- Security benefit: AI agents limited to defined grants, cannot escape constraints
- Operations benefit: Prompt injection cannot expand the agent's server-side permissions or bypass grant constraints