pgmcp

Connect AI assistants to PostgreSQL with natural language queries.

Local

Install

See the repository for setup

What it does

pgmcp is a Model Context Protocol server that lets MCP-compatible AI clients query an existing PostgreSQL database using natural language. It translates a plain-English question into a SQL query and returns results in table, JSON, or CSV form, with automatic streaming and pagination for large result sets. Three tools are exposed: ask for natural-language questions, search for free-text lookup across text columns, and stream for very large results.

It is aimed at developers and analysts who want an assistant to explore an existing schema without writing SQL, including mixed-case table names and composite keys. No schema changes are required, and access is enforced as read-only: write statements are blocked and queries run in read-only transactions with timeouts.

Configuration is through environment variables such as DATABASE_URL and an optional OPENAI_API_KEY for AI-generated SQL, plus HTTP address, path, and bearer-token settings. It runs as a standalone binary, container, or Kubernetes deployment and serves over streamable HTTP; client configurations for Cursor and Claude Desktop are shown. The included client supports repeated questions and output formats.

Limitations: PostgreSQL only; AI SQL generation needs an OpenAI-compatible key (a configurable model, default gpt-4o-mini); incorrect generated SQL returns an error and suggestion rather than automatic repair.

Compatibility and authentication

Connection
Local
Transports
Unspecified
Authentication
Unknown

Security and permissions

  • When you run the server locally, it runs with your user permissions.
  • Authentication type: Unknown.

Repository data

Stars
544
Last push
May 26, 2026
License
Other
Archived
No

Other OpenAI MCP servers

Compare servers

FAQ

What license does pgmcp use?
Other
Does pgmcp run locally or remotely?
It runs locally.
Is pgmcp an official server?
It is listed as a community server.

Comments

No comments yet.

Embed a listing badge

Featured on AI Agents Marketplace
<a href="https://aiagentsmarketplace.dev/mcp/pgmcp-2"><img src="https://aiagentsmarketplace.dev/badges/featured.svg" alt="Featured on AI Agents Marketplace" width="262" height="36"></a>
See badge options