Postgres MCP — Claude Code MCP server: PostgreSQL access
Gives your agent a map of PostgreSQL schemas and safe read-only queries. Useful when the model should read the real database instead of guessing names.
claude mcp add --env MCP_KEY_HOST=<MCP_KEY_HOST> --env MCP_KEY_PORT=<MCP_KEY_PORT> --env MCP_KEY_NAME=<MCP_KEY_NAME> --env MCP_KEY_USER=<MCP_KEY_USER> --env MCP_KEY_PASS=<MCP_KEY_PASS> --transport stdio edelciomolina-postgres-mcp -- npx -y @edelciomolina/postgres-mcpWhat Postgres MCP does
Postgres MCP is a server built on @modelcontextprotocol/sdk and pg. It assembles a map of your database for the model: schemas, tables, columns, foreign keys, links between tables, plus risk levels and which business domains the data belongs to. All of it comes from the live schema rather than being invented.
Read-only is the default: writes, DDL and arbitrary SQL stay off until you allow them yourself. The pg_classify_query_risk tool lets the model check a query for safety before running it. Credentials are resolved from .env at startup, so nothing sensitive sits in mcp.json. Each tool is opt-in through a tool=<name> argument.
You need Node.js 18 or newer and a .env file with connection details. Turn on write-capable tools but forget POSTGRES_MCP_ALLOW_WRITE=true in env, and the server exits at startup — check that before the first connection.
What it helps with
- read the real schema before writing a query
- check a query for risk before running it
- let the agent reach PostgreSQL without write access
- connect through a
DATABASE_URLconnection string - expose only the database tools you pick
Example prompts for the agent
- Show me the
orderstable schema and its foreign keys - Check this query for risk before running it
- Connect to the database and describe which domains the tables belong to
How to install Postgres MCP
Platform CLI
claude mcp add --env MCP_KEY_HOST=<MCP_KEY_HOST> --env MCP_KEY_PORT=<MCP_KEY_PORT> --env MCP_KEY_NAME=<MCP_KEY_NAME> --env MCP_KEY_USER=<MCP_KEY_USER> --env MCP_KEY_PASS=<MCP_KEY_PASS> --transport stdio edelciomolina-postgres-mcp -- npx -y @edelciomolina/postgres-mcpReplace <…> with your own values. 1 more environment variable is in the server README
Platform CLI
codex mcp add edelciomolina-postgres-mcp --env MCP_KEY_HOST=<MCP_KEY_HOST> --env MCP_KEY_PORT=<MCP_KEY_PORT> --env MCP_KEY_NAME=<MCP_KEY_NAME> --env MCP_KEY_USER=<MCP_KEY_USER> --env MCP_KEY_PASS=<MCP_KEY_PASS> -- npx -y @edelciomolina/postgres-mcpReplace <…> with your own values. 1 more environment variable is in the server README
Config file
{
"mcpServers": {
"edelciomolina-postgres-mcp": {
"command": "npx",
"args": [
"-y",
"@edelciomolina/postgres-mcp"
],
"env": {
"MCP_KEY_HOST": "<MCP_KEY_HOST>",
"MCP_KEY_PORT": "<MCP_KEY_PORT>",
"MCP_KEY_NAME": "<MCP_KEY_NAME>",
"MCP_KEY_USER": "<MCP_KEY_USER>",
"MCP_KEY_PASS": "<MCP_KEY_PASS>"
}
}
}
}Replace <…> with your own values. 1 more environment variable is in the server README
Config file
{
"servers": {
"edelciomolina-postgres-mcp": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@edelciomolina/postgres-mcp"
],
"env": {
"MCP_KEY_HOST": "<MCP_KEY_HOST>",
"MCP_KEY_PORT": "<MCP_KEY_PORT>",
"MCP_KEY_NAME": "<MCP_KEY_NAME>",
"MCP_KEY_USER": "<MCP_KEY_USER>",
"MCP_KEY_PASS": "<MCP_KEY_PASS>"
}
}
}
}Replace <…> with your own values. 1 more environment variable is in the server README
Platform CLI
gemini mcp add -e MCP_KEY_HOST=<MCP_KEY_HOST> -e MCP_KEY_PORT=<MCP_KEY_PORT> -e MCP_KEY_NAME=<MCP_KEY_NAME> -e MCP_KEY_USER=<MCP_KEY_USER> -e MCP_KEY_PASS=<MCP_KEY_PASS> edelciomolina-postgres-mcp npx -y @edelciomolina/postgres-mcpReplace <…> with your own values. 1 more environment variable is in the server README
Step by step, with commands for each platform: How to add an MCP server to Claude Code, Codex, Cursor, VS Code, Gemini CLI and more
Questions about Postgres MCP
How do I install Postgres MCP in Claude Code?
Run claude mcp add postgres-mcp -- npx -y @edelciomolina/postgres-mcp. For custom key mappings, use the second command with `--env MCP_KEY_HOST=<MCP_KEY_HOST> --env MCP_KEY_PORT=<MCP_KEY_PORT> --env MCP_KEY_NAME=<MCP_KEY_NAME> --env MCP_KEY_USER=<MCP_KEY_USER> --env MCP_KEY_PASS=<MCP_KEY_PASS> --transport stdio edelciomolina-postgres-mcp -- npx -y @edelciomolina/postgres-mcp`.
What does Postgres MCP do?
It builds a map of PostgreSQL schemas, tables, columns and relations for the model, and provides tools to work with the database. Only reading is available by default.
Do I need extra setup to write to the database?
Yes. Write-capable tools are enabled explicitly with tool=<name>, and without POSTGRES_MCP_ALLOW_WRITE=true in env the server will not start.