Skip to main content
MCP server CX Codex

PostgreSQL — Claude Code MCP server: what it does, how to install

Connects AI assistants to PostgreSQL instances locally or in cloud providers like Neon and RDS. Inspect table schemas and run read-only queries from chat.

Install into Claude Code · Platform CLI All methods and platforms ↓
claude mcp add --env DATABASE_URL=<DATABASE_URL> --env PG_HOST=<PG_HOST> --env PG_PORT=<PG_PORT> --env PG_USER=<PG_USER> --env PG_PASSWORD=<PG_PASSWORD> --transport stdio postgresql -- npx -y mcp-postgres-server
Open on GitHub

What PostgreSQL does

The server runs via npx over stdio and needs Node.js 20 or newer. It keeps dependencies minimal, relying on pg, zod, and pg-connection-string. A single DATABASE_URL is enough for setup, though discrete host and port variables are also supported.

Safety is the default. In read-only mode, queries run inside a BEGIN READ ONLY block followed by ROLLBACK, guaranteeing that writes cannot slip through. The agent inspects schemas and fetches column details with tools like describe_table and list_tables.

Write operations stay blocked. Unless PG_ALLOW_WRITE is explicitly set to true, the execute tool refuses to run any mutating statements.

What it helps with

  • inspect database tables and column types
  • run read-only SQL queries with bound parameters
  • connect your coding agent to Neon or Docker databases
  • safely explore production schemas without accidental writes

Example prompts for the agent

  • List all available tables in the public schema.
  • Describe the structure and columns of the users table.
  • Run SELECT id, name FROM users WHERE email = $1 with parameter [email protected].

How to install PostgreSQL

Platform CLI

claude mcp add --env DATABASE_URL=<DATABASE_URL> --env PG_HOST=<PG_HOST> --env PG_PORT=<PG_PORT> --env PG_USER=<PG_USER> --env PG_PASSWORD=<PG_PASSWORD> --transport stdio postgresql -- npx -y mcp-postgres-server

Replace <…> with your own values. 17 more environment variables are 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 PostgreSQL

How to install PostgreSQL in Claude Code?

Run `claude mcp add --env DATABASE_URL=<DATABASE_URL> --env PG_HOST=<PG_HOST> --env PG_PORT=<PG_PORT> --env PG_USER=<PG_USER> --env PG_PASSWORD=<PG_PASSWORD> --transport stdio postgresql -- npx -y mcp-postgres-server` in your terminal.

What does the PostgreSQL MCP server do?

It lets MCP clients inspect database schemas, read table structures, and run parameterized SQL statements over stdio.

Can the model modify database records?

Not by default. Writes are forbidden and rejected until you enable PG_ALLOW_WRITE="true" in the environment.

Similar MCP servers

All MCP servers for Data and databases →

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor