PostgreSQL MCP Server

by hthuong09
Verified

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

Integrations

  • Enables interaction with PostgreSQL databases, allowing users to list tables, retrieve schemas, and execute read-only SQL queries against PostgreSQL databases.

MCP PostgreSQLサーバー

これは、PostgreSQLデータベースとやり取りするためのモデルコンテキストプロトコル(CMP)サーバーです。PostgreSQLデータベースへのクエリとスキーマの検査を行うための読み取り専用インターフェースを提供します。

インストール

npm install -g @hthuong09/postgres-mcp

構成

サーバーは複数の方法で構成できます。優先順位は次のとおりです。

  1. 環境変数
    • POSTGRES_URL : 完全なデータベース URL (例: postgres://user:pass@host:5432/dbname )
    • 個別の接続パラメータ:
      • POSTGRES_HOST : データベースホスト
      • POSTGRES_PORT : データベースポート(デフォルト: 5432)
      • POSTGRES_DB : データベース名
      • POSTGRES_USER : データベースユーザー
      • POSTGRES_PASSWORD : データベースパスワード
      • POSTGRES_SSL : SSL モードを有効にする (有効にするには 'true' に設定)
      • POSTGRES_SCHEMA : データベーススキーマ(デフォルト: 'public')
    • 追加構成:
      • DOTENV_PATH : .env ファイルへのカスタムパス
      • DEBUG_MCP : デバッグログを有効にする(有効にするには「true」に設定)
  2. コマンドライン
    npx @hthuong09/postgres-mcp "postgres://user:pass@host:5432/dbname"

リソース

  • テーブルスキーマ: データベース内の各テーブルはリソースとして公開されます
  • リソース URI 形式: postgres://user@host/dbname/table_name/schema
  • レスポンス形式: 列定義のJSON配列(名前とデータ型)

使用例

  1. 環境変数の使用:
    export POSTGRES_HOST=localhost export POSTGRES_DB=mydb export POSTGRES_USER=myuser export POSTGRES_PASSWORD=mypassword npx @hthuong09/postgres-mcp
  2. 接続 URL の使用:
    npx @hthuong09/postgres-mcp "postgres://myuser:mypassword@localhost:5432/mydb"
  3. SSL で環境変数を使用する:
    export POSTGRES_HOST=db.example.com export POSTGRES_DB=mydb export POSTGRES_USER=myuser export POSTGRES_PASSWORD=mypassword export POSTGRES_SSL=true npx @hthuong09/postgres-mcp
  4. カスタム .env ファイルの場所を使用する:
    DOTENV_PATH=/path/to/.env npx @hthuong09/postgres-mcp

セキュリティに関する考慮事項

  • データベースの資格情報は安全に保管する必要がある
  • プロセスリストで資格情報が公開されないように、本番環境ではコマンドライン引数の代わりに環境変数または .env ファイルを使用します。
  • 実稼働環境ではSSLの使用を検討する
  • サーバーは安全のため読み取り専用トランザクションのみを許可します
  • パスワードはリソースURIから自動的に削除されます

発達

ローカルでサーバーを構築するには:

npm install npm run build

開発中にウォッチモードで実行するには:

npm run watch

デバッグ

デバッグログを有効にするには、 DEBUG_MCP=trueを設定します。ログは次の場所に書き込まれます。

  • Unix/macOS: /tmp/postgres-mcp-debug.json
  • Windows: %TEMP%/postgres-mcp-debug.json

ライセンス

マサチューセッツ工科大学

-
security - not tested
F
license - not found
-
quality - not tested

PostgreSQL データベースと対話してテーブルを一覧表示したり、スキーマを取得したり、読み取り専用 SQL クエリを実行したりできるようにするモデル コンテキスト プロトコル サーバー。

  1. Installation
    1. Configuration
      1. Resources
    2. Usage Examples
      1. Security Considerations
        1. Development
          1. Debugging
            1. License
              ID: c92j003vx0