{
  "markdown": "# mcp-server-postgres\n\n[![npm version](https://img.shields.io/npm/v/mcp-pg-server.svg)](https://www.npmjs.com/package/mcp-pg-server)\n[![npm downloads](https://img.shields.io/npm/dm/mcp-pg-server.svg)](https://www.npmjs.com/package/mcp-pg-server)\n[![CI](https://github.com/ofershap/mcp-server-postgres/actions/workflows/ci.yml/badge.svg)](https://github.com/ofershap/mcp-server-postgres/actions/workflows/ci.yml)\n[![TypeScript](https://img.shields.io/badge/TypeScript-strict-blue.svg)](https://www.typescriptlang.org/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nQuery 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.\n\n```bash\nDATABASE_URL=postgres://user:pass@localhost:5432/mydb npx mcp-pg-server\n```\n\n> Works with Claude Desktop, Cursor, VS Code Copilot, and any MCP client. Connects via `DATABASE_URL` or per-call `connectionString`.\n\n## Why\n\nPostgres 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.\n\n## Tools\n\n| Tool           | What it does                                                                  |\n| -------------- | ----------------------------------------------------------------------------- |\n| `query`        | Execute SQL (SELECT, WITH, EXPLAIN, SHOW, ANALYZE). Returns a text table.     |\n| `schema`       | Tables in a schema (default `public`) with columns and approximate row counts |\n| `table_info`   | One table: columns, types, null/default, PK, exact row count                  |\n| `explain`      | EXPLAIN (FORMAT TEXT), optional ANALYZE                                       |\n| `list_schemas` | List non-system schemas                                                       |\n\n## Quick Start\n\n### Cursor\n\nAdd to `.cursor/mcp.json`:\n\n```json\n{\n  \"mcpServers\": {\n    \"postgres\": {\n      \"command\": \"npx\",\n      \"args\": [\"mcp-pg-server\"],\n      \"env\": {\n        \"DATABASE_URL\": \"postgres://user:pass@localhost:5432/mydb\"\n      }\n    }\n  }\n}\n```\n\n### Claude Desktop\n\nAdd to `claude_desktop_config.json` (macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`):\n\n```json\n{\n  \"mcpServers\": {\n    \"postgres\": {\n      \"command\": \"npx\",\n      \"args\": [\"mcp-pg-server\"],\n      \"env\": {\n        \"DATABASE_URL\": \"postgres://user:pass@localhost:5432/mydb\"\n      }\n    }\n  }\n}\n```\n\n### VS Code\n\nConfigure the MCP server in your VS Code settings to run `npx mcp-pg-server` with `DATABASE_URL` set.\n\n## Example prompts\n\n- \"Show me the schema of the public tables\"\n- \"Query users: SELECT * FROM users LIMIT 10\"\n- \"Explain this join query\"\n- \"What schemas exist in this database?\"\n- \"How many rows are in the orders table?\"\n\n## Safety\n\nRead-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.\n\nPass `connectionString` on any tool to override `DATABASE_URL` for a single call.\n\n## Development\n\n```bash\nnpm install\nnpm run typecheck\nnpm run build\nnpm test\nnpm run format\nnpm run lint\n```\n\n## See also\n\nMore MCP servers and developer tools on my [portfolio](https://gitshow.dev/ofershap).\n\n## Author\n\n[![Made by ofershap](https://gitshow.dev/api/card/ofershap)](https://gitshow.dev/ofershap)\n\n[![LinkedIn](https://img.shields.io/badge/LinkedIn-Connect-0A66C2?style=flat&logo=linkedin&logoColor=white)](https://linkedin.com/in/ofershap)\n[![GitHub](https://img.shields.io/badge/GitHub-Follow-181717?style=flat&logo=github&logoColor=white)](https://github.com/ofershap)\n\n## License\n\nMIT © 2026 Ofer Shapira\n",
  "bytes": 3945,
  "sha": "bc047ef2997abb75f902caa7a8641855e6b71fac3652cf5c020e72d337764222",
  "repo_slug": "ofershap/mcp-server-postgres",
  "fonte": "repo",
  "truncated": false,
  "api": "https://agentalog.com/api/listings/mcp_io_github_ofershap_postgres_99c770c8/readme"
}