pg-mcp-server

MCP server for PostgreSQL: an agent runs SQL and sees tables and schemas, with writes off until you explicitly allow them

  • 179 ★ on the repository
  • Last commit
  • MIT
MCP server

Extended access

Why this level

  • The agent runs arbitrary SQL through the connection string you pass and the results go into the model's context
  • The `DANGEROUSLY_ALLOW_WRITE_OPS` variable enables writing and deleting data
All reasons and checks

ericzakariasson/pg-mcp-server

Install

In your terminal, with SkillFoxx CLI

npx skillfoxx add mcp/ericzakariasson-pg-mcp-server

Detects the agents on your machine, shows the access level and pins the version.

Other ways to install

Access and checks

How we review

Extended accessThe tool runs code or makes network calls and only reads external data.

  • The agent runs arbitrary SQL through the connection string you pass and the results go into the model's context
  • The `DANGEROUSLY_ALLOW_WRITE_OPS` variable enables writing and deleting data

This is third-party code. Review the repository files before installing.

What it does

pg-mcp-server gives an agent a PostgreSQL database through one `query` tool that runs an SQL query. Two resources complement it: `postgres://tables` lists tables and `postgres://table/{schema}/{table}` returns a table's schema and sample data. Writes are off by default and the `DANGEROUSLY_ALLOW_WRITE_OPS` variable enables them. The server runs over stdio and over HTTP: with `--transport=http` it listens at `/mcp` on port 3000 by default. For TLS you can point `PG_SSL_ROOT_CERT` at a root certificate, for example the AWS RDS bundle. The repository holds a Cursor rule for working with notebooks alongside the server, and `docker-compose.yml` starts a test PostgreSQL with the tables users, products, orders and order_items and a `bun run inspector` command for checks through MCP Inspector.

Who it is for. Analysts and backend developers who want to let Cursor or Claude Code read a production or test PostgreSQL without third-party hosting.

Good fit when

  • You need to quickly find out how many active users are in the users table without opening a database client
  • An agent studies an unfamiliar schema and should see tables and sample rows before writing a query
  • Data analysis happens in a Cursor notebook and relies on SQL against the database
  • Connecting to AWS RDS needs a root certificate that you can pass with a variable
  • You need the server over HTTP for a client that cannot launch stdio processes

Not a fit when

  • You need EXPLAIN plans, index tuning and database health checks: richer servers exist for that
  • The agent must work with several databases through one connection: here there is a single DATABASE_URL
  • The database holds personal data and policy forbids sending it to a model
  • You need precise SQL parsing with a table allowlist: there is one tool and the query is arbitrary

Example request

Show the database tables and the schema of orders, then list the five latest orders with customer names.

MCP

Transport
stdio, http
Authentication
not required

Environment variables

DATABASE_URL required, secret
PostgreSQL connection string
DANGEROUSLY_ALLOW_WRITE_OPS
Enables writes to the database, false by default
DEBUG
Enables debug logging, false by default
PG_SSL_ROOT_CERT
Path to a TLS root certificate, for example the AWS RDS bundle
PORT
Port for HTTP mode, 3000 by default

Limitations

  • There is one DATABASE_URL connection string and one `query` tool. No EXPLAIN plans or index hints.
  • Writes are enabled with the `DANGEROUSLY_ALLOW_WRITE_OPS` variable. Enable them only on a test database and connect production with a read-only user.
  • Query results go into the model's context: limit large selections with `LIMIT`.
  • Running needs Node.js, and building from source needs Bun.

How to disable. Remove the postgres block from your MCP client configuration. For the sample database stop Docker with `bun run db:stop`.

FAQ

How do I install pg-mcp-server in Cursor?

Use the install button in the README or add an MCP settings block with command npx and arguments `--yes pg-mcp-server --transport stdio`. The env needs a DATABASE_URL variable with the connection string.

Can the agent modify data in the database?

Not by default: writes are off. The `DANGEROUSLY_ALLOW_WRITE_OPS` variable enables them and its default is false. If you turn them on, do it on a test database.

How do I run the server over HTTP?

Add the `--transport=http` flag: the server serves Streamable HTTP at `/mcp` on port 3000 and the client connects to `http://localhost:3000/mcp`. The PORT variable changes the port.

How do I test the server without my own database?

The repository has a `docker-compose.yml` with a sample PostgreSQL. `bun run db:start` starts it with the tables users, products, orders and order_items, and `bun run inspector` opens MCP Inspector.

What resources does the server expose besides the tool?

Two: `postgres://tables` with a list of tables and `postgres://table/{schema}/{table}` with the schema and sample data of the chosen table.

Discussion

No questions or reviews yet.

A Go MCP server that lets an agent ask a PostgreSQL database questions in plain language and returns the query result

MCP serverExtended access542Repository stars

An MCP server for PostgreSQL with several databases at once, table descriptions from the catalog, PostGIS and pgvector hints and query plans

MCP serverExtended access541Repository stars

pgEdge Postgres MCP

pgEdge Postgres MCP Server

Postgres MCP in Go with read-mode queries, EXPLAIN plans, semantic search, several databases and a ready chat client and web interface

MCP serverExtended access246Repository stars

Postgres MCP (Microsoft)

Postgres MCP Server (Microsoft)

Postgres MCP from Microsoft: connection profiles with passwords in the OS keyring, Entra ID sign-in for Azure, queries, schema, CSV and server metrics

MCP serverBroad access86Repository stars

One MCP server for SQLite, SQL Server, PostgreSQL and MySQL: read and change data, edit schemas and export to CSV and JSON

MCP serverBroad access391Repository stars
Official

An MCP server and skills from TigerData that help agents write PostgreSQL schemas and queries from current docs and practices

MCP serverExtended access1.9KRepository stars

Comparison with similar tools

Cards that share the main search query, and how they differ.

ToolOfficialAuthenticationRepository starsMain difference
pg-mcp-server (this card)nonot required179
Postgres MCP PronoAPI key3,472a server with EXPLAIN plans, index tuning and health checks, while this one is simpler and limited to a single query tool
PG-MCP Servernonot required541a same-named MCP server by a different author; this is a separate project launched through npx with an HTTP mode

README in short

The README is short: a one-click Cursor install and a JSON snippet, the environment variables, stdio and HTTP modes, the tool and resources and a sample prompt. It continues with a Cursor rule for notebooks, a Docker quick start, development commands and the npm release process.

README badge

Report a problem