pgEdge MCP Server for Postgres

by pgedge

351 downloads Not rated yet

About

The pgEdge Postgres Model Context Protocol (MCP) server enables SQL queries against PostgreSQL databases through MCP-compatible clients like Claude Desktop. The Natural Language Agent provides supporting functionality that allows you to use natural language to form SQL queries.

Explore

- 🔒 Read-Only Protection - All queries run in read-only transactions
- 📊 Resources - Access PostgreSQL statistics and more
- 🛠️ Tools - Query execution, schema analysis, advanced hybrid search
(BM25+MMR), embedding generation, resource reading, and more
- 🧠 Prompts - Guided workflows for semantic search setup, database
exploration, query diagnostics, and more
- 💬 Production Chat Client - Full-featured Go client with Anthropic
prompt caching (90% cost reduction)
- 🌐 HTTP/HTTPS Mode - Direct API access with token authentication
- 🖥️ Web Interface - Modern React-based UI with AI-powered chat for
natural language database interaction
- 🐳 Docker Support - Complete containerized deployment with Docker
Compose
- 🔐 Secure - TLS support, token auth, read-only enforcement
- 🔄 Hot Reload - Automatic reload of authentication files without server
restart

- Go 1.21 or higher
- PostgreSQL (for testing)
- golangci-lint v1.x (for linting)

git clone <repository-url>
cd pgedge-postgres-mcp
make build

Claude Code: .mcp.json in each of your project directories
Claude Desktop on macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Claude Desktop on Windows: %APPDATA%\\Claude\\claude_desktop_config.json

{
  "mcpServers": {
    "pgedge": {
      "command": "/absolute/path/to/bin/pgedge-postgres-mcp"
    }
  }
}

./bin/pgedge-postgres-mcp -http -no-auth

./bin/pgedge-postgres-mcp -http -token-file tokens.json

./bin/pgedge-postgres-mcp -http -tls \
-cert server.crt \
-key server.key \
-token-file tokens.json


> Note: Authentication is enabled by default in HTTP mode. Use -no-auth to
> disable it for local development, or provide an authentication token file with
> -token-file. See the
> Authentication Guide for token setup.

API Endpoint: POST http://localhost:8080/mcp/v1

Example request (with authentication):

bash
curl -X POST http://localhost:8080/mcp/v1 \
-H "Authorization: Bearer your-token" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "query_database",
"arguments": {
"query": "SELECT FROM users LIMIT 10"
}
}
}'

Example request (without authentication):

bash
curl -X POST http://localhost:8080/mcp/v1 \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "query_database",
"arguments": {
"query": "SELECT
FROM users LIMIT 10"
}
}
}'

cp examples/pgedge-postgres-mcp-stdio.yaml.example bin/pgedge-postgres-mcp-stdio.yaml
cp examples/pgedge-nla-cli-stdio.yaml.example bin/pgedge-nla-cli-stdio.yaml

./start_cli_stdio.sh

cp examples/pgedge-nla-cli-http.yaml.example bin/pgedge-nla-cli-http.yaml
./start_cli_http.sh

Features:
- 💬 Natural language database queries powered by Claude, GPT, or Ollama
- 🔧 Dual mode support (stdio subprocess or HTTP API)
- 💰 Anthropic prompt caching (90% cost reduction on repeated queries)
- ⚡ Runtime configuration with slash commands
- 📝 Persistent command history with readline support
- 🎨 PostgreSQL-themed UI with animations

Example queries:
- What tables are in my database?
- Show me the 10 most recent orders
- Which customers have placed more than 5 orders?
- Find documents similar to 'PostgreSQL performance tuning'

API Key Configuration:

The CLI client supports three ways to provide LLM API keys (in priority order):

1. Environment variables (recommended for development):

   export ANTHROPIC_API_KEY="sk-ant-..."
export OPENAI_API_KEY="sk-proj-..."

2. API key files (recommended for production):

   echo "sk-ant-..." > ~/.anthropic-api-key
chmod 600 ~/.anthropic-api-key

3. Configuration file values (not recommended - use env vars or files
instead)

See Using the CLI Client for detailed documentation.

cp examples/pgedge-postgres-mcp-http.yaml.example bin/pgedge-postgres-mcp-http.yaml
cp examples/pgedge-postgres-mcp-users.yaml.example bin/pgedge-postgres-mcp-users.yaml
cp examples/pgedge-postgres-mcp-tokens.yaml.example bin/pgedge-postgres-mcp-tokens.yaml

