Skip to main content
Glama

MCP Server for PostgreSQL

by asadudin

PostgreSQL用MCPサーバー

PostgreSQL 用のモデル コンテキスト プロトコル (MCP) サーバー実装。MCP を介して PostgreSQL データベースと対話するためのシンプルなインターフェイスを提供します。

特徴

  • パラメータ化された入力でSQLクエリを実行する
  • INSERT/UPDATE/DELETE操作を実行する
  • 新しいデータベースを作成する
  • テーブルスキーマの作成または更新
  • PostgreSQL接続のデバッグ
  • Dockerでコンテナ化して簡単に導入できる
  • 環境ベースの構成

前提条件

  • Python 3.8以上
  • PostgreSQL 10以上
  • Docker (オプション、コンテナ化されたデプロイメント用)
  • Docker Compose(オプション、開発用)

インストール

Dockerの使用(推奨)

  1. リポジトリをクローンします。
    git clone https://github.com/asadudin/mcp-server-postgres.git cd mcp-server-postgres
  2. サンプル環境ファイルをコピーします。
    cp .env.example .env
  3. PostgreSQL の資格情報を使用して.envファイルを更新します。
    PG_HOST=postgres PG_PORT=5432 PG_USER=postgres PG_PASSWORD=your_password PG_DATABASE=your_database HOST=0.0.0.0 PORT=8056
  4. Docker Compose を使用してサービスを開始します。
    docker-compose up -d

手動インストール

  1. リポジトリをクローンします。
    git clone https://github.com/asadudin/mcp-server-postgres.git cd mcp-server-postgres
  2. 仮想環境を作成してアクティブ化します。
    python -m venv venv source venv/bin/activate # On Windows: .\venv\Scripts\activate
  3. 依存関係をインストールします:
    pip install -r requirements.txt
  4. サンプル環境ファイルをコピーして更新します。
    cp .env.example .env # Edit .env with your configuration
  5. サーバーを実行します。
    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_ポート5432PostgreSQL ポート
PG_ユーザーポストグルPostgreSQLユーザー名
PG_パスワードPostgreSQLパスワード
PG_データベースポストグルデフォルトのデータベース名
ホスト0.0.0.0MCPサーバーをバインドするホスト
ポート8056MCPサーバーを実行するポート

発達

テストの実行

# Install test dependencies pip install -r requirements-dev.txt # Run tests pytest

Dockerイメージの構築

docker build -t mcp-server-postgres .

APIドキュメント

詳細な API ドキュメントについては、 OpenAPI 仕様を参照してください。

貢献

貢献を歓迎します!お気軽にプルリクエストを送信してください。

ライセンス

このプロジェクトは MIT ライセンスに基づいてライセンスされています - 詳細についてはLICENSEファイルを参照してください。

謝辞

  • FastMCP - MCP サーバーフレームワーク
  • asyncpg - Python 用 PostgreSQL クライアント
  • FastAPI - API を構築するための最新の高速 Web フレームワーク
-
security - not tested
F
license - not found
-
quality - not tested

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

PostgreSQL データベースと対話するためのシンプルなインターフェイスを提供し、MCP を介した SQL クエリ、データベース操作、およびスキーマ管理を可能にするモデル コンテキスト プロトコル サーバー実装。

  1. 特徴
    1. 前提条件
      1. インストール
        1. Dockerの使用(推奨)
        2. 手動インストール
      2. 使用法
        1. sql_query
        2. sql_execute
        3. create_database
        4. create_or_update_table
        5. debug_postgres_connection
      3. 環境変数
        1. 発達
          1. テストの実行
          2. Dockerイメージの構築
        2. APIドキュメント
          1. 貢献
            1. ライセンス
              1. 謝辞

                Related MCP Servers

                • -
                  security
                  F
                  license
                  -
                  quality
                  A 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 -
                  141
                  7
                  JavaScript
                • A
                  security
                  A
                  license
                  A
                  quality
                  A 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 -
                  18
                  438
                  89
                  TypeScript
                  AGPL 3.0
                  • Linux
                  • Apple
                • -
                  security
                  F
                  license
                  -
                  quality
                  A Model Context Protocol server that enables performing PostgreSQL database operations (create, read, update, delete) on User and Post entities through MCP tools.
                  Last updated -
                  TypeScript
                • -
                  security
                  A
                  license
                  -
                  quality
                  A Model Context Protocol server that enables interaction with PostgreSQL databases to list tables, retrieve schemas, and execute read-only SQL queries.
                  Last updated -
                  35
                  JavaScript
                  MIT License
                  • Linux
                  • Apple

                View all related MCP servers

                MCP directory API

                We provide all the information about MCP servers via our MCP API.

                curl -X GET 'https://glama.ai/api/mcp/v1/servers/asadudin/mcp-server-postgres'

                If you have feedback or need assistance with the MCP directory API, please join our Discord server