mcp-server-postgres
Query PostgreSQL databases, inspect schemas, and explain query plans from an AI assistant.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mcp-server-postgresShow me the schema of the users table"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
mcp-server-postgres
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-serverWorks with Claude Desktop, Cursor, VS Code Copilot, and any MCP client. Connects via
DATABASE_URLor per-callconnectionString.
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.
Related MCP server: Postgres Scout MCP
Tools
Tool | What it does |
| Execute SQL (SELECT, WITH, EXPLAIN, SHOW, ANALYZE). Returns a text table. |
| Tables in a schema (default |
| One table: columns, types, null/default, PK, exact row count |
| EXPLAIN (FORMAT TEXT), optional ANALYZE |
| List 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 lintSee also
More MCP servers and developer tools on my portfolio.
Author
License
MIT © 2026 Ofer Shapira
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- FlicenseAqualityDmaintenanceEnables AI assistants to interact with PostgreSQL databases using natural language queries, providing secure read-only access to database schemas and SQL translation capabilities.610
- Alicense-qualityDmaintenanceEnables AI assistants to safely explore, analyze, and maintain PostgreSQL databases with read-only mode by default, SQL injection prevention, query performance analysis, and optional write operations.64Apache 2.0
- Alicense-quality-maintenanceProvides AI assistants with safe, controlled access to PostgreSQL databases with read-only defaults, granular permissions, query safety features, and schema introspection capabilities.1
- FlicenseAqualityDmaintenanceEnables AI agents to inspect and query PostgreSQL databases safely, with features like listing tables, retrieving schemas, and running read-only SQL queries.3
Related MCP Connectors
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Comprehensive PostgreSQL documentation and best practices, including ecosystem tools
Read-only bank access for your AI agent. Connects Claude, ChatGPT, Cursor, Gemini, Codex.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/ofershap/mcp-server-postgres'
If you have feedback or need assistance with the MCP directory API, please join our Discord server