SP

stuzero/pg-mcp-server

Developer tools

このページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。 原文を見る

540 stars 43 forks 品質 49 トレンド 20MIT

AIエージェント向けの強化機能を備えたPostgreSQLデータベース向けのモデルコンテキストプロトコル(MCP)サーバー。

概要

AIエージェント向けの強化機能を備えたPostgreSQLデータベース向けのモデルコンテキストプロトコル(MCP)サーバー。 PG-MCPは、PostgreSQLデータベース向けのモデルコンテキストプロトコルのサーバー実装です。これは、MCPのリソース指向アーキテクチャを通じて、AIエージェントがPostgreSQLデータベースを発見し、接続し、クエリし、理解するための包括的なAPIを提供します。 この実装は、参照版Postgres MCP実装を基盤とし、いくつかの重要な強化を加えています。 1. : 本番環境向けのSSEトランスポートを備えた完全なサーバーとして構築 2.: 複数のPostgreSQLデータベースに同時に接続 3.: データベースカタログからテーブル/列の記述を抽出・公開 4.: PostGISやpgvector 5などのPostgreSQL拡張に関する詳細なYAMLベースの知識を提供します。: クエリ実行計画を解析するための専用ツールを含みます 6.

概要(AI 翻訳)

AIエージェント向けの強化機能を備えたPostgreSQLデータベース向けのモデルコンテキストプロトコル(MCP)サーバー。

PG-MCPプロジェクトの詳細はこちら:

https://stuzero.github.io/pg-mcp/

概要

PG-MCPは、PostgreSQLデータベース向けのモデルコンテキストプロトコルのサーバー実装です。これは、MCPのリソース指向アーキテクチャを通じて、AIエージェントがPostgreSQLデータベースを発見し、接続し、クエリし、理解するための包括的なAPIを提供します。

この実装は、参照版Postgres MCP実装を基盤とし、いくつかの重要な強化を加えています。

  1. フルサーバー実装:本番環境向けにSSEトランスポートを備えた完全なサーバーとして構築
  2. マルチデータベースサポート:複数のPostgreSQLデータベースに同時に接続
  3. リッチカタログ情報:データベースカタログからテーブル/カラムの記述を抽出・公開
  4. 拡張コンテキスト:PostGISやpgvectorなどのPostgreSQL拡張に関する詳細なYAMLベースの知識を提供します
  5. クエリ説明:クエリ実行計画を分析するための専用ツールが含まれています
  6. 堅牢な接続管理:安全な接続ID処理を備えたデータベース接続の適切なライフサイクル

特徴

このページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。

README

以下は原文 README の抜粋です。原文を見る。

PostgreSQL Model Context Protocol (PG-MCP) Server

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

More info on the pg-mcp project here:

https://stuzero.github.io/pg-mcp/

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

# Clone the repository
git clone https://github.com/stuzero/pg-mcp-server.git
cd pg-mcp-server

# Build and run with Docker Compose
docker-compose up -d

Manual Installation

# Clone the repository
git clone https://github.com/stuzero/pg-mcp-server.git
cd pg-mcp-server

# Install dependencies and create a virtual environment ( .venv )
uv sync

# Activate the virtual environment
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Run the server
GitHub で README 全文を見る

インストール

This server does not publish a one-line install command.

Open the repository installation guide MCP 初心者?mcpskill.org のガイドから始めましょう →