MCP Directory

PGMCP - PostgreSQL Model Context Protocol Server

Query any PostgreSQL database in natural language via MCP, with safe read-only SQL and streaming.

Unverified
HTTP (remote)
API key
Go

Add to your client

Copy the config for your MCP client and paste it into its config file.

Install / run
brew tap subnetmarco/homebrew-tap && brew install pgmcp

Paste 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)

ask

Natural language questions converted to SQL queries with automatic streaming.

search

Free-text search across all database text columns.

stream

Advanced 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.

Verified
stdio (local)
OAuth
Go
10 tools
Updated 15 days agoRepo

Read/write Postgres access plus index tuning, EXPLAIN plans, and database health analysis for AI agents.

Verified
stdio (local)
API key
Python
9 tools
Updated 3 months agoRepo

Official Supabase server: manage tables, run SQL, branches, configs and edge functions from your AI client.

Verified
HTTP (remote)
OAuth
TypeScript
12 tools
Updated 1 month agoRepo