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.
Install PostgreSQL MCP Server
Built from the published package, never by AI.
claude mcp add postgresql-mcp-server -- npx -y @yawlabs/postgres-mcpRun in your terminal. Add --scope user to use it in every project.
{
"mcpServers": {
"postgresql-mcp-server": {
"args": [
"-y",
"@yawlabs/postgres-mcp"
],
"command": "npx"
}
}
}Settings, Developer, Edit config. Paste into claude_desktop_config.json and restart.
Step-by-step: install PostgreSQL MCP Server in Claude Desktop
{
"mcpServers": {
"postgresql-mcp-server": {
"args": [
"-y",
"@yawlabs/postgres-mcp"
],
"command": "npx"
}
}
}Add to ~/.cursor/mcp.json (all projects) or .cursor/mcp.json (this project).
{
"servers": {
"postgresql-mcp-server": {
"args": [
"-y",
"@yawlabs/postgres-mcp"
],
"command": "npx"
}
}
}Add to .vscode/mcp.json. VS Code uses "servers", not "mcpServers".
codex mcp add postgresql-mcp-server -- npx -y @yawlabs/postgres-mcp{
"mcpServers": {
"postgresql-mcp-server": {
"args": [
"-y",
"@yawlabs/postgres-mcp"
],
"command": "npx"
}
}
}Add to ~/.gemini/config/mcp_config.json (all projects) or .agents/mcp_config.json (this project).
Step-by-step: install PostgreSQL MCP Server in Antigravity CLI
gemini mcp add postgresql-mcp-server npx -y @yawlabs/postgres-mcpGemini CLI was replaced by Antigravity CLI in June 2026 and remains only for enterprise licences and paid API keys.
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
ANo 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 →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.
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.
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.
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.
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.
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.
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.