nano bin/pgedge-postgres-mcp-http.yaml

Deploy the entire stack with Docker Compose for production or development:


cp .env.example .env

nano .env # Add your database connection, API keys, etc.

The project uses golangci-lint v1.x. Install it with:

bash
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest

Note: The configuration file .golangci.yml is compatible
with golangci-lint v1.x (not v2).

./bin/pgedge-postgres-mcp

pgEdge Postgres MCP Server and Natural Language Agent

CI - MCP Server
CI - CLI Client
CI - Web Client
CI - Docker
CI - Documentation

- Introduction
- Choosing the Right Solution
- Installing the MCP Server
- Deploying on Docker
- Deploying from Source
- Accessing Online Help
- Configuring the MCP Server
- Specifying Configuration Preferences
- Using Environment Variables to Specify Options
- Including Provider Embeddings in a Configuration File
- Configuring the Agent for Multiple Databases
- Configuring Supporting Services; HTTP, systemd, and nginx
- Using an Encryption Secret File
- Enabling or Disabling Features
- Configuring and Using Client Applications
- Connecting with the Web Client
- Using the Go Chat Client
- Using the Claude Desktop
- Authentication and Security
- Authentication Overview
- User Authentication Management
- Token Authentication Management
- Security Best Practices - Checklist
- Security Management
- Reference
- Tools
- Resources
- Prompts
- Examples
- Advanced Topics
- Custom Definitions
- Knowledgebase
- LLM Proxy
- For Developers
- Overview
- MCP Protocol
- API Reference
- Building Chat Clients
- Overview
- Python - Stdio and Claude
- Python - HTTP and OLLAMA
- Contributing
- Development Setup
- Architecture
- Internal Architecture
- KB Builder
- Testing
- CI/CD
- Troubleshooting
- pgEdge Postgres MCP Server and Natural Language Agent Release Notes
- Licence

The pgEdge Postgres Model Context Protocol (MCP) server enables SQL queries against
PostgreSQL databases through MCP-compatible clients like Claude Desktop. The Natural Language Agent provides supporting functionality that allows you to use natural language to form SQL queries.

> 🚧 WARNING: This code is in pre-release status and MUST NOT be put
> into production without thorough testing!

> ⚠️ NOT FOR PUBLIC-FACING APPLICATIONS: This MCP server provides LLMs
> with read access to your entire database schema and data. It should only be
> used for internal tools, developer workflows, or environments where all users
> are trusted. For public-facing applications, consider the
> pgEdge RAG Server instead.
> See the Choosing the Right Solution guide for
> details.

Key Features

- 🔒 Read-Only Protection - All queries run in read-only transactions
- 📊 Resources - Access PostgreSQL statistics and more
- 🛠️ Tools - Query execution, schema analysis, advanced hybrid search
(BM25+MMR), embedding generation, resource reading, and more
- 🧠 Prompts - Guided workflows for semantic search setup, database
exploration, query diagnostics, and more
- 💬 Production Chat Client - Full-featured Go client with Anthropic
prompt caching (90% cost reduction)
- 🌐 HTTP/HTTPS Mode - Direct API access with token authentication
- 🖥️ Web Interface - Modern React-based UI with AI-powered chat for
natural language database interaction
- 🐳 Docker Support - Complete containerized deployment with Docker
Compose
- 🔐 Secure - TLS support, token auth, read-only enforcement
- 🔄 Hot Reload - Automatic reload of authentication files without server
restart

Quick Start

1. Installation

git clone <repository-url>
cd pgedge-postgres-mcp
make build

2. Configure for Claude Code and/or Claude Desktop

Claude Code: .mcp.json in each of your project directories
Claude Desktop on macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Claude Desktop on Windows: %APPDATA%\\Claude\\claude_desktop_config.json

{
  "mcpServers": {
    "pgedge": {
      "command": "/absolute/path/to/bin/pgedge-postgres-mcp"
    }
  }
}

3. Connect to Your Database

Update your Claude Code and/or Claude Desktop configuration to include database connection
parameters:

{
  "mcpServers": {
    "pgedge": {
      "command": "/absolute/path/to/bin/pgedge-postgres-mcp",
      "env": {
        "PGHOST": "localhost",
        "PGPORT": "5432",
        "PGDATABASE": "mydb",
        "PGUSER": "myuser",
        "PGPASSWORD": "mypass"
      }
    }
  }
}

Alternatively, use a .pgpass file for password management (recommended for
security):

```bash

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.