loading…
Search for a command to run...
loading…
Provides a secure, schema-aware PostgreSQL database agent for LLMs, enabling natural language queries and validated SQL execution with strong security guardrail
Provides a secure, schema-aware PostgreSQL database agent for LLMs, enabling natural language queries and validated SQL execution with strong security guardrails.
Production-Grade, Schema-Aware PostgreSQL Agent via Model Context Protocol (MCP)
License: MIT MCP Compliant PRs Welcome
mcp-server-postgres is an intelligent database isolation layer designed to bridge the gap between Large Language Models (LLMs) and production PostgreSQL clusters. Developed with a security-first, schema-aware architecture, it translates natural language requests into validated, optimized, and ACID-compliant SQL.
graph TD
Client[MCP Client/LLM] -->|JSON-RPC| Server[MCP Server Hub]
Server -->|Validation| Guard[Security Guardrails]
Guard -->|AST/Pattern Scan| SQL[Validated SQL]
SQL -->|Execution| Pool[Connection Pool Manager]
Pool -->|Write Ops| Primary[Primary DB]
Pool -->|Read Ops| Replica[Read Replicas]
Pool -->|Auditing| Audit[Pino Structured Logs]
READ_ONLY to ADMIN) to maintain least-privilege principles.UPDATE or DELETE missing an explicit WHERE clause.password_hash, ssn).BEGIN/COMMIT blocks.Configure your environment variables in .env:
| Variable | Description | Default |
|---|---|---|
DATABASE_URL |
Primary PostgreSQL DSN | Required |
READ_REPLICA_URL |
Optional replica DSN for read routing | null |
PERMISSION_TIER |
READ_ONLY | READ_WRITE | DDL_ALLOWED | ADMIN |
READ_ONLY |
MASKED_COLUMNS |
Comma-separated list of columns to redact | null |
MAX_ROWS |
Hard upper limit for result pages | 100 |
SLOW_QUERY_THRESHOLD_MS |
Warning threshold for latency | 500 |
query(sql, params, page, page_size): Executes validated SQL. Includes auto-pagination.nl_query(request, context): High-level translation interface (requires LLM bridge).schema_inspect(schema, table): Deep introspection of schema metadata.list_tables(schema): Optimized enumeration of current database schema.describe_table(schema, table): Column definitions, indexes, and FK relationships.explain(sql, params): Transparent query analyzer with cost estimation.transaction(operations): Atomic batch execution for complex mutations.confirm_ddl(token): Final execution of verified schema changes.npm install
npm run build
npm run start
Add to yours claude_desktop_config.json:
{
"mcpServers": {
"postgres": {
"command": "node",
"args": ["/absolute/path/to/mcp-server-postgres/dist/index.js"],
"env": {
"DATABASE_URL": "postgresql://user:pass@localhost:5432/db",
"PERMISSION_TIER": "READ_WRITE"
}
}
}
}
All operations are logged via pino for enterprise observability.
{
"level": "INFO",
"module": "audit",
"operation_type": "QUERY",
"affected_tables": ["public.users"],
"execution_ms": 12.4,
"row_count": 8,
"agent_identity": "mcp-server-postgres"
}
MIT License. Created with precision by Ismail-2001.
Run in your terminal:
claude mcp add mcp-server-postgres -- npx Yes, Server Postgres MCP is free — one-click install via Unyly at no cost.
No, Server Postgres runs without API keys or environment variables.
A hosted option is available: Unyly runs the server in the cloud, no local setup required.
Open Server Postgres on unyly.org, pick your client tab (Claude Desktop, Claude Code, Cursor) and press Install — the config is generated automatically, no JSON editing.
Query your database in natural language
by AnthropicA universal database MCP server supporting simultaneous connections to multiple databases. It provides tools for database operations, health analysis, SQL optim
by wenb1n-devThis server enables interaction with PostgreSQL databases through the Model Context Protocol, optimized for the AWS Bedrock AgentCore Runtime. It provides tools
by madhurprashRead-only database access with schema inspection.
by modelcontextprotocolNot sure what to pick?
Find your stack in 60 seconds
Author?
Embed badge for your README
Browse similar
All data MCPs