# pgmcp

> pgmcp is an open-source MCP server for databases. MCP server letting AI assistants query your PostgreSQL database in plain English. It is available on CLI, API, Linux, macOS, Windows and Self-hosted.

- **Kind:** MCP server
- **Pricing:** Open source
- **Platforms:** CLI, API, Linux, macOS, Windows, Self-hosted
- **Repository:** https://github.com/subnetmarco/pgmcp
- **GitHub stars:** 544
- **Categories:** [databases](https://ai-powered.com/categories/databases)
- **Listing updated:** 2026-12-01

## About

Point it at an existing PostgreSQL database and AI clients can ask questions in everyday language, getting back SQL results as tables, JSON or CSV. Queries are generated with an optional OpenAI model, while the server enforces read-only access inside read-only transactions with timeouts and input checks.

Beyond natural-language questions, it offers a free-text search across all text columns and a streaming tool for very large result sets with pagination. A companion command-line client lets you run the same questions from a terminal.

It suits developers and analysts who want to explore production-style data from Cursor, Claude Desktop or similar MCP clients without granting write access to the database.

## Features

- **Natural language querying:** Turns plain-English questions into SQL run against your own schema.
- **Read-only enforcement:** Blocks write statements and runs queries inside read-only transactions.
- **Free-text search:** Searches across every text column in the database for a given term.
- **Streaming large results:** Paginates very large result sets instead of loading them all at once.
- **Multiple output formats:** Returns results as tables, JSON or CSV.
- **Optional bearer authentication:** Protects the HTTP endpoint with a configurable bearer token.

## Good for

- Exploring an unfamiliar production database by asking questions in chat
- Letting analysts pull reports from PostgreSQL without writing SQL
- Exporting filtered query results to CSV from a terminal
- Searching for a customer or record across all text fields

## Tools

From the tool list in its README, going by the names, 1 of 3 tools reads data; 2 names don't say. From the server's own tool labels and tool names; not verified by us.

- `ask`: Natural language questions converted to SQL queries with automatic streaming.
- `search` (name suggests: reads): Free-text search across all database text columns.
- `stream`: Streaming for very large result sets with pagination.

## FAQ

### Can pgmcp modify my data?

No. Write operations such as INSERT, UPDATE and DELETE are blocked, and all queries run in read-only transactions.

### Does pgmcp need an OpenAI key?

The OpenAI API key is optional and is used for AI-powered SQL generation; the server reads its model from OPENAI_MODEL, defaulting to gpt-4o-mini.

### Which clients can connect?

Any MCP-compatible client that supports the HTTP transport, including Cursor and Claude Desktop, can connect to the /mcp endpoint.

### How is pgmcp installed?

Install from pre-compiled binaries on GitHub Releases, via Homebrew, from source with Go, or by running the Docker image.

### Is pgmcp free?

Yes. pgmcp is open source, so you can use and self-host it for free.

### What are the best alternatives to pgmcp?

The closest alternatives to pgmcp are postgres_mcp, Postgres MCP, PostgreSQL MCP Server, sql-query-mcp and MCP Postgres.

## Where this comes from

- Description: written from the project's README.

## Alternatives

- [postgres_mcp](https://ai-powered.com/mcp/postgres-mcp-5): postgres_mcp is an open-source MCP server for databases.
- [Postgres MCP](https://ai-powered.com/mcp/postgres-mcp-2): Postgres MCP is an open-source MCP server for databases.
- [PostgreSQL MCP Server](https://ai-powered.com/mcp/postgresql-mcp-server-2): PostgreSQL MCP Server is an open-source MCP server for databases.
- [sql-query-mcp](https://ai-powered.com/mcp/sql-query-mcp): sql-query-mcp is an open-source MCP server for databases.
- [MCP Postgres](https://ai-powered.com/mcp/mcp-postgres): MCP Postgres is an open-source MCP server for databases.
- [MCP Database Server](https://ai-powered.com/mcp/mcp-database-server): MCP Database Server is an open-source MCP server for databases.
- [postgres-mcp](https://ai-powered.com/mcp/postgres-mcp-4): postgres-mcp is an open-source MCP server for databases.
- [Postgres](https://ai-powered.com/mcp/postgres-2): Postgres is an open-source MCP server for databases.

---
Source: https://ai-powered.com/mcp/pgmcp-2
