MCP ConfigsApr 6, 2026·2 min read

PostgreSQL MCP — SQL Database Server for AI Agents

MCP server that gives AI agents direct access to PostgreSQL databases. Run queries, explore schemas, manage tables, and analyze data through natural language. 3,000+ stars.

MC
MCP Hub · Community
Quick Use

Use it first, then decide how deep to go

This block should tell both the user and the agent what to copy, install, and apply first.

Add to your .mcp.json:

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres"],
      "env": {
        "POSTGRES_CONNECTION_STRING": "postgresql://user:pass@localhost:5432/mydb"
      }
    }
  }
}

Restart Claude Code. Ask: "Show all tables in the database" or "Find the top 10 customers by revenue."


Intro

PostgreSQL MCP is a Model Context Protocol server that gives AI agents like Claude Code direct, read/write access to PostgreSQL databases with 3,000+ GitHub stars. Run SQL queries, explore schemas, create tables, analyze data, and generate reports — all through natural language. Your AI agent becomes a database-aware assistant that understands your data model. Best for developers working with PostgreSQL who want AI-assisted data exploration and database operations. Works with: Claude Code, Cursor, any MCP client. Setup time: under 1 minute.


Available Tools

Schema Exploration

"Show all tables and their column types"
"Describe the users table"
"What foreign keys reference the orders table?"
"Show all indexes on the products table"

Query Execution

"Find all users who signed up in the last 30 days"
"What is the average order value by country?"
"Show the top 10 products by revenue this quarter"
"Count active vs inactive users"

Data Analysis

"Analyze the orders table and find trends in monthly revenue"
"Find customers with declining purchase frequency"
"Show the distribution of order sizes"

Schema Management

"Create a table for tracking user preferences with columns: user_id, key, value, updated_at"
"Add an index on the email column of the users table"
"Add a nullable column 'phone' to the customers table"

Migration Generation

"Generate a migration to add soft-delete to the users table"
"Create a migration that adds a full-text search index on products.description"

Safety Features

Read-Only Mode

{
  "env": {
    "POSTGRES_CONNECTION_STRING": "postgresql://readonly_user:pass@host/db"
  }
}

Query Confirmation

The agent shows the SQL before executing write operations — you approve or reject.

Key Stats

  • 3,000+ GitHub stars
  • Official MCP server
  • Full SQL execution
  • Schema exploration
  • Read-only mode available

FAQ

Q: What is PostgreSQL MCP? A: An MCP server that gives AI agents direct access to PostgreSQL databases for querying data, exploring schemas, and managing tables via natural language.

Q: Is it safe? A: Use a read-only database user for exploration. Write operations require confirmation. Never use superuser credentials.

Q: Is PostgreSQL MCP free? A: Yes, open-source under MIT license.


🙏

Source & Thanks

Part of the MCP Servers collection. Licensed under MIT.

server-postgres — ⭐ 3,000+

Thanks for making databases conversational.

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets