MCP Server for PostgreSQL
PostgreSQL用MCPサーバー
PostgreSQL 用のモデル コンテキスト プロトコル (MCP) サーバー実装。MCP を介して PostgreSQL データベースと対話するためのシンプルなインターフェイスを提供します。
特徴
パラメータ化された入力でSQLクエリを実行する
INSERT/UPDATE/DELETE操作を実行する
新しいデータベースを作成する
テーブルスキーマの作成または更新
PostgreSQL接続のデバッグ
Dockerでコンテナ化して簡単に導入できる
環境ベースの構成
Related MCP server: MCP PostgreSQL Server
前提条件
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文字列(リストまたは辞書)
例:
{
"query": "SELECT * FROM users WHERE id = $1",
"params": [1]
}sql_execute
INSERT/UPDATE/DELETE ステートメントを実行します。
パラメータ:
query: SQL文params: クエリパラメータのオプションのJSON文字列(リストまたは辞書)
例:
{
"query": "INSERT INTO users (name, email) VALUES ($1, $2)",
"params": ["John Doe", "john@example.com"]
}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サーバーを実行するポート |
発達
テストの実行
# Install test dependencies
pip install -r requirements-dev.txt
# Run tests
pytestDockerイメージの構築
docker build -t mcp-server-postgres .APIドキュメント
詳細な API ドキュメントについては、 OpenAPI 仕様を参照してください。
貢献
貢献を歓迎します!お気軽にプルリクエストを送信してください。
ライセンス
このプロジェクトは MIT ライセンスに基づいてライセンスされています - 詳細についてはLICENSEファイルを参照してください。
謝辞
Related MCP Connectors
Hosted PostgreSQL MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
Text-to-SQL MCP server: read-only queries on PostgreSQL, MySQL and SQL Server with your real schema
MCP server for interacting with the Supabase platform
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
Related MCP Servers
- AlicenseBqualityDmaintenanceA Model Context Protocol server that enables powerful PostgreSQL database management capabilities including analysis, schema management, data migration, and monitoring through natural language interactions.181,931 npm203AGPL 3.0
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that enables performing PostgreSQL database operations (create, read, update, delete) on User and Post entities through MCP tools.522 npmMIT
- AlicenseNot gradedqualityCmaintenanceA Model Context Protocol server that enables interaction with PostgreSQL databases to list tables, retrieve schemas, and execute read-only SQL queries.13 npmMIT
- FlicenseNot gradedqualityDmaintenanceAn MCP server that enables AI assistants to interact with PostgreSQL databases by executing SQL queries and inspecting database schemas. It provides tools for standardized database exploration and management through the Model Context Protocol.-