Pgmcp

v1.0.0โ€ขDatabasesโ€ขstable

๐ŸŽ๏ธ ๐Ÿ  - Natural language PostgreSQL queries with automatic streaming, read-only safety, and universal database compatibility.

agentagentic-aiaianalyticsartificial-intelligence
Share:
529
Stars
0
Downloads
0
Weekly
0/5

What is Pgmcp?

Pgmcp is a Model Context Protocol (MCP) server that allows AI assistants like Claude, Cursor, and VS Code to ๐ŸŽ๏ธ ๐Ÿ  - natural language postgresql queries with automatic streaming, read-only safety, and universal database compatibility.

๐ŸŽ๏ธ ๐Ÿ  - Natural language PostgreSQL queries with automatic streaming, read-only safety, and universal database compatibility.

This server falls under the Databases category on MCPgee, the world's largest MCP server directory with 33,000+ servers.

Features

  • ๐ŸŽ๏ธ ๐Ÿ  - Natural language PostgreSQL queries with automatic st

Use Cases

Natural language PostgreSQL queries
Streaming database analysis
Read-only database safety
subnetmarco

Maintainer

LicenseNOASSERTION
Languagego
Versionv1.0.0
UpdatedApr 23, 2026
Statushealthy
Maintenanceactive

Works with

ClaudeOpenAIwindowsmacoslinux

Installation

Manual Installation

npx pgmcp

Configuration

Configuration Details

Config File

claude_desktop_config.json

Performance

Response Metrics

Response Time< 200ms
ThroughputMedium

Resource Usage

Memory UsageLow
CPU UsageLow

How to Set Up and Use Pgmcp

PGMCP is a PostgreSQL MCP server written in Go that lets AI assistants query any existing PostgreSQL database through natural language without modifying the schema. It translates plain-English questions into read-only SQL, streams large result sets automatically, and supports free-text search across all text columns. It works with Cursor, Claude Desktop, VS Code extensions, and any other MCP-compatible client, making database exploration and analytics accessible without writing SQL manually.

Prerequisites

  • An existing PostgreSQL database with a valid connection string
  • Go 1.21+ (to build from source) or access to the pre-compiled binary from the GitHub Releases page
  • DATABASE_URL environment variable pointing to your PostgreSQL instance
  • OpenAI API key (optional but recommended โ€” enables natural language to SQL translation; without it basic schema introspection still works)
  • An MCP-compatible client such as Claude Desktop or Cursor
1

Download the pre-compiled binary for your platform

Visit the GitHub Releases page at github.com/subnetmarco/pgmcp/releases and download the tarball for your OS (Linux, macOS, or Windows). Extract it and place the pgmcp-server binary somewhere on your PATH.

tar xzf pgmcp_*.tar.gz
cd pgmcp_*/
# binaries: pgmcp-server (the MCP server) and pgmcp-client (CLI test tool)
2

Set required environment variables

Set DATABASE_URL to your PostgreSQL connection string. Optionally set OPENAI_API_KEY for AI-powered SQL generation โ€” without it the server uses schema introspection only. Other optional variables control the server address, MCP path, and bearer token auth.

export DATABASE_URL="postgres://user:password@localhost:5432/mydb"
export OPENAI_API_KEY="your-openai-api-key"   # optional
export OPENAI_MODEL="gpt-4o-mini"              # optional, default gpt-4o-mini
export HTTP_ADDR=":8080"                       # optional, default :8080
export AUTH_BEARER="your-token"               # optional, enables auth
3

Start the PGMCP server

Run the server binary. It listens on :8080 by default and exposes an MCP endpoint at /mcp. The server connects to your PostgreSQL database and caches the schema for efficient SQL generation.

./pgmcp-server
4

Test with the CLI client

Use the bundled pgmcp-client to verify the server is working before connecting an AI client. Ask natural language questions and inspect the output in table, JSON, or CSV format.

./pgmcp-client -ask "What tables do I have?" -format table
./pgmcp-client -ask "Who is the customer with the most orders?" -format table
./pgmcp-client -search "john" -format table
5

Add PGMCP to your MCP client config

Configure Claude Desktop or Cursor to connect to the running PGMCP server via its MCP HTTP endpoint. Alternatively, run the server as a stdio process directly from the client config.

{
  "mcpServers": {
    "pgmcp": {
      "command": "./pgmcp-server",
      "env": {
        "DATABASE_URL": "postgres://user:password@localhost:5432/mydb",
        "OPENAI_API_KEY": "your-openai-api-key"
      }
    }
  }
}

Pgmcp Examples

Client configuration

Claude Desktop configuration running PGMCP as a stdio server with required DATABASE_URL and optional OPENAI_API_KEY environment variables.

{
  "mcpServers": {
    "pgmcp": {
      "command": "/usr/local/bin/pgmcp-server",
      "env": {
        "DATABASE_URL": "postgres://myuser:mypass@localhost:5432/mydb",
        "OPENAI_API_KEY": "sk-...",
        "OPENAI_MODEL": "gpt-4o-mini"
      }
    }
  }
}

Prompts to try

Natural language questions PGMCP can answer against any PostgreSQL schema โ€” no SQL knowledge required.

- "What are all the tables in this database and how many rows does each have?"
- "Who are the top 5 customers by total revenue this year?"
- "Show me the 20 most recently created orders and their status."
- "Search for any records containing the word 'refund' across all text columns."
- "Export all users who signed up in the last 30 days as CSV."

Troubleshooting Pgmcp

Server starts but returns 'connection refused' or database errors

Verify DATABASE_URL is correctly formatted: postgres://user:password@host:port/dbname. For local databases use 127.0.0.1 instead of localhost if DNS resolution is slow. Ensure the PostgreSQL user has SELECT privileges on the tables you want to query.

Natural language questions return generic or incorrect SQL

OPENAI_API_KEY is optional but strongly recommended. Without it, SQL generation falls back to schema-only introspection and may miss context. Set a valid OPENAI_API_KEY and optionally use a larger model by setting OPENAI_MODEL=gpt-4o.

Large queries time out or consume too much memory

PGMCP uses automatic streaming and pagination for large result sets. If you still hit issues, use the -max-rows flag with the CLI client or ask the AI to add a LIMIT to the query.

Frequently Asked Questions about Pgmcp

What is Pgmcp?

Pgmcp is a Model Context Protocol (MCP) server that ๐ŸŽ๏ธ ๐Ÿ  - natural language postgresql queries with automatic streaming, read-only safety, and universal database compatibility. It connects AI assistants to external tools and data sources through a standardized interface.

How do I install Pgmcp?

Follow the installation instructions on the Pgmcp GitHub repository. Clone the repo, install dependencies, and add the server config to your AI client.

Which AI clients work with Pgmcp?

Pgmcp works with all major MCP-compatible AI clients including Claude Desktop, Claude Code, Cursor, VS Code (GitHub Copilot), Windsurf, and Cline.

Is Pgmcp free to use?

Yes, Pgmcp is open source and available under the NOASSERTION license. You can use it freely in both personal and commercial projects.

Browse More Databases MCP Servers

Explore all databases servers available in the MCPgee directory. Each server includes setup guides for Claude, Cursor, and VS Code.

Quick Config Preview

{ "mcpServers": { "pgmcp": { "command": "npx", "args": ["-y", "pgmcp"] } } }

Add this to your claude_desktop_config.json or .cursor/mcp.json

Read the full setup guide โ†’

Ready to use Pgmcp?

Browse our complete directory of 33,000+ MCP servers, read setup guides for your editor, and start building with the Model Context Protocol.

33,000+ ServersFree & Open SourceStep-by-Step Guides