Pgmcp
๐๏ธ ๐ - Natural language PostgreSQL queries with automatic streaming, read-only safety, and universal database compatibility.
What is Pgmcp?
Pgmcp is a Model Context Protocol (MCP) server that allows AI assistants like Claude, Cursor, and VS Code to ๐๏ธ ๐ - natural language postgresql queries with automatic streaming, read-only safety, and universal database compatibility.
๐๏ธ ๐ - Natural language PostgreSQL queries with automatic streaming, read-only safety, and universal database compatibility.
This server falls under the Databases category on MCPgee, the world's largest MCP server directory with 33,000+ servers.
Features
- ๐๏ธ ๐ - Natural language PostgreSQL queries with automatic st
Use Cases
Maintainer
Works with
Installation
Manual Installation
npx pgmcpConfiguration
Configuration Details
claude_desktop_config.json
Performance
Response Metrics
Resource Usage
How to Set Up and Use Pgmcp
PGMCP is a PostgreSQL MCP server written in Go that lets AI assistants query any existing PostgreSQL database through natural language without modifying the schema. It translates plain-English questions into read-only SQL, streams large result sets automatically, and supports free-text search across all text columns. It works with Cursor, Claude Desktop, VS Code extensions, and any other MCP-compatible client, making database exploration and analytics accessible without writing SQL manually.
Prerequisites
- An existing PostgreSQL database with a valid connection string
- Go 1.21+ (to build from source) or access to the pre-compiled binary from the GitHub Releases page
- DATABASE_URL environment variable pointing to your PostgreSQL instance
- OpenAI API key (optional but recommended โ enables natural language to SQL translation; without it basic schema introspection still works)
- An MCP-compatible client such as Claude Desktop or Cursor
Download the pre-compiled binary for your platform
Visit the GitHub Releases page at github.com/subnetmarco/pgmcp/releases and download the tarball for your OS (Linux, macOS, or Windows). Extract it and place the pgmcp-server binary somewhere on your PATH.
tar xzf pgmcp_*.tar.gz
cd pgmcp_*/
# binaries: pgmcp-server (the MCP server) and pgmcp-client (CLI test tool)Set required environment variables
Set DATABASE_URL to your PostgreSQL connection string. Optionally set OPENAI_API_KEY for AI-powered SQL generation โ without it the server uses schema introspection only. Other optional variables control the server address, MCP path, and bearer token auth.
export DATABASE_URL="postgres://user:password@localhost:5432/mydb"
export OPENAI_API_KEY="your-openai-api-key" # optional
export OPENAI_MODEL="gpt-4o-mini" # optional, default gpt-4o-mini
export HTTP_ADDR=":8080" # optional, default :8080
export AUTH_BEARER="your-token" # optional, enables authStart the PGMCP server
Run the server binary. It listens on :8080 by default and exposes an MCP endpoint at /mcp. The server connects to your PostgreSQL database and caches the schema for efficient SQL generation.
./pgmcp-serverTest with the CLI client
Use the bundled pgmcp-client to verify the server is working before connecting an AI client. Ask natural language questions and inspect the output in table, JSON, or CSV format.
./pgmcp-client -ask "What tables do I have?" -format table
./pgmcp-client -ask "Who is the customer with the most orders?" -format table
./pgmcp-client -search "john" -format tableAdd PGMCP to your MCP client config
Configure Claude Desktop or Cursor to connect to the running PGMCP server via its MCP HTTP endpoint. Alternatively, run the server as a stdio process directly from the client config.
{
"mcpServers": {
"pgmcp": {
"command": "./pgmcp-server",
"env": {
"DATABASE_URL": "postgres://user:password@localhost:5432/mydb",
"OPENAI_API_KEY": "your-openai-api-key"
}
}
}
}Pgmcp Examples
Client configuration
Claude Desktop configuration running PGMCP as a stdio server with required DATABASE_URL and optional OPENAI_API_KEY environment variables.
{
"mcpServers": {
"pgmcp": {
"command": "/usr/local/bin/pgmcp-server",
"env": {
"DATABASE_URL": "postgres://myuser:mypass@localhost:5432/mydb",
"OPENAI_API_KEY": "sk-...",
"OPENAI_MODEL": "gpt-4o-mini"
}
}
}
}Prompts to try
Natural language questions PGMCP can answer against any PostgreSQL schema โ no SQL knowledge required.
- "What are all the tables in this database and how many rows does each have?"
- "Who are the top 5 customers by total revenue this year?"
- "Show me the 20 most recently created orders and their status."
- "Search for any records containing the word 'refund' across all text columns."
- "Export all users who signed up in the last 30 days as CSV."Troubleshooting Pgmcp
Server starts but returns 'connection refused' or database errors
Verify DATABASE_URL is correctly formatted: postgres://user:password@host:port/dbname. For local databases use 127.0.0.1 instead of localhost if DNS resolution is slow. Ensure the PostgreSQL user has SELECT privileges on the tables you want to query.
Natural language questions return generic or incorrect SQL
OPENAI_API_KEY is optional but strongly recommended. Without it, SQL generation falls back to schema-only introspection and may miss context. Set a valid OPENAI_API_KEY and optionally use a larger model by setting OPENAI_MODEL=gpt-4o.
Large queries time out or consume too much memory
PGMCP uses automatic streaming and pagination for large result sets. If you still hit issues, use the -max-rows flag with the CLI client or ask the AI to add a LIMIT to the query.
Frequently Asked Questions about Pgmcp
What is Pgmcp?
Pgmcp is a Model Context Protocol (MCP) server that ๐๏ธ ๐ - natural language postgresql queries with automatic streaming, read-only safety, and universal database compatibility. It connects AI assistants to external tools and data sources through a standardized interface.
How do I install Pgmcp?
Follow the installation instructions on the Pgmcp GitHub repository. Clone the repo, install dependencies, and add the server config to your AI client.
Which AI clients work with Pgmcp?
Pgmcp works with all major MCP-compatible AI clients including Claude Desktop, Claude Code, Cursor, VS Code (GitHub Copilot), Windsurf, and Cline.
Is Pgmcp free to use?
Yes, Pgmcp is open source and available under the NOASSERTION license. You can use it freely in both personal and commercial projects.
Pgmcp Alternatives โ Similar Databases Servers
Looking for alternatives to Pgmcp? 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 Pgmcp 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 Pgmcp?
Browse our complete directory of 33,000+ MCP servers, read setup guides for your editor, and start building with the Model Context Protocol.