PostgreSQL用MCPサーバー
PostgreSQL 用のモデル コンテキスト プロトコル (MCP) サーバー実装。MCP を介して PostgreSQL データベースと対話するためのシンプルなインターフェイスを提供します。
特徴
パラメータ化された入力でSQLクエリを実行する
INSERT/UPDATE/DELETE操作を実行する
新しいデータベースを作成する
テーブルスキーマの作成または更新
PostgreSQL接続のデバッグ
Dockerでコンテナ化して簡単に導入できる
環境ベースの構成
前提条件
Python 3.8以上
PostgreSQL 10以上
Docker (オプション、コンテナ化されたデプロイメント用)
Docker Compose(オプション、開発用)
インストール
Dockerの使用(推奨)
リポジトリをクローンします。
git clone https://github.com/asadudin/mcp-server-postgres.git cd mcp-server-postgresサンプル環境ファイルをコピーします。
cp .env.example .envPostgreSQL の資格情報を使用して
.env
ファイルを更新します。PG_HOST=postgres PG_PORT=5432 PG_USER=postgres PG_PASSWORD=your_password PG_DATABASE=your_database HOST=0.0.0.0 PORT=8056Docker Compose を使用してサービスを開始します。
docker-compose up -d
手動インストール
リポジトリをクローンします。
git clone https://github.com/asadudin/mcp-server-postgres.git cd mcp-server-postgres仮想環境を作成してアクティブ化します。
python -m venv venv source venv/bin/activate # On Windows: .\venv\Scripts\activate依存関係をインストールします:
pip install -r requirements.txtサンプル環境ファイルをコピーして更新します。
cp .env.example .env # Edit .env with your configurationサーバーを実行します。
python mcp_server_postgres.py
使用法
MCP サーバーは次のエンドポイントを提供します。
sql_query
SELECT クエリを実行し、結果を JSON として返します。
パラメータ:
query
: SQLクエリ文字列params
: クエリパラメータのオプションのJSON文字列(リストまたは辞書)
例:
sql_execute
INSERT/UPDATE/DELETE ステートメントを実行します。
パラメータ:
query
: SQL文params
: クエリパラメータのオプションのJSON文字列(リストまたは辞書)
例:
create_database
新しい PostgreSQL データベースを作成します。
パラメータ:
database_name
: 作成するデータベースの名前
create_or_update_table
テーブル スキーマを作成または更新します。
パラメータ:
sql
: CREATE TABLE または ALTER TABLE SQL ステートメント
debug_postgres_connection
PostgreSQL 接続をデバッグします。
環境変数
変数 | デフォルト | 説明 |
PG_ホスト | ローカルホスト | PostgreSQLホスト |
PG_ポート | 5432 | PostgreSQL ポート |
PG_ユーザー | ポストグル | PostgreSQLユーザー名 |
PG_パスワード | PostgreSQLパスワード | |
PG_データベース | ポストグル | デフォルトのデータベース名 |
ホスト | 0.0.0.0 | MCPサーバーをバインドするホスト |
ポート | 8056 | MCPサーバーを実行するポート |
発達
テストの実行
Dockerイメージの構築
APIドキュメント
詳細な API ドキュメントについては、 OpenAPI 仕様を参照してください。
貢献
貢献を歓迎します!お気軽にプルリクエストを送信してください。
ライセンス
このプロジェクトは MIT ライセンスに基づいてライセンスされています - 詳細についてはLICENSEファイルを参照してください。
謝辞
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
PostgreSQL データベースと対話するためのシンプルなインターフェイスを提供し、MCP を介した SQL クエリ、データベース操作、およびスキーマ管理を可能にするモデル コンテキスト プロトコル サーバー実装。
Related MCP Servers
- -securityFlicense-qualityA Model Context Protocol server providing both read and write access to PostgreSQL databases, enabling LLMs to query data, modify records, and manage database schemas.Last updated -5837
- AsecurityAlicenseAqualityA Model Context Protocol server that enables powerful PostgreSQL database management capabilities including analysis, schema management, data migration, and monitoring through natural language interactions.Last updated -181,016119AGPL 3.0
- -securityFlicense-qualityA Model Context Protocol server that enables performing PostgreSQL database operations (create, read, update, delete) on User and Post entities through MCP tools.Last updated -
- -securityAlicense-qualityA Model Context Protocol server that enables interaction with PostgreSQL databases to list tables, retrieve schemas, and execute read-only SQL queries.Last updated -26MIT License