by subnetmarco
An MCP server to query any Postgres database in natural language.
# Add to your Claude Code skills
git clone https://github.com/subnetmarco/pgmcpPGMCP connects AI assistants to any PostgreSQL database through natural language queries. Ask questions in plain English and get structured SQL results with automatic streaming and robust error handling.
Works with: Cursor, Claude Desktop, VS Code extensions, and any MCP-compatible client
PGMCP connects to your existing PostgreSQL database and makes it accessible to AI assistants through natural language queries.
# Set up environment variables
export DATABASE_URL="postgres://user:password@localhost:5432/your-existing-db"
export OPENAI_API_KEY="your-api-key" # Optional
# Run server (using pre-compiled binary)
./pgmcp-server
# Test with client in another terminal
./pgmcp-client -ask "What tables do I have?" -format table
./pgmcp-client -ask "Who is the customer that has placed the most orders?" -format table
./pgmcp-client -search "john" -format table
Here is how it works:
š¤ User / AI Assistant
ā
ā "Who are the top customers?"
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā Any MCP Client ā
ā ā
ā PGMCP CLI ā Cursor ā Claude Desktop ā VS Code ā ... ā
ā JSON/CSV ā Chat ā AI Assistant ā Editor ā ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā
ā Streamable HTTP / MCP Protocol
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā PGMCP Server ā
ā ā
ā š Security š§ AI Engine š Streaming ā
ā ⢠Input Valid ⢠Schema Cache ⢠Auto-Pagination ā
ā ⢠Audit Log ⢠OpenAI API ⢠Memory Management ā
ā ⢠SQL Guard ⢠Error Recovery ⢠Connection Pool ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā
ā Read-Only SQL Queries
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā Your PostgreSQL Database ā
ā ā
ā Any Schema: E-commerce, Analytics, CRM, etc. ā
ā Tables ⢠Views ⢠Indexes ⢠Functions ...