Pgmcp logo

Pgmcp

by subnetmarco

Connects MCP clients to PostgreSQL for natural-language, read-only SQL, text search, and streamed results.

Install Pgmcp

Run the project’s own setup commands, in order.

Setup steps from the project

subnetmarco/pgmcp installs with its own steps rather than a config we can generate, so these are copied as-is. Follow them in order and run the commands in a terminal. Source: github.com

  1. 1. Start the server
    ./pgmcp-server
    
  2. 2. Install
    brew tap subnetmarco/homebrew-tap
    
  3. 3. Install
    brew install pgmcp
    
  4. 4. Install
    go build -o pgmcp-server ./server
    
  5. 5. Install
    go build -o pgmcp-client ./client
    
  6. 6. Install
    go build -ldflags="-s -w -extldflags=-static" -trimpath -o pgmcp-server ./server
    

Overview

The subnetmarco/pgmcp MCP server connects MCP-compatible clients to an existing PostgreSQL database through natural-language questions. It can generate SQL with OpenAI, enforce read-only access, stream large result sets, search text columns, and return table, JSON, or CSV output. The server exposes HTTP MCP access at a configurable endpoint and can run with precompiled binaries, Docker, or from source. Reach for it when an AI assistant needs to inspect or query PostgreSQL data without modifying the database schema.

Use cases

  • Ask natural-language questions about PostgreSQL data
  • Search text columns across an existing database
  • Stream large query results with pagination
  • Inspect database contents from Cursor or Claude Desktop

Key features

  • Natural-language to SQL generation
  • Read-only SQL enforcement
  • Automatic result streaming and pagination
  • Free-text search across text columns
  • Table, JSON, and CSV output
  • Mixed-case PostgreSQL table support

Security & health

What it can reach and how reliably it runs — from our own checks, not the maintainer’s claims.

ActiveLast checked

Recent health check succeeded.

30/31 checks healthy over the last 117d

Adoption & maintenance

Factual signals from GitHub, npm, and our automated checks — not a rating.

GitHub stars543Stargazers on the source repository.
Last commit6mo agoMost recent push to the default branch.
Directory activity4 viewsConfig copies, upvotes, and views on AllMCPs.

How Pgmcp works

What subnetmarco/pgmcp MCP server does

The subnetmarco/pgmcp MCP server gives AI assistants access to an existing PostgreSQL database through MCP. Users can ask questions such as which customers placed the most orders or how many orders were created on a given day. The server translates natural-language requests into SQL and returns structured results.

It is intended to work with arbitrary PostgreSQL schemas rather than a bundled application schema. No database schema changes are required. The project also includes example schemas for testing, including one with mixed-case table names and another with composite primary keys.

How it works

An MCP client connects to the server over streamable HTTP. The server connects to PostgreSQL using the DATABASE_URL connection string, inspects the available database structure, and processes requests through its MCP tools. OpenAI can be enabled for SQL generation, with gpt-4o-mini used by default when no model is specified.

The subnetmarco/pgmcp MCP server applies read-only safeguards before executing generated SQL. It also supports query timeouts, connection pooling, automatic pagination, and streaming for larger result sets. When generated SQL is invalid, the server reports the database error and a suggestion rather than terminating the service.

Results can be formatted as tables, JSON, or CSV. The separate command-line client supports asking questions, issuing text searches, sending multiple questions, and limiting the number of returned rows.

Setup and configuration

A PostgreSQL database and the DATABASE_URL environment variable are required. The server can be obtained as a platform-specific release binary, built with Go, or run using the published Docker image. The repository also documents Kubernetes manifests and a Homebrew option described as available after the first release.

The subnetmarco/pgmcp MCP server accepts these configuration variables:

  • DATABASE_URL: PostgreSQL connection string; required.
  • OPENAI_API_KEY: optional key for AI-assisted SQL generation.
  • OPENAI_MODEL: optional model name; defaults to gpt-4o-mini.
  • HTTP_ADDR: listening address; defaults to :8080.
  • HTTP_PATH: MCP endpoint path; defaults to /mcp.
  • AUTH_BEARER: optional bearer token for authentication.

Cursor and Claude Desktop can connect to a local instance at http://localhost:8080/mcp when the default address and path are used.

Tools and capabilities

The exposed MCP tools are:

  • ask: converts a natural-language question into a SQL query and streams the result when needed.
  • search: searches across text columns in the database.
  • stream: provides advanced streaming and pagination for very large result sets.

The implementation handles PostgreSQL mixed-case table names and supports multiple output formats. Its write protections block operations such as INSERT, UPDATE, and DELETE, making it suited to read-oriented analytics and database exploration.

Limitations and notes

The database must be PostgreSQL; the stated compatibility covers PostgreSQL databases and their varying schemas, not arbitrary database engines. AI-powered SQL generation uses OpenAI only when an API key is supplied, so users should account for that external dependency when enabling the feature. Natural-language results still depend on the generated SQL matching the database schema; invalid queries produce an error and guidance to rephrase the request.

The project documentation describes HTTP MCP configuration rather than a direct desktop stdio configuration. Running the service also requires access to the target database and a suitable PostgreSQL connection string.

Written by AllMCPs with AI assistance from the project’s README and listing data. How we build listings

Reviews

No reviews yet — be the first to share how it worked for you.

Frequently Asked Questions about Pgmcp

Download a platform-specific binary from the GitHub Releases page, build the server with Go, or use the documented Docker image. Set DATABASE_URL before starting it.

Yes. The README provides Claude Desktop configuration using the HTTP endpoint http://localhost:8080/mcp.

No. OPENAI_API_KEY is optional, but it enables AI-powered SQL generation.

Set DATABASE_URL to the connection string for an existing PostgreSQL database, then start pgmcp-server.

The server enforces read-only access and blocks write operations such as INSERT, UPDATE, and DELETE.

Related MCP servers

Add a badge to your READMEShow it’s listed — live SVG, Markdown or HTML.

AllMCPs Directory Badge

Full Badge Customizer

Showcase your server listing on GitHub or your project documentation. Embed this dynamic SVG badge to highlight official listing status and live engagement.

Badge Style:
Live Dynamic SVG PreviewPgmcp AllMCPs Directory Badge
Markdown (GitHub README)
[![AllMCPs](https://allmcps.com/api/badge/subnetmarco-pgmcp?style=directory)](https://allmcps.com/mcp/subnetmarco-pgmcp)
HTML Embed
<a href="https://allmcps.com/mcp/subnetmarco-pgmcp"><img src="https://allmcps.com/api/badge/subnetmarco-pgmcp?style=directory" alt="Pgmcp on AllMCPs" /></a>