PostgreSQL
Enables users to perform SQL query execution, schema exploration, and performance analysis on PostgreSQL databases through any MCP-compatible client. It prioritizes security with read-only protection by default and provides guided workflows for datab
What is PostgreSQL?
PostgreSQL is a Model Context Protocol (MCP) server that allows AI assistants like Claude, Cursor, and VS Code to enables users to perform sql query execution, schema exploration, and performance analysis on postgresql databases through any mcp-compatible client. it prioritizes security with read-only protection ...
Enables users to perform SQL query execution, schema exploration, and performance analysis on PostgreSQL databases through any MCP-compatible client. It prioritizes security with read-only protection by default and provides guided workflows for datab
This server falls under the Databases category on MCPgee, the world's largest MCP server directory with 33,000+ servers.
Features
- Enables users to perform SQL query execution, schema explora
Use Cases
Maintainer
Works with
Installation
NPM
npx -y @ahmedmustahid/postgres-mcp-serverManual Installation
npx -y @ahmedmustahid/postgres-mcp-serverConfiguration
Configuration Details
claude_desktop_config.json
Performance
Response Metrics
Resource Usage
How to Set Up and Use PostgreSQL
The PostgreSQL MCP server enables Claude and other MCP-compatible clients to query PostgreSQL databases using natural-language prompts, executing read-only SQL, exploring table schemas, and analyzing database performance. It exposes a query tool along with schema and table resources that give the AI context about your database structure before generating queries. The server defaults to read-only protection to prevent accidental data modification, making it safe to use for data exploration, reporting, and performance analysis tasks. It supports both stdio transport for Claude Desktop integration and HTTP transport for multi-client or web-based deployments.
Prerequisites
- Node.js and npm installed (for npx-based launch)
- A running PostgreSQL database that is network-accessible from your machine
- PostgreSQL credentials: username, password, host, and database name
- An MCP-compatible client such as Claude Desktop
- Optional: Docker or Podman for containerized deployment with uv
Test the server with npx
Run the server directly with npx to verify the package installs and starts without errors. Use stdio mode for Claude Desktop integration.
npx -y @ahmedmustahid/postgres-mcp-server stdioSet your PostgreSQL environment variables
Prepare the database connection details. You can pass these as environment variables in the MCP config or export them for testing.
export POSTGRES_USERNAME="your_db_user"
export POSTGRES_PASSWORD="your_db_password"
export POSTGRES_HOST="localhost"
export POSTGRES_DATABASE="your_database_name"Add the server to Claude Desktop
Open your Claude Desktop configuration file at ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) and add the server block with your database credentials in the env section.
Restart Claude Desktop
Save the configuration and fully restart Claude Desktop to load the MCP server with the PostgreSQL connection.
Explore your database schema
Ask Claude to list your database tables and describe the schema to confirm connectivity and explore what data is available.
PostgreSQL Examples
Client configuration
Add this block to your Claude Desktop config at ~/Library/Application Support/Claude/claude_desktop_config.json. Replace all placeholder values with your actual PostgreSQL connection details.
{
"mcpServers": {
"postgresql": {
"command": "npx",
"args": ["-y", "@ahmedmustahid/postgres-mcp-server", "stdio"],
"env": {
"POSTGRES_USERNAME": "your_db_user",
"POSTGRES_PASSWORD": "your_db_password",
"POSTGRES_HOST": "localhost",
"POSTGRES_DATABASE": "your_database_name"
}
}
}
}Prompts to try
Once the server is connected, use these prompts to interact with your PostgreSQL database through Claude.
- "List all tables in my PostgreSQL database"
- "Show me the schema for the users table including column types and constraints"
- "Write and run a query to find the top 10 most active users by order count"
- "How many rows are in each table? Give me a summary"
- "Find any tables that don't have a primary key defined"
- "Show me a sample of 5 rows from the products table"Troubleshooting PostgreSQL
Connection refused or could not connect to server errors
Verify that POSTGRES_HOST, POSTGRES_USERNAME, POSTGRES_PASSWORD, and POSTGRES_DATABASE are all correct. If PostgreSQL is running locally, ensure it is listening on the expected port (default 5432). If it is running in Docker, ensure the container's port is mapped to the host with -p 5432:5432.
Authentication failed for user errors
Check your PostgreSQL pg_hba.conf to ensure the user is allowed to connect from the host where the MCP server is running. For local development, md5 or trust authentication for localhost connections is typical. Verify the password is correct by connecting manually with psql -U your_user -h localhost your_database.
npx takes too long to start on every Claude Desktop launch
Install the package globally to avoid the npx download delay on each startup: npm install -g @ahmedmustahid/postgres-mcp-server. Then update the command in your config from npx with args to the direct binary name postgres-mcp-server with the stdio argument.
Frequently Asked Questions about PostgreSQL
What is PostgreSQL?
PostgreSQL is a Model Context Protocol (MCP) server that enables users to perform sql query execution, schema exploration, and performance analysis on postgresql databases through any mcp-compatible client. it prioritizes security with read-only protection by default and provides guided workflows for datab It connects AI assistants to external tools and data sources through a standardized interface.
How do I install PostgreSQL?
Install via npm with the command: npx -y @ahmedmustahid/postgres-mcp-server. Then add the server configuration to your AI client's JSON config file (e.g., claude_desktop_config.json or .cursor/mcp.json).
Which AI clients work with PostgreSQL?
PostgreSQL works with all major MCP-compatible AI clients including Claude Desktop, Claude Code, Cursor, VS Code (GitHub Copilot), Windsurf, and Cline.
Is PostgreSQL free to use?
Yes, PostgreSQL is open source and available under the MIT License license. You can use it freely in both personal and commercial projects.
PostgreSQL Alternatives — Similar Databases Servers
Looking for alternatives to PostgreSQL? Here are other popular databases servers you can use with Claude, Cursor, and VS Code.
Excelize
★ 20.6kGo language library for reading and writing Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) spreadsheets
MCP Toolbox for Databases
★ 15.3kOpen source MCP server specializing in easy, fast, and secure tools for Databases.
DBHub
★ 2.8kA universal database gateway MCP server that enables AI assistants to connect to and query multiple databases (PostgreSQL, MySQL, MariaDB, SQL Server, SQLite) with support for schema exploration, SQL execution, and secure connections via SSH tunnels.
Tabularis
★ 2.1kA lightweight, cross-platform database client for developers. Supports MySQL, PostgreSQL and SQLite. Hackable with plugins. Built for speed, security, and aesthetics.
Postgres AI Guide
★ 1.7kMCP server and Claude plugin for Postgres skills and documentation. Helps AI coding tools generate better PostgreSQL code.
Anyquery
★ 1.7k🏎️ 🏠 ☁️ - Query more than 40 apps with one binary using SQL. It can also connect to your PostgreSQL, MySQL, or SQLite compatible database. Local-first and private by design.
Browse More Databases MCP Servers
Explore all databases servers available in the MCPgee directory. Each server includes setup guides for Claude, Cursor, and VS Code.
Set Up PostgreSQL in Your Editor
Choose your AI client for step-by-step setup instructions.
Quick Config Preview
Add this to your claude_desktop_config.json or .cursor/mcp.json
Ready to use PostgreSQL?
Browse our complete directory of 33,000+ MCP servers, read setup guides for your editor, and start building with the Model Context Protocol.