Skip to main content
Glama
asadudin

MCP Server for PostgreSQL

by asadudin

PostgreSQL用MCPサーバー

ライセンス: MIT Dockerプル

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の使用(推奨)

  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_ポート

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
pytest

Dockerイメージの構築

docker build -t mcp-server-postgres .

APIドキュメント

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

貢献

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

ライセンス

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

謝辞

  • FastMCP - MCP サーバーフレームワーク

  • asyncpg - Python 用 PostgreSQL クライアント

  • FastAPI - API を構築するための最新の高速 Web フレームワーク

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.

No tool schema history has been recorded yet.

Maintenance

ActivityInactive
ResponsivenessSyncing

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • A
    license
    B
    quality
    B
    maintenance
    A Model Context Protocol server that enables powerful PostgreSQL database management capabilities including analysis, schema management, data migration, and monitoring through natural language interactions.
    18
    1,692
    198
    AGPL 3.0
  • A
    license
    Not graded
    quality
    D
    maintenance
    A Model Context Protocol server that enables performing PostgreSQL database operations (create, read, update, delete) on User and Post entities through MCP tools.
    751
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    A Model Context Protocol server that enables interaction with PostgreSQL databases to list tables, retrieve schemas, and execute read-only SQL queries.
    29
    MIT
  • F
    license
    Not graded
    quality
    D
    maintenance
    An 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.
    -

Appeared in Searches

Latest Blog Posts

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