Server data from the Official MCP Registry
PostgreSQL MCP wrapper with .env credential mapping, tool selection, and safe read-only defaults.
PostgreSQL MCP wrapper with .env credential mapping, tool selection, and safe read-only defaults.
This PostgreSQL MCP server has solid security fundamentals with read-only defaults, proper credential handling via .env files, and reasonable permission scoping for its category. However, there are several code quality and potential security concerns: missing input validation on user-supplied SQL queries, inadequate error handling with potential information disclosure, and the write-capable tools (pg_execute_mutation, pg_execute_sql) lack sufficient safeguards despite being opt-in. The server appropriately reads credentials from environment variables at runtime rather than storing them, and the explicit tool selection mechanism is well-designed for security. Supply chain analysis found 3 known vulnerabilities in dependencies (0 critical, 3 high severity). Package verification found 1 issue.
3 files analyzed Β· 16 issues found
Security scores are indicators to help you make informed decisions, not guarantees. Always review permissions before connecting any MCP server.
This plugin requests these system permissions. Most are normal for its category.
Set these up before or after installing:
Environment variable: MCP_KEY_HOST
Environment variable: MCP_KEY_PORT
Environment variable: MCP_KEY_NAME
Environment variable: MCP_KEY_USER
Environment variable: MCP_KEY_PASS
Environment variable: MCP_KEY_SSLMODE
Add this to your MCP configuration file:
{
"mcpServers": {
"io-github-edelciomolina-postgres-mcp": {
"env": {
"MCP_KEY_HOST": "your-mcp-key-host-here",
"MCP_KEY_NAME": "your-mcp-key-name-here",
"MCP_KEY_PASS": "your-mcp-key-pass-here",
"MCP_KEY_PORT": "your-mcp-key-port-here",
"MCP_KEY_USER": "your-mcp-key-user-here",
"MCP_KEY_SSLMODE": "your-mcp-key-sslmode-here"
},
"args": [
"-y",
"@edelciomolina/postgres-mcp"
],
"command": "npx"
}
}
}From the project's GitHub README.
π English | PortuguΓͺs
This is a native MCP server built directly with @modelcontextprotocol/sdk and pg (node-postgres). It provides:
.env file at startup, so no secrets are stored in mcp.json.env variable names; tell the server which ones to use via env in mcp.jsontool=<name> args to choose exactly which MCP tools to expose.env file with the 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 required. npx downloads and runs the package on demand. Add -y as the first arg to skip the confirmation prompt.
{
"servers": {
"Postgres Tools": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@edelciomolina/postgres-mcp",
"tool=pg_manage_query",
"tool=pg_manage_schema",
"tool=pg_manage_indexes",
"tool=pg_monitor_database"
],
"env": {
"MCP_KEY_HOST": "DB_HOST",
"MCP_KEY_PORT": "DB_PORT",
"MCP_KEY_NAME": "DB_NAME",
"MCP_KEY_SSLMODE": "DB_SSLMODE",
"MCP_KEY_USER": "DB_USER",
"MCP_KEY_PASS": "DB_PASS"
}
}
}
}
VS Code supports discovering and installing MCP servers directly from the editor, without touching the terminal.
MCP: Add Serverpostgres-mcp or edelciomolinamcp.json automaticallyπ‘ You can also open the MCP Servers panel via the 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= args and env key mappings as shown in the Usage section below.
mcp.json){
"servers": {
"Postgres Tools": {
"type": "stdio",
"command": "npx",
"args": [
"@edelciomolina/postgres-mcp",
"tool=pg_manage_query",
"tool=pg_manage_schema",
"tool=pg_manage_indexes",
"tool=pg_monitor_database"
],
"env": {
"MCP_KEY_HOST": "DB_HOST",
"MCP_KEY_PORT": "DB_PORT",
"MCP_KEY_NAME": "DB_NAME",
"MCP_KEY_SSLMODE": "DB_SSLMODE",
"MCP_KEY_USER": "DB_USER",
"MCP_KEY_PASS": "DB_PASS"
}
}
}
}
The corresponding .env in your project root:
DB_HOST=db.your-project.supabase.co
DB_PORT=5432
DB_NAME=postgres
DB_SSLMODE=require
DB_USER=readonly_user
DB_PASS=your_password
mcp.json configuration worksenv - credential key mappingThe env block does not contain the actual credentials. It maps each MCP_KEY_* to the name of the variable in your .env file.
Key in env | Points to .env variable | Example value |
|---|---|---|
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 |
This indirection means you can use any variable names in your .env - useful when sharing an .env across multiple services with different naming conventions.
args - tool selection via tool= prefixEach enabled MCP tool is declared as a separate arg using the tool=<name> format:
"args": [
"-y",
"@edelciomolina/postgres-mcp",
"tool=pg_manage_schema",
"tool=pg_manage_indexes"
]
This makes the tool list explicit and auditable directly in mcp.json - no hidden config files. π
If you omit all tool= args, the server starts with a curated read-only set - every tool that can retrieve, analyze, or explain data, but nothing that can modify it.
β οΈ Excluded from defaults (write-capable, opt-in via tool= arg):
| Tool | Risk |
|---|---|
pg_execute_mutation | INSERT / UPDATE / DELETE / UPSERT operations |
pg_execute_sql | Executes arbitrary SQL with optional transaction support |
β Included in defaults:
pg_execute_query pg_manage_query pg_manage_schema
pg_manage_indexes pg_manage_constraints pg_manage_functions
pg_manage_triggers pg_manage_rls pg_get_setup_instructions
pg_manage_users pg_analyze_database pg_monitor_database
pg_debug_database
π‘
pg_execute_queryis included in the defaults but is handler-enforced read-only: the tool handler rejects anyINSERT,UPDATE,DELETE, or DDL statement and returns a permission error before the database is contacted.
β οΈ Management tools like
pg_manage_schemabundle both read and write sub-operations (e.g.get_infoandcreate_table). For strict write prevention, pair with a database user that only hasSELECTprivileges.
π‘ Tip: While this MCP is secure and customizable via tools, for maximum safety, pair the default tool set with a database user that only has
SELECTprivileges.
.env file discoveryThe server resolves the .env file in this order:
env-file=<path> arg - explicit path relative to cwd; takes priority over everything elsecwd, searches each parent directory until a .env is found or the filesystem root is reachedIf no .env is found, the server exits with a clear error message.
When VS Code starts the MCP process, cwd is typically the workspace root. If your .env lives in a subfolder (e.g. functions/.env), use env-file= to point to it explicitly:
{
"servers": {
"Postgres Tools": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@edelciomolina/postgres-mcp",
"env-file=functions/.env",
"tool=pg_manage_schema",
"tool=pg_monitor_database"
],
"env": {
"MCP_KEY_HOST": "DB_HOST",
"MCP_KEY_PORT": "DB_PORT",
"MCP_KEY_NAME": "DB_NAME",
"MCP_KEY_SSLMODE": "DB_SSLMODE",
"MCP_KEY_USER": "DB_USER",
"MCP_KEY_PASS": "DB_PASS"
}
}
}
}
π‘ The walk-up behavior handles the common case automatically. Use
env-file=when you need explicit control (CI, monorepos, Docker bind-mounts).
| Tool | Description |
|---|---|
pg_execute_query | SELECT / COUNT / EXISTS with multi-statement and write-op guards |
pg_manage_query | EXPLAIN plans, slow query analysis, pg_stat_statements |
pg_manage_schema | Schema info, create/alter tables, manage ENUMs |
pg_manage_indexes | Get, create, drop, reindex, analyze index usage |
pg_manage_constraints | Get, create, and drop constraints and foreign keys |
pg_manage_functions | Get, create, and drop functions/procedures |
pg_manage_triggers | Get, create, drop, enable/disable triggers |
pg_manage_rls | Row-Level Security policies |
pg_get_setup_instructions | Platform-specific PostgreSQL setup instructions |
pg_manage_users | User permissions, create/drop/alter users, grant/revoke |
pg_analyze_database | Performance, configuration, and storage analysis |
pg_monitor_database | Real-time connection, query, lock, and replication monitoring |
pg_debug_database | Diagnose connections, locks, performance, and replication |
tool= arg)| Tool | Description |
|---|---|
pg_execute_mutation | INSERT / UPDATE / DELETE / UPSERT with parameterized queries |
pg_execute_sql | Arbitrary SQL execution with optional transaction support |
For a deep dive into the communication flow between the MCP client, proxy, and PostgreSQL - including the full sequence diagram - see ARCHITECT.md.
MIT Β© Edelcio Molina
Be the first to review this server!
by Toleno Β· Developer Tools
Toleno Network MCP Server β Manage your Toleno mining account with Claude AI using natural language.
by mcp-marketplace Β· Developer Tools
Create, build, and publish Python MCP servers to PyPI β conversationally.
by Microsoft Β· Content & Media
Convert files (PDF, Word, Excel, images, audio) to Markdown for LLM consumption