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 ...
No comments yet. Be the first to share your thoughts!