PG MCP

v1.0.0Databasesstable

PG-MCP is an HTTP server implementation that enables AI systems to interact with PostgreSQL databases via MCP, providing tools for querying, connecting to multiple databases, and exploring schema resources. The system enriches context by extracting t

pgmcpai-integration
Share:
539
Stars
0
Downloads
0
Weekly
0/5

What is PG MCP?

PG MCP is a Model Context Protocol (MCP) server that allows AI assistants like Claude, Cursor, and VS Code to pg-mcp is an http server implementation that enables ai systems to interact with postgresql databases via mcp, providing tools for querying, connecting to multiple databases, and exploring schema reso...

PG-MCP is an HTTP server implementation that enables AI systems to interact with PostgreSQL databases via MCP, providing tools for querying, connecting to multiple databases, and exploring schema resources. The system enriches context by extracting t

This server falls under the Databases category on MCPgee, the world's largest MCP server directory with 33,000+ servers.

Features

  • PG-MCP is an HTTP server implementation that enables AI syst

Use Cases

AI access to PostgreSQL databases
Multi-database connections
Schema exploration and querying
awaketai

Maintainer

LicenseMIT
Languagepython
Versionv1.0.0
UpdatedMay 21, 2026
Statushealthy
Maintenanceactive

Works with

ClaudeOpenAIwindowsmacoslinux

Installation

NPM

npx -y pg-mcp-server

Manual Installation

npx -y pg-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 PG MCP

PG-MCP is an HTTP-based MCP server that lets AI systems query PostgreSQL databases using natural language, automatically translating questions into safe, SELECT-only SQL via OpenAI. It auto-discovers the full schema of connected databases on startup — including tables, views, columns, indexes, foreign keys, and enums — so AI assistants can answer questions about your data without requiring users to know SQL syntax. Database teams and analysts use it to enable conversational data access across multiple PostgreSQL databases while enforcing query safety through a built-in SQL validator.

Prerequisites

  • Python 3.10+ with pip installed
  • One or more PostgreSQL databases accessible via connection string
  • An OpenAI API key (OPENAI_API_KEY) for natural language to SQL translation
  • An MCP-capable client such as Claude Desktop or Claude Code
1

Clone the repository and install

Clone the pg-mcp repository and install it in editable mode using pip.

git clone https://github.com/awaketai/postgres-mcp
cd postgres-mcp
pip install -e .
2

Set required environment variables

Configure the database connection string and OpenAI API key. PG_MCP_DATABASES accepts a comma-separated list of PostgreSQL DSNs for multi-database support.

export PG_MCP_DATABASES="postgresql://user:password@localhost:5432/mydb"
export OPENAI_API_KEY="sk-..."

# Optional settings
export OPENAI_MODEL="gpt-4o"
export PG_MCP_MAX_ROWS=100
export PG_MCP_QUERY_TIMEOUT=30
3

Start the MCP server

Start the pg-mcp server. It will auto-discover the schema for all configured databases on startup.

pg-mcp
4

Add to Claude Desktop configuration

Configure Claude Desktop to use pg-mcp with your database and OpenAI credentials.

{
  "mcpServers": {
    "pg-mcp": {
      "command": "pg-mcp",
      "env": {
        "PG_MCP_DATABASES": "postgresql://user:password@localhost:5432/mydb",
        "OPENAI_API_KEY": "sk-...",
        "PG_MCP_MAX_ROWS": "100"
      }
    }
  }
}
5

Refresh the schema cache if needed

If you make schema changes to your database, use the refresh_schema tool to reload the schema cache without restarting the server.

PG MCP Examples

Client configuration

Claude Desktop JSON configuration for pg-mcp connecting to a local PostgreSQL database.

{
  "mcpServers": {
    "pg-mcp": {
      "command": "pg-mcp",
      "env": {
        "PG_MCP_DATABASES": "postgresql://user:password@localhost:5432/mydb",
        "OPENAI_API_KEY": "sk-...",
        "OPENAI_MODEL": "gpt-4o",
        "PG_MCP_MAX_ROWS": "100",
        "PG_MCP_QUERY_TIMEOUT": "30"
      }
    }
  }
}

Prompts to try

Example natural-language data queries once pg-mcp is connected to your AI assistant.

- "How many users registered in the last 30 days?"
- "Show me the top 10 products by revenue this quarter"
- "List all databases connected to this MCP server"
- "Describe the schema of the orders table including indexes and foreign keys"
- "Which customers have placed more than 5 orders in the past year?"

Troubleshooting PG MCP

Connection to PostgreSQL fails on startup

Verify that PG_MCP_DATABASES contains a valid PostgreSQL DSN including host, port, database name, user, and password. Test the connection directly with psql or a database client before running pg-mcp.

OpenAI API errors when running natural language queries

Confirm that OPENAI_API_KEY is set correctly and that the selected OPENAI_MODEL (default: gpt-4o) is available on your OpenAI account. Check your usage limits and billing status if requests fail consistently.

Query results are incomplete or truncated

The default PG_MCP_MAX_ROWS is 100. Increase this value (up to 1000) by setting PG_MCP_MAX_ROWS in your environment. For time-sensitive queries, also adjust PG_MCP_QUERY_TIMEOUT beyond the 30-second default.

Frequently Asked Questions about PG MCP

What is PG MCP?

PG MCP is a Model Context Protocol (MCP) server that pg-mcp is an http server implementation that enables ai systems to interact with postgresql databases via mcp, providing tools for querying, connecting to multiple databases, and exploring schema resources. the system enriches context by extracting t It connects AI assistants to external tools and data sources through a standardized interface.

How do I install PG MCP?

Install via npm with the command: npx -y pg-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 PG MCP?

PG MCP works with all major MCP-compatible AI clients including Claude Desktop, Claude Code, Cursor, VS Code (GitHub Copilot), Windsurf, and Cline.

Is PG MCP free to use?

Yes, PG MCP is open source and available under the MIT 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": { "pg": { "command": "npx", "args": ["-y", "pg-mcp-server"] } } }

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

Read the full setup guide →

Ready to use PG MCP?

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