
PGMCP - PostgreSQL Model Context Protocol Server
Query any PostgreSQL database in natural language via MCP, with safe read-only SQL and streaming.
Add to your client
Copy the config for your MCP client and paste it into its config file.
brew tap subnetmarco/homebrew-tap && brew install pgmcpPaste into ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"pgmcp---postgresql-model-context-protocol-server": {
"command": "npx",
"args": [
"-y",
"mcp-remote",
"http://localhost:8080/mcp"
]
}
}
}Claude Desktop connects to remote servers through the `mcp-remote` proxy (installed on first run via npx). Restart Claude Desktop after saving.
Step-by-step guides: Add to Claude Desktop · Add to Cursor · Add to Windsurf
Before you start
- PostgreSQL database (existing database with your schema)
- OpenAI API key (optional, for AI-powered SQL generation)
About PGMCP - PostgreSQL Model Context Protocol Server
PGMCP is a Go-based MCP server that makes any existing PostgreSQL database accessible to AI assistants through natural language. It runs as a Streamable HTTP MCP endpoint (default :8080/mcp), translates plain-English questions into SQL (optionally via the OpenAI API), and returns structured results in table, JSON, or CSV format. It enforces read-only access, automatic streaming for large result sets, query timeouts, and input validation, and works with any PostgreSQL schema without modifications. A companion CLI (pgmcp-client) is provided for testing and direct querying.
Tools & capabilities (3)
askNatural language questions converted to SQL queries with automatic streaming.
searchFree-text search across all database text columns.
streamAdvanced streaming for very large result sets with pagination.
When to use it
- Ask plain-English analytics questions over an existing PostgreSQL database (e.g. top customers, order counts)
- Perform free-text search across all text columns of a database
- Export query results as table, JSON, or CSV for reporting
- Give AI assistants like Cursor or Claude Desktop safe, read-only access to production data
Security notes
Read-only enforcement blocks write operations (INSERT, UPDATE, DELETE, etc.) and runs all queries in read-only transactions. Query timeouts prevent long-running queries; input validation sanitizes and validates user input. Optional Bearer-token authentication via the AUTH_BEARER environment variable. Natural-language-to-SQL generation sends schema/queries to the OpenAI API when OPENAI_API_KEY is configured.
PGMCP - PostgreSQL Model Context Protocol Server FAQ
Is it safe to point this at my production database?
It enforces read-only access, blocking write operations (INSERT, UPDATE, DELETE, etc.) and running all queries in read-only transactions, with query timeouts and input validation. No schema modifications are required.
Do I need an OpenAI API key?
It is optional. OPENAI_API_KEY enables AI-powered natural-language-to-SQL generation; the default model is gpt-4o-mini and can be overridden with OPENAI_MODEL.
How do I connect it to Claude Desktop or Cursor?
Start the server (it listens on http://localhost:8080/mcp by default), then add an mcpServers entry with an http transport pointing to that URL in your client config.
Which databases are supported?
Any PostgreSQL database. You point DATABASE_URL at your existing database and it works with any schema, including mixed-case table names and composite primary keys.
Alternatives to PGMCP - PostgreSQL Model Context Protocol Server
Compare all alternatives →Google's official MCP server with prebuilt BigQuery tools, querying datasets via Application Default Credentials.
Read/write Postgres access plus index tuning, EXPLAIN plans, and database health analysis for AI agents.
Official Supabase server: manage tables, run SQL, branches, configs and edge functions from your AI client.
Compare PGMCP - PostgreSQL Model Context Protocol Server with: