Sponsored byOutsenseAI that finds your next clients
SponsorGROUOutbound, LinkedIn content and leads for B2B teamsSponsorOutsenseAI that finds your next clientsAd+Your tool hereSeen by people installing AI tools@Weekly picksThe best new tools, one email a week

PostgreSQL MCP Server

MCP server by YawLabs Community

Lets AI assistants like Claude Code and Cursor query PostgreSQL databases. It adds schema introspection, EXPLAIN plans, performance diagnostics and health checks, and is read-only by default.

  • Score 86
  • 12 stars
  • 4.1k a week
  • MIT
  • Updated

Install PostgreSQL MCP Server

Built from the published package, never by AI.

claude mcp add postgresql-mcp-server -- npx -y @yawlabs/postgres-mcp

Run in your terminal. Add --scope user to use it in every project.

Step-by-step: install PostgreSQL MCP Server in Claude Code

MCP servers run with your permissions and can read what you give them access to. Some need an API key: check the README and add it under env in the postgresql-mcp-server block.

About

@yawlabs/postgres-mcp is an MCP server that lets Claude Code, Cursor and other MCP clients query a PostgreSQL database. It provides schema introspection, EXPLAIN plans, performance diagnostics, role and privilege checks and a health snapshot. Writes are off by default and need ALLOW_WRITES=1. Large results are capped at 1000 rows by default.

The server ships as a single bundled file with zero runtime dependencies. User SQL runs in a BEGIN READ ONLY transaction using the extended query protocol, which allows one statement per request. The README recommends a least-privileged database role as the main access control. It is aimed at developers who want an AI assistant to work against an existing Postgres database.

Written from the project's README and checked against it.

Tools it gives your assistant

  • pg_queryRuns user SQL with parameters in a read-only transaction, or with writes if ALLOW_WRITES=1 is set.
  • pg_readonlyRuns SQL in a BEGIN READ ONLY transaction regardless of the ALLOW_WRITES setting.
  • pg_explainReturns a query plan in text or JSON format, with optional ANALYZE.
  • pg_index_advisorRecommends indexes for a workload using HypoPG hypothetical indexes, without creating them.
  • pg_list_schemasLists schemas in the database.
  • pg_list_tablesLists tables in the database.
  • pg_describe_tableReturns columns, primary keys, foreign keys and indexes for a table.
  • pg_top_queriesShows top queries from pg_stat_statements to help answer why a query is slow.
  • pg_healthReturns version, database size, connection counts and the 10 longest-running active queries.
  • pg_table_privilegesShows table privileges for role and access questions.

What you need

  • Node.js 22 or later
  • A PostgreSQL database with a DATABASE_URL connection string
  • An MCP client such as Claude Code or Cursor
  • On Windows, the cmd /c wrapper shown in the quick start

Try asking

  • Show me the tables and foreign keys in the public schema.
  • Explain the query plan for this slow SELECT statement.
  • Run a health check on the database and list long-running queries.

Good to know

  • Read-only by default. Writes need ALLOW_WRITES=1.
  • Results are capped at POSTGRES_MAX_ROWS, which defaults to 1000 rows.
  • pg_readonly still allows functions such as pg_terminate_backend if the database role has the privilege, so the role is the real control.
  • Audit logging is opt-in and does not record a complete history.

Security check

A

No download-and-run commands, hidden instructions or signs of sending keys out were found.

Checked automatically: README.md, package.json. This looks for known risky patterns and is not a full audit. How grades work

Alternatives to PostgreSQL MCP Server

All alternatives →
Supabase supabase
97

Connects Supabase projects to AI assistants such as Cursor, Claude and Windsurf over the Model Context Protocol. It lets assistants manage tables, fetch config and query data in a Supabase project.

AAA Local and remote 172k/wk
ArcadeDB MCP Server ArcadeData
94

ArcadeDB MCP Server is the built-in Model Context Protocol server of the ArcadeDB multi-model database. It lets AI assistants and LLMs work with ArcadeDB's graph, document, time-series, vector and other data models. It suits people who already run ArcadeDB and want assistant access to it.

AAA Local 1.3k
DBHubbytebase
94

Connects MCP clients such as Claude Desktop, Cursor and VS Code to PostgreSQL, MySQL, MariaDB, SQL Server, Oracle, ClickHouse and SQLite. It exposes two tools by default, with read-only mode and query timeouts available as guardrails.

AAA Local 343k/wk
MCP Toolbox for Databasesgoogleapis
94

MCP Toolbox for Databases is an open source MCP server that connects AI agents, IDEs and applications to enterprise databases. It provides prebuilt tools for exploring schemas and running queries, plus a framework for custom tools. It is aimed at developers building agents that need database access.

AAA Local 17k
MCP Toolbox for Databasesgoogleapis
94

Connects AI agents, IDEs and applications to enterprise databases through the Model Context Protocol. Offers prebuilt database tools for MCP clients and a framework for building custom tools for production agents.

AAA Local 17k
mongodb-mcp-servermongodb-js
94

MongoDB MCP Server lets AI assistants interact with MongoDB databases and MongoDB Atlas. It is an official server from mongodb-js, run locally with npx or Docker. It works with self-managed deployments and Atlas clusters.

AAA Local 203k/wk

Compare with Supabase, ArcadeDB MCP Server or DBHub

PostgreSQL MCP Server: common questions

Is the PostgreSQL MCP server read-only?

Yes by default. User SQL runs in a BEGIN READ ONLY transaction, and writes require ALLOW_WRITES=1. The README recommends a least-privileged database role as the main access control.

Which AI assistants work with this server?

The README says it works with Claude Code, Cursor and any MCP client.

How does it compare to the archived Anthropic Postgres MCP server?

The README says it was written from scratch and is actively maintained, and it describes the reference server as archived and deprecated with a known stacked-query SQL injection.

How do I install PostgreSQL MCP Server?

In Claude Code run claude mcp add postgresql-mcp-server -- npx -y @yawlabs/postgres-mcp. For Claude Desktop, Cursor and VS Code, paste the config shown above and restart. See the install guides.

Is PostgreSQL MCP Server the official server?

PostgreSQL MCP Server is a community project by YawLabs, not verified by a company domain.

Is PostgreSQL MCP Server free?

The code is published under the MIT licence. The service it connects to may have its own pricing.

Is PostgreSQL MCP Server safe to use?

It scores 86 of 100. Grades: maintenance A, licence A, quality C. Security check: grade A, no risky patterns found in the files checked. Review the code before you install. How grades work.

What are alternatives to PostgreSQL MCP Server?

Similar MCP servers: Supabase, ArcadeDB MCP Server, DBHub, MCP Toolbox for Databases.

Does PostgreSQL MCP Server work with ChatGPT?

Not directly. It runs locally, and ChatGPT only connects to remote servers with a URL. Use it in Claude Code, Claude Desktop, Cursor, VS Code or Codex.

PostgreSQL MCP Server Install

Add to stack

Loading.