Connects to a PostgreSQL database to explore schemas, query data using natural language, analyze table statistics, and optionally perform write operations.
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., "@PostgreSQL MCP Server for Claude DesktopDescribe the users table and show me 5 sample rows."
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.
π PostgreSQL MCP Server for Claude Desktop
Connect Claude Desktop to your PostgreSQL database using the Model Context Protocol (MCP). Ask Claude questions in plain English and it will query your database, explore schemas, and analyze data β no SQL required.
β¨ Features
Category | Tools |
ποΈ Database Info |
|
π Schema Exploration |
|
π Querying |
|
βοΈ Write Operations |
|
π Resources |
|
π¬ Prompts |
|
π Quick Start
1. Clone the Repository
2. Create a Virtual Environment
3. Install Dependencies
4. Configure Your Database
Edit .env with your PostgreSQL credentials:
All credentials live only in β they are never put in the Claude Desktop config file.
5. Test the Server
You should see:
Press Ctrl+C to stop.
6. Connect to Claude Desktop
Find your Claude Desktop config file:
OS | Path |
Windows |
|
macOS |
|
Linux |
|
Add the to the mcpServers section (update the path):
Note: No DB credentials go in this file. The server reads them automatically from your
.envfile usingpython-dotenv.
Restart Claude Desktop after saving the config.
π¬ Example Conversations with Claude
Once connected, try asking Claude:
π§ Tool Reference
Database Info
Tool | Description |
| PostgreSQL version, DB size, connection count, server info |
| All databases on the server with sizes and encoding |
Schema Exploration
Tool | Description |
| All user-defined schemas in the connected database |
| Tables in a schema with row counts and sizes |
| Columns, types, nullable, defaults, PKs, FKs |
| Find tables/columns by keyword (case-insensitive) |
| Indexes on a table with type and columns |
Querying
Tool | Description |
| Read-only SELECT (enforced via read-only transaction) |
| Sample rows from a table (max 100) |
| Row counts, sizes, vacuum/analyze timestamps |
| EXPLAIN execution plan (no data modification) |
Write Operations
Tool | Description |
| INSERT/UPDATE/DELETE β requires |
π Security
Read-only by default β write operations require explicit opt-in in
.envCredentials in β never in the Claude Desktop config
Read-only transactions β SELECT queries run inside
readonly=TruetransactionsInput validation β table/schema names validated with regex to prevent injection
No DDL β DROP, CREATE, ALTER are always blocked even when writes are enabled
.envβ credentials never committed
π Project Structure
βοΈ Environment Variables
All configuration is done via .env:
Variable | Default | Description |
|
| PostgreSQL host |
|
| PostgreSQL port |
| β | Database name |
| β | Database user |
| β | Database password |
|
| Min pool connections |
|
| Max pool connections |
|
| Enable INSERT/UPDATE/DELETE |
|
| Logging level (DEBUG/INFO/WARNING) |
π οΈ Troubleshooting
Claude doesn't see the MCP server
Fully quit and reopen Claude Desktop after editing the config
Check the
cwdpath β it must point to the project folderVerify the
.venvPython path is correct:.venv\Scripts\python.exe
Connection refused / authentication failed
Check your
.envcredentials match your PostgreSQL setupTest directly:
psql -h localhost -U your_user -d your_dbEnsure PostgreSQL is running:
pg_isready
mcp or asyncpg module not found
Server starts but tools don't appear in Claude
Open Claude Desktop β Settings β Developer β MCP Servers
Check for error messages next to the
postgresserver entryRun
python main.pymanually and check stderr for import errors
π Requirements
Python 3.10+
PostgreSQL 12+
Claude Desktop (with MCP support)
π License
MIT License β free to use, modify, and distribute.
π€ Contributing
Pull requests welcome! Please fork the repo, create a feature branch, and submit a PR with a clear description.