Model Context Protocol
PostgreSQL MCP Server
Query and explore PostgreSQL databases with schema inspection and read-only SQL execution.
Last reviewed Mar 2, 2026
Install
claude mcp add postgres --transport stdio -- npx -y @modelcontextprotocol/server-postgres postgresql://user:pass@localhost:5432/dbnameAvailable tools
| Tool | Description |
|---|---|
| query | Execute a read-only SQL query against the database |
| list_tables | List all tables in the database with their schemas |
| describe_table | Get column names, types, and constraints for a table |
What it does
The PostgreSQL MCP Server connects your AI coding assistant to a PostgreSQL database, enabling it to explore schemas, inspect table structures, and run read-only queries. This gives the assistant deep understanding of your data model when helping you write application code, debug queries, or design new features.
The server operates in read-only mode by default, executing queries within a transaction that gets rolled back. This makes it safe to use against development and staging databases without risk of accidental data modification.
Use cases
- Explore your database schema to inform AI-assisted code generation for data access layers
- Debug SQL queries by letting the assistant inspect table structures and run test queries
- Generate ORM models, migrations, or TypeScript types based on your actual database schema
- Analyze data patterns by running aggregate queries during development
- Validate that your application queries match the actual table structures
Getting started
- Prepare your PostgreSQL connection string in the format
postgresql://user:password@host:port/database. For local development databases, this is typicallypostgresql://postgres:postgres@localhost:5432/mydb. - Replace the connection string in the install command with your actual database credentials.
- The server runs queries in read-only mode by default. All queries are wrapped in a transaction that is rolled back after execution.
- For production databases, create a dedicated read-only database user to add an extra layer of safety. Grant
SELECTprivileges only on the schemas you want the assistant to access.
Compatibility
Related MCP servers
AWS MCP Server
Interact with AWS services including S3, Lambda, CloudWatch, and ECS from your AI coding assistant.
Context7 MCP Server
Fetch up-to-date library documentation and code examples directly into your AI coding assistant.
Docker MCP Server
Manage Docker containers, images, and builds directly from your AI coding assistant.