mcp-postgres-serverBLOCK
MCP server for PostgreSQL. Works with VS Code, Cursor, Claude Code, Codex, and Windsurf.
Overview
From the repository's own README, as read at the audited commit. Badges and raw HTML are left out.
[](https://www.npmjs.com/package/mcp-postgres-server) [](https://github.com/antonorlov/mcp-postgres-server/actions/workflows/ci.yml)
A Model Context Protocol (MCP) server for PostgreSQL: local, Docker, RDS, Neon, and Supabase databases.
The server is small and auditable, with four runtime dependencies: the MCP SDK, pg, pg-connection-string, and zod (plus ssh2, an optional dependency used only for SSH tunneling).
Requires Node.js 20 or newer.
Quick start
The preferred way to configure the server is a single DATABASE_URL:
{
"mcpServers": {
"postgres": {
"type": "stdio",
"command": "npx",
"args": ["-y", "mcp-postgres-server"],
"env": {
"DATABASE_URL": "postgres://user:password@localhost:5432/mydb",
"PG_ALLOW_WRITE": "false"
}
}
}
}With PG_ALLOW_WRITE set to "false" the server has read-only access to the database. This is the default; set it to "true" only if the model must write.
The same JSON works in any MCP client that speaks stdio: VS Code, Cursor, Claude Code, Codex, Windsurf.
Alternatively, set the individual PG_* variables; they are used when DATABASE_URL is not set:
{
"mcpServers": {
"postgres": {
"type": "stdio",
"command": "npx",
"args": ["-y", "mcp-postgres-server"],
"env": {
"PG_HOST": "your_host",
"PG_PORT": "5432",
"PG_USER": "your_user",
"PG_PASSWORD": "your_password",
"PG_DATABASE": "your_database",
"PG_ALLOW_WRITE": "false"
}
}
}
}Manual Installation
npm install mcp-postgres-server
Or run directly with:
npx mcp-postgres-server
Connect to your database
Local Postgres:
DATABASE_URL=postgres://mcp_readonly:secret@localhost
4971cd6e29e7OBSERVED · 2026-10-12Connect
Built from this server's own package name, version and transport as found in its source — not copied from anyone's documentation, so it cannot drift against a page we do not control. Replace the environment placeholders with a token scoped to the least it needs.
claude mcp add mcp-postgres-server --env DATABASE_URL=${DATABASE_URL} --env PG_PASSWORD=${PG_PASSWORD} -- npx -y [email protected]Exposed tools (6)
5 read · 1 write · 0 destructive.
| Tool | Risk | Description |
|---|---|---|
connect_db | read | |
describe_table | read | |
execute | write | |
list_schemas | read | |
list_tables | read | |
query | read |
Trust audit
BLOCKgrade D · trust 68/100 Do not install this without reading the findings. The audit found something that could harm you or your machine.
| Layer | What it checks | Result |
|---|---|---|
| L0 | Provenance & inventory | PASS |
| L1 | Static analysis of the code | FAIL |
| L2 | Instruction surface (what it tells the agent) | PASS |
| L3 | Class-specific surface | PASS |
| L4 | Behavioural (sandbox) | SKIPPED |
What the source does
- Filesystem
- declared (3 observation(s))
- Network
- none-observed
- Shell
- none-observed
- Dependencies
- not all pinned
- Secrets in source
- found
Findings (17)
const FINGERPRINT_HINT = 'get it with ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub (on the bastion) or ssh-keygen -lF host (from ~/.ssh/known_hosts)';
for (const name of ['id_ed25519', 'id_rsa', 'id_ecdsa']) {throw new ConnectionError('SSH_CONFIG_INVALID', 'SSH authentication required: set PG_SSH_PRIVATE_KEY, PG_SSH_AGENT, or PG_SSH_PASSWORD, or provide a default key (~/.ssh/id_ed25519) or a running agentPG_TEST_URL: postgres://postgres:postgres@localhost:5432/mcp_test
DATABASE_URL=postgres://mcp_readonly:secret@localhost:5432/mydb
DATABASE_URL=postgres://mcp_readonly:[email protected]:5432/mydb
"DATABASE_URL": "postgres://mcp_readonly:[email protected]:5432/mydb?sslmode=verify-full",
const { proc, handlers, exited } = fakeProcess({ DATABASE_URL: 'postgres://u:p@h:5432/d' });.mcpbignore
const KEY_PATH = join(dir, 'id_ed25519');
writeFileSync(join(HOME_WITH_KEY, '.ssh', 'id_ed25519'), 'DEFAULT-KEY-BYTES');
expect(sslForTunnel({ rejectUnauthorized: false }, 'db.example.com')).toEqual({ ssl: { rejectUnauthorized: false, servername: 'db.example.com' } });expect(cfg.ssl).toEqual({ rejectUnauthorized: false });expect(on.ssl).toEqual({ rejectUnauthorized: false });expect(bare.ssl).toEqual({ rejectUnauthorized: false });expect(loadConfig({ PG_HOST: 'h', PG_SSLMODE: 'prefer' }).ssl).toEqual({ rejectUnauthorized: false });@modelcontextprotocol/sdk, pg, pg-connection-string, zod, @types/node, @types/pg, @types/ssh2, @vitest/coverage-v8
Gates applied: no_behavioural_pass.
4971cd6e29e7full audit observations/trust-audit/mcp-server/antonorlov__mcp-postgres-server.json · Report an issue / request a re-scanAudit history
Every audit this server has had. A grade with a past is a grade somebody is still checking.
| Date | Source | Verdict | Grade | Score | Change |
|---|---|---|---|---|---|
| 2026-10-12 | 4971cd6e29e7 | BLOCK | D | 68 | first audit |
Questions
What is the mcp-postgres-server MCP server?
MCP server for PostgreSQL. Works with VS Code, Cursor, Claude Code, Codex, and Windsurf.
What tools does mcp-postgres-server expose?
6 in total: 5 read-only, 1 that write, and 0 that can delete or overwrite. Every one is listed on this page with its risk.
Is mcp-postgres-server safe to connect to an agent?
No — not without reading the findings first. The audit graded it D (68/100) and found 3 critical or high issues in the source. Each one is listed on this page with the file and line it is on.
What credentials does mcp-postgres-server need?
It reads DATABASE_URL and PG_PASSWORD from the environment. Give it a token scoped to the least it needs — an agent that can be talked into calling a tool can be talked into calling it with your credentials.
How does mcp-postgres-server run?
It speaks stdio, so it runs as a local process your client starts. It is published on npm as mcp-postgres-server at 0.3.1.
How current is this page?
The grade is for one exact copy of the source (4971cd6e29e7), read on 2026-10-12. The repository is watched and re-audited when it changes.