PostgreSQL MCP wrapper with .env credential mapping, tool selection, and safe read-only defaults.
Copy the AI prompt to install this server into Claude Code, Cursor, or another agent β or use 1-click editor setup below.
We haven't yet run this listing's install command through our automated sandbox check. This isn't a red flag β we're steadily working through the catalog.
π‘ Paste the JSON block into your client's configuration file under mcpServers, then restart the application.
English | π PortuguΓͺs
|
|
Postgres MCPπ Native MCP server for PostgreSQL - reads credentials from |
Most LLMs interact with databases by guessing - assuming table names, inventing column names, and writing queries that may fail or expose sensitive data. Postgres MCP solves this by giving the LLM a structured, safe interface to actually understand the database before touching it.
Built with @modelcontextprotocol/sdk and pg, it provides:
pg_classify_query_risk lets the LLM check a query's safety before running it.env at startup; nothing sensitive lives in mcp.jsontool=<name> args, so the LLM only sees what you choose to expose.env file with database credentials (anywhere in the project tree - see .env Discovery)There are two ways to use this package. Choose the one that best fits your workflow.
npx, recommended for quick start)No installation needed. npx downloads and runs the package on demand. Add -y as the first argument to skip the confirmation prompt.
This starts the server with the default read-only tool set - no tool= arguments needed. To enable write-capable tools, see Write-capable tools.
π‘ Using Supabase, Neon, Railway or another platform that only provides a connection string? Use
MCP_KEY_URLpointing toDATABASE_URL(or whatever variable name the platform uses). The server will prioritize the URL and ignore the individual variables. See Connection via URL.
VS Code supports discovering and installing MCP servers directly in the editor, without using the terminal.
MCP: Add Serverpostgres-mcp or edelciomolinamcp.json automaticallyπ‘ You can also open the MCP Servers panel via Copilot chat icon β Manage MCP Servers to browse, enable, or disable servers at any time.
After installing, edit the generated entry in .vscode/mcp.json to add your tool= arguments and env key mappings as shown in the Usage section below.
mcp.json)Read-only (default - no tool= arguments needed):
With write tools (explicit opt-in required):
β οΈ Write-capable tools require
POSTGRES_MCP_ALLOW_WRITE=trueinenv. Without it, the server exits at startup.
The corresponding .env file at the root of your project:
mcp.json configuration worksenv - credential key mappingThe env block does not contain the actual credentials. It maps each MCP_KEY_* to the variable name in your .env file.
Key in env | Points to .env variable | Example value |
|---|---|---|
MCP_KEY_URL | DATABASE_URL | postgresql://user:pass@host:5432/db?sslmode=require |
MCP_KEY_HOST | DB_HOST | db.example.supabase.co |
MCP_KEY_PORT | DB_PORT | 5432 |
MCP_KEY_NAME | DB_NAME | postgres |
MCP_KEY_SSLMODE | DB_SSLMODE | require |
MCP_KEY_USER | DB_USER | readonly_user |
MCP_KEY_PASS | DB_PASS | secret |
Priority: when
MCP_KEY_URL(orDATABASE_URL) is present, the server uses the URL directly and ignores the individual credential keys.
This indirection lets you use any variable name in your .env - useful when sharing a .env across multiple services with different naming conventions.
args - tool selection via tool= prefixEach enabled MCP tool is declared as a separate argument in the format tool=<name>:
This makes the tool list explicit and auditable directly in mcp.json - no hidden configuration files. π
DATABASE_URL)In addition to individual credentials, you can provide a full connection string - the standard format on platforms like Supabase, Neon, and Railway.
.env:
mcp.json:
The variable mapped by MCP_KEY_URL has priority over the other keys (MCP_KEY_HOST, MCP_KEY_PORT, etc.). If the URL is present, the other variables are ignored.
If the platform uses a different name (e.g. DB_URL), just adjust the mapping:
If you omit all tool= arguments, the server starts with a curated read-only set - all tools that can retrieve, analyze, or explain data, but nothing that can modify it.
β Included in defaults (read-only):
π‘
pg_execute_queryrejectsINSERT,UPDATE,DELETE, DDL,ANALYZE,VACUUM,EXPLAIN ANALYZEand other write/maintenance commands before the database is queried.
π‘
pg_inspect_schemaprovides read-only schema introspection (get_info,get_enums). For DDL operations, usepg_manage_schemawith explicit opt-in.
β οΈ Excluded from defaults - require tool= argument AND POSTGRES_MCP_ALLOW_WRITE=true:
No reviews yet β be the first to share how this listing worked for you.
Showcase your server listing on GitHub or your project documentation. Embed this dynamic SVG badge to highlight official listing status and live engagement.
[](https://allmcps.com/mcp/postgres-mcp)<a href="https://allmcps.com/mcp/postgres-mcp"><img src="https://allmcps.com/api/badge/postgres-mcp?style=directory" alt="Postgres MCP on AllMCPs" /></a>