PostgreSQL

v0.8.5Databasesstable

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

postgresmcpserverdatabasemodel-context-protocol
Share:
30
Stars
0
Downloads
0
Weekly
0/5

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

Execute SQL queries and explore database schemas from Claude.
Perform performance analysis and optimization on PostgreSQL databases.
Query databases securely with read-only protection by default.
ahmedmustahid

Maintainer

LicenseMIT License
Languagetypescript
Versionv0.8.5
UpdatedApr 16, 2026
Statushealthy
Maintenanceactive

Works with

ClaudeOpenAIwindowsmacoslinux

Installation

NPM

npx -y @ahmedmustahid/postgres-mcp-server

Manual Installation

npx -y @ahmedmustahid/postgres-mcp-server

Configuration

Configuration Details

Config File

claude_desktop_config.json

Performance

Response Metrics

Response Time< 200ms
ThroughputMedium

Resource Usage

Memory UsageLow
CPU UsageLow

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
1

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 stdio
2

Set 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"
3

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.

4

Restart Claude Desktop

Save the configuration and fully restart Claude Desktop to load the MCP server with the PostgreSQL connection.

5

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.

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.

Quick Config Preview

{ "mcpServers": { "postgresql-mcp-server": { "command": "npx", "args": ["-y", "@ahmedmustahid/postgres-mcp-server"] } } }

Add this to your claude_desktop_config.json or .cursor/mcp.json

Read the full setup guide →

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.

33,000+ ServersFree & Open SourceStep-by-Step Guides