mcpField
P
postgres

postgres

Local
github.com/ofershapDatabases0Updated 11w ago

About postgres

postgres is an MCP server for querying PostgreSQL databases and inspecting their structure, aimed at local and development workflows. It is read-only by default, with an option to enable writes when needed.

Key features

  1. 01Run SQL queries in read-only mode by default
  2. 02List schemas and inspect tables
  3. 03View columns, types, keys, and row counts
  4. 04Explain query plans with optional ANALYZE
  5. 05Override the database connection per call

Use cases

  1. 01Explore a local or development database schema
  2. 02Check table columns and row counts
  3. 03Inspect a query plan while working in an IDE
  4. 04Enable writes for database changes when needed

MCP support

Provides PostgreSQL query, schema, table, and explain tools to MCP clients. It connects using DATABASE_URL or a per-call connectionString, and defaults to read-only queries.

Configuration

Local server config is the same for every client. Copy it into your client’s MCP config file.

mcp.json · Universal config
{
"mcpServers": {
"ofershap-postgres": {
"command": "npx",
"args": [
"-y",
"mcp-pg-server"
]
}
}
}
Run commandnpx -y mcp-pg-server

Local servers need a runtime on your machine (e.g. Node.js 18+). Config file locations differ by client; see your client’s docs.

Packages
npmmcp-pg-server1.0.0

Tools

No tool list yet

Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.

Details

From the project README

mcp-server-postgres

npm version npm downloads CI TypeScript License: MIT

Query PostgreSQL, inspect schemas, and explain queries from your AI assistant. A daily-driver MCP for local and dev Postgres — same belt as docker and sqlite servers, not an enterprise DBA suite.

DATABASE_URL=postgres://user:pass@localhost:5432/mydb npx mcp-pg-server

Works with Claude Desktop, Cursor, VS Code Copilot, and any MCP client. Connects via DATABASE_URL or per-call connectionString.

Why

Postgres is the default for most new backends, local dev stacks, and agent workflows that need a real SQL database. You already run it in Docker or on localhost — this server lets your assistant query it, read schemas, and explain plans without leaving the IDE. Read-only by default so exploration stays safe; opt into writes when you need them.

Tools

ToolWhat it does
queryExecute SQL (SELECT, WITH, EXPLAIN, SHOW, ANALYZE). Returns a text table.
schemaTables in a schema (default public) with columns and approximate row counts
table_infoOne table: columns, types, null/default, PK, exact row count
explainEXPLAIN (FORMAT TEXT), optional ANALYZE
list_schemasList non-system schemas

Quick Start

Cursor

Add to .cursor/mcp.json:

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": ["mcp-pg-server"],
      "env": {
        "DATABASE_URL": "postgres://user:pass@localhost:5432/mydb"
      }
    }
  }
}
Claude Desktop

Add to claude_desktop_config.json (macOS: ~/Library/Application Support/Claude/claude_desktop_config.json):

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": ["mcp-pg-server"],
      "env": {
        "DATABASE_URL": "postgres://user:pass@localhost:5432/mydb"
      }
    }
  }
}
VS Code

Configure the MCP server in your VS Code settings to run npx mcp-pg-server with DATABASE_URL set.

Example prompts

  • "Show me the schema of the public tables"
  • "Query users: SELECT * FROM users LIMIT 10"
  • "Explain this join query"
  • "What schemas exist in this database?"
  • "How many rows are in the orders table?"

Safety

Read-only by default. The query tool accepts only SELECT, WITH, EXPLAIN, SHOW, and ANALYZE in readonly mode. Set readonly=false to enable INSERT, UPDATE, DELETE, and DDL.

Pass connectionString on any tool to override DATABASE_URL for a single call.

Development

npm install
npm run typecheck
npm run build
npm test
npm run format
npm run lint

See also

More MCP servers and developer tools on my portfolio.

Author

Made by ofershap

LinkedIn GitHub

License

MIT © 2026 Ofer Shapira

Comments

Markdown supported

New to MCP?

From what the protocol is to installing your first server, these answers cover most first questions.

An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.