PostgreSQL MCPとは
PostgreSQLはMCPサーバーです。 AIコーディングエージェントがPostgreSQLデータベースへのクエリ、変更、検査を行い、接続プロファイルの管理やパフォーマンス診断を実行できるようにします。.
プロジェクトのREADMEから生成された概要
PostgreSQL MCP server について
PostgreSQLデータベースに対して直接作業を行う必要があるコーディングエージェントは、postgres-mcpを呼び出して、クエリ、スキーマ設計、診断、CSVインポートを行うことができます。このツールはNode.js 22以降で動作するstdio経由のMCP serverであり、npxを使用してインストール不要で起動できます。GitHub Copilot、Claude Code、Codex、Open Code、Cursor、VS Code、Claude Desktopを含むすべてのMCPクライアントに対応しています。クライアントの設定はnpxの実行コマンドを指すのみで、認証情報は含みません。エージェントは実行時に保存されたプロファイルを読み込みます。
プロファイルは、libpq URIまたはkey=value形式の文字列を用いたconnection addコマンドで一度作成するだけで、パスワードは設定ファイルではなくOSのキーリングに保持されます。キーリングのないヘッドレス環境やCI環境では、環境変数から接続文字列を取得できます。Azureプロファイルでキーリングにパスワードが保存されていない場合は、Microsoft Entra IDが自動的に選択されます。ツールセットには、postgres_mcp_queryによる読み取り専用SQL、postgres_mcp_modifyによるDDLおよびDML、テーブル・インデックス・関数・シーケンスのCREATEスクリプト、COPYによるCSVの記述と一括ロード、機能の調査、およびパフォーマンスメトリクスグループが含まれます。
サーバーは指定されたユーザーとしてリクエストを実行するため、アクセス制御はデータベースのロールに依存します。読み取り専用プロファイルはaccess_mode: roで設定できます。ローカルファイルの読み取りは、パスが明示的に許可されていない限り、起動時の作業ディレクトリに制限され、エラーメッセージから機密情報は削除されます。
できること
- 1Postgresから最新の注文を取得するSQLクライアントを開くことなく、テストデータを確認するために、エージェントに最新の注文を10件表示するよう依頼できます。
- 2現在のデータベースのボトルネックを特定するエージェントにパフォーマンスメトリクスグループを収集させ、現在サーバーの動作を遅らせている原因を特定させます。
- 3データベース内のテーブルを一覧表示するスキーマ設計の開始点として、接続されたデータベース内のテーブルの一覧を取得します。
プロジェクトの README から作成されています。すべてのユースケースは、その引用と照らし合わせて確認されています。
PostgreSQL MCPのインストール方法
フォーマット検証日 2026年11月10日Claude CodeにPostgreSQL MCPをインストール
$ claude mcp add postgres-mcp -- npx -y @microsoft/postgres-mcpCursorにPostgreSQL MCPをインストール
~/.cursor/mcp.json
{
"mcpServers": {
"postgres-mcp": {
"command": "npx",
"args": [
"-y",
"@microsoft/postgres-mcp"
]
}
}
}VS CodeにPostgreSQL MCPをインストール
.vscode/mcp.json
{
"servers": {
"postgres-mcp": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@microsoft/postgres-mcp"
]
}
}
}Claude DesktopにPostgreSQL MCPをインストール
claude_desktop_config.json
{
"mcpServers": {
"postgres-mcp": {
"command": "npx",
"args": [
"-y",
"@microsoft/postgres-mcp"
]
}
}
}CodexにPostgreSQL MCPをインストール
~/.codex/config.toml
[mcp_servers.postgres-mcp] command = "npx" args = ["-y", "@microsoft/postgres-mcp"]
Gemini CLIにPostgreSQL MCPをインストール
~/.gemini/settings.json
{
"mcpServers": {
"postgres-mcp": {
"command": "npx",
"args": [
"-y",
"@microsoft/postgres-mcp"
]
}
}
}自動チェック
実行日 2026年11月13日詳細レポート →自動チェックに合格しました。これはセキュリティ監査ではありません。コードを読み、サーバーに必要最小限のアクセス権を与えてください。 チェックの仕組み
- ソースリポジトリがリンクされており、アクセス可能合格
- オープンソースライセンス (OSI)合格
- 過去1年以内にコミットまたはリリースあり合格
- パッケージ名が有名なパッケージに酷似していない合格
- リモートエンドポイントがHTTPSを使用未チェック
- 破壊的なツールがラベル付けされている未チェック
- モデルへの隠れた指示がない合格
- パッケージと依存関係に重大なアドバイザリがない未チェック
README
GitHubで見るPostgres MCP Server
Connect your coding agent to PostgreSQL. postgres-mcp lets you generate
queries and run analytics, design database schemas, diagnose performance of the
server and queries, securely manage connections, and import data. It is
compatible with any MCP client — GitHub Copilot, Claude Code, Codex, Open Code,
Cursor, VS Code, and more.
- npm: https://www.npmjs.com/package/@microsoft/postgres-mcp
- No install required — run it straight from
npx.
Quick start
1. Save a connection profile
Create a named profile once — the password is stored in your OS keyring, never in a config file:
# add a profile from a libpq URI or key=value string
npx -y @microsoft/postgres-mcp connection add local \
"postgresql://postgres@localhost:5432/postgres"
# store its password securely (hidden prompt)
npx -y @microsoft/postgres-mcp connection set-password local
# check it
npx -y @microsoft/postgres-mcp connection list
Profiles created by
connection addpermit write tools unlessaccess_mode: rois set. For autonomous agents that should not write, use an explicit read-only profile and a read-only database role — see Read-only profiles.
2. Add postgres-mcp to your coding agent
The server speaks MCP over stdio. Point your client at
npx @microsoft/postgres-mcp run — no credentials go in the client config; the
coding agent discovers and connects to your saved profile at runtime.
GitHub Copilot CLI, Claude Code, Cursor & Claude Desktop — clients that use the mcpServers format (~/.copilot/mcp-config.json, mcp.json, .cursor/mcp.json, claude_desktop_config.json, …):
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["-y", "@microsoft/postgres-mcp", "run"]
}
}
}
Running headless or in CI, without a keyring? The server can also take a database connection string from the environment — see Connecting without a profile in the guide.
3. Ask your coding agent
"List the tables in my PostgreSQL database." "Show me the 10 most recent orders from my PostgreSQL database." "What's slowing down my PostgreSQL server right now?"
The agent calls the server's tools (postgres_mcp_connect,
postgres_mcp_query, postgres_mcp_db_context, …) for you.
What it can do
| Area | Tools |
|---|---|
| Connections | list / add / remove profiles, connect, disconnect, list databases |
| Query | read‑only SQL (postgres_mcp_query), DDL/DML (postgres_mcp_modify) |
| Schema | fetch CREATE scripts for tables, indexes, functions, sequences… |
| Data | describe a CSV, bulk‑load a CSV via COPY |
| Diagnostics | probe server capabilities, collect performance metric groups |
See the usage guide for tools, configuration, authentication (including Microsoft Entra ID), TLS, and the security model.
Security in one minute
- The server doesn't decide what's allowed — your database does. It just passes requests along to PostgreSQL and runs them as the database user in your connection profile. It can't tell the difference between a request you meant to make and one the AI invented or was tricked into making, so anything that database user can do, the AI can do. What actually protects you is the permissions you give that user, the approval prompts in your MCP client, and the model you choose to run. See Security model for who's responsible for what, plus a checklist for locking things down.
postgres_mcp_queryis read‑only. Omitted profileaccess_modepermits write tools; setaccess_mode: roand use a read-only database role unless writes are intentionally delegated.- Microsoft Entra ID (AAD) is selected automatically for Azure profiles without a stored keyring password. Store a profile password to use password authentication instead.
- Local file reads (
postgres_mcp_bulk_load_csv,postgres_mcp_describe_csv) are limited to the MCP server's startup working directory by default and paths allowed withallow-access-to-path <path>. A file allows only itself; a directory allows recursive access. - Secrets are scrubbed from error messages before they leave the process.
See more info about security model in the usage guide.
Requirements
- Node.js 22+ (to run via
npx). - Linux x64/arm64, macOS x64/arm64, or Windows x64. Windows ARM uses x64 emulation.
- A reachable PostgreSQL database — local, Docker, on‑premises, Azure Database for PostgreSQL, Amazon RDS/Aurora, Google Cloud SQL/AlloyDB, or any wire‑compatible server.
Changelog
See CHANGELOG.md for release notes.
License
This repository is a getting started information package. It is licensed under the MIT License © Microsoft. The postgres-mcp project itself is proprietary and its source code is not avialable under MIT license.
PostgreSQL MCPのよくある質問
PostgreSQL MCPをClaude Codeに追加するには
ターミナルでclaude mcp add postgres-mcp -- npx -y @microsoft/postgres-mcpを実行します。すべてのプロジェクトで利用するには--scope userを追加します。
PostgreSQL MCPをCursorに追加するには
~/.cursor/mcp.jsonを開き、上記のインストールセクションに示すCursor設定を使ってmcpServersの下にサーバーを追加します。
postgres-mcpをClaude CodeやGitHub Copilotに接続するにはどうすればよいですか?
クライアントのmcpServers設定に、npx @microsoft/postgres-mcp runを指すstdioエントリを追加してください。その設定ファイルに認証情報を記述する必要はありません。
データベースのパスワードはどこに保存されますか?
パスワードはconnection set-passwordを使用してOSのキーリングに保存されます。設定ファイルには保存されません。
クエリツールは読み取り専用ですか?
はい、postgres_mcp_queryは読み取り専用です。ただし、プロファイルでaccess_modeがroに設定されていない限り、書き込みツールも利用可能です。
プロファイルを保存せずに(CI環境などで)使用することはできますか?
はい、キーリングが利用できない場合、サーバーは環境変数からデータベース接続文字列を受け取ることができます。
必要なNode.jsのバージョンは?
npx経由で実行するには、Node.js 22以降が必要です。