PostgreSQL Model Context Protocol (PG-MCP) Server

by tanster1234

194 downloads
Not rated
GitHub

Description

# PostgreSQL Model Context Protocol (PG-MCP) Server A Model Context Protocol (MCP) server for PostgreSQL databases with enhanced capabilities for AI agents. ## Overview PG-MCP is a server implementation of the [Model Context Protocol](https://modelcontextprotocol.io) for…

About

# PostgreSQL Model Context Protocol (PG-MCP) Server A Model Context Protocol (MCP) server for PostgreSQL databases with enhanced capabilities for AI agents. ## Overview PG-MCP is a server implementation of the [Model Context Protocol](https://modelcontextprotocol.io) for PostgreSQL databases. It provides a…

Details

Author
tanster1234
Downloads
194
Categories
Database

- Multi-database support with simultaneous connections.
- Rich catalog information from table/column descriptions.
- Query execution plan analysis via pg_explain tool.
- Built-in extension context for PostGIS and pgvector.
- Read-only mode enforced via transaction settings.
- Connection pooling and secure opaque connection IDs.

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name PostgreSQL Model Context Protocol (PG-MCP) Server
    Command (node, npx, python, etc.)

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

Install via Docker or manual setup with Python 3.13+. Run python -m server.app after installing dependencies with uv sync --frozen. Clients connect to the SSE endpoint (default http://localhost:8000/sse) and invoke tools like connect, pg_query, and pg_explain using a secure connection ID.

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "postgresql model context protocol (pg-mcp) server": {
            "mcp_server_postgres": {
                "command": "python",
                "args": [
                    "-m",
                    "venv",
                    ".venv"
                ]
            }
        }
    }
}

McpServers

{
    "mcp_server_postgres": {
        "command": "python",
        "args": [
            "-m",
            "venv",
            ".venv"
        ]
    }
}

PostgreSQL Model Context Protocol (PG-MCP) Server

A Model Context Protocol (MCP) server for PostgreSQL databases with enhanced capabilities for AI agents.

Overview

PG-MCP is a server implementation of the Model Context Protocol for PostgreSQL databases. It provides a comprehensive API for AI agents to discover, connect to, query, and understand PostgreSQL databases through MCP's resource-oriented architecture.

This implementation builds upon and extends the reference Postgres MCP implementation with several key enhancements:

1. Full Server Implementation: Built as a complete server with SSE transport for production use
2. Multi-database Support: Connect to multiple PostgreSQL databases simultaneously
3. Rich Catalog Information: Extracts and exposes table/column descriptions from the database catalog
4. Extension Context: Provides detailed YAML-based knowledge about PostgreSQL extensions like PostGIS and pgvector
5. Query Explanation: Includes a dedicated tool for analyzing query execution plans
6. Robust Connection Management: Proper lifecycle for database connections with secure connection ID handling

Features

Connection Management

- Connect Tool: Register PostgreSQL connection strings and get a secure connection ID
- Disconnect Tool: Explicitly close database connections when done
- Connection Pooling: Efficient connection management with pooling

Query Tools

- pg_query: Execute read-only SQL queries using a connection ID
- pg_explain: Analyze query execution plans in JSON format

Schema Discovery Resources

- List schemas with descriptions
- List tables with descriptions and row counts
- Get column details with data types and descriptions
- View table constraints and indexes
- Explore database extensions

Data Access Resources

- Sample table data (with pagination)
- Get approximate row counts

Extension Context

Built-in contextual information for PostgreSQL extensions like:

- PostGIS: Spatial data types, functions, and examples
- pgvector: Vector similarity search functions and best practices

Additional extensions can be easily added via YAML config files.

Installation

Prerequisites

- Python 3.13+
- PostgreSQL database(s)

Using Docker

```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.