MCP DB Gateway
OfficialProvides governed, read-only access to PostgreSQL databases, with schema and table allowlists, SQL validation, row and statement time limits, and audit events.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MCP DB Gatewaydescribe the customers table"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MCP DB Gateway
Governed database access for AI agents.
MCP DB Gateway sits between MCP clients and your database. It gives agents enough context to work while keeping database access narrow, read-only, limited, and auditable.
The goal is not another universal SQL connector. The goal is a practical governance boundary for tools such as Cursor, Claude Code, and Claude Desktop.
Early-stage software. Do not treat v0.1 as a complete security boundary without reviewing it for your environment.
Why this exists
Giving an AI agent a database connection creates two opposing problems:
Too little access forces developers to paste schemas and data into prompts.
Too much access lets an agent explore or expose far more than the task requires.
MCP DB Gateway makes that boundary explicit through allowlists, read-only transactions, query limits, and audit events.
Related MCP server: readonly-postgres-mcp
v0.1 scope
PostgreSQL
MCP over stdio
list_tablesdescribe_tableexecute_querySchema and table allowlists
Read-only SQL validation and transactions
Row and statement-timeout limits
JSON audit events written to stderr
MySQL, SQLite, PII masking, role-based access, and a remote gateway are intentionally deferred.
Quick start
Requirements: Node.js 20+ and PostgreSQL.
git clone https://github.com/altsys/mcp-db-gateway.git
cd mcp-db-gateway
npm install
cp mcp-db-gateway.example.json mcp-db-gateway.jsonEdit mcp-db-gateway.json so it contains only the schemas and tables the agent needs. Then build and run:
export DATABASE_URL="postgresql://user:password@localhost:5432/database"
npm run build
MCP_DB_GATEWAY_CONFIG=./mcp-db-gateway.json node dist/index.jsExample MCP client configuration:
{
"mcpServers": {
"database": {
"command": "node",
"args": ["/absolute/path/to/mcp-db-gateway/dist/index.js"],
"env": {
"DATABASE_URL": "postgresql://user:password@localhost:5432/database",
"MCP_DB_GATEWAY_CONFIG": "/absolute/path/to/mcp-db-gateway/mcp-db-gateway.json"
}
}
}
}Configuration
{
"databaseUrlEnv": "DATABASE_URL",
"governance": {
"allowedSchemas": ["public"],
"allowedTables": ["public.customers", "public.orders"],
"maxRows": 100,
"statementTimeoutMs": 5000
}
}An empty allowedTables array permits every table inside allowedSchemas. For a real deployment, prefer an explicit table allowlist.
Security model
The gateway provides defense in depth, not magic. Use a dedicated PostgreSQL role with SELECT access only. The application also validates SQL, opens a read-only transaction, limits execution time, and caps returned rows.
SQL parsing is deliberately conservative in v0.1. A proper PostgreSQL parser and table-level query enforcement belong on the near-term roadmap.
Roadmap
Enforce table policy inside arbitrary SQL queries
Replace conservative string validation with an AST-based PostgreSQL policy engine
Mask configured PII columns
Add structured file or HTTP audit sinks
Add MySQL and SQLite adapters behind a shared provider interface
Add named context packs for task-specific access
Add RBAC and remote transport
Contributing
Issues and focused pull requests are welcome. Please keep changes aligned with the central idea: agents should receive the least database access necessary to complete the task.
License
MIT
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- Alicense-qualityAmaintenanceProvides a read-only PostgreSQL SQL surface for LLM agents via MCP, with defense-in-depth security layers for safe database queries.3MIT
- Alicense-qualityCmaintenanceReadonly PostgreSQL MCP server with SQL guardrails for analytical queries and schema introspection.7MIT
- Alicense-qualityAmaintenanceA hardened, read-only Postgres MCP server that enables LLMs to safely query databases without write, DDL, shell, or credential exposure.MIT
- Alicense-qualityCmaintenanceProvides a read-only PostgreSQL MCP server with schema introspection. Enforces least-privilege database roles to prevent any writes, even from malicious SQL.MIT
Related MCP Connectors
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
A paid remote MCP for AI SDK data query MCP, built to return verdicts, receipts, usage logs, and aud
Analytical memory for AI agents: a real Postgres queried in plain English over MCP. One command.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/altsys/mcp-db-gateway'
If you have feedback or need assistance with the MCP directory API, please join our Discord server