PostgreSQL MCPサーバー
コミット 2026年11月9日AIアシスタントに対し、スキーマの探索、データプロファイリング、および安全な読み取り/書き込み操作のための、構造化されたPostgreSQLデータベースへのアクセスを提供します。
別名 ralscha/postgresql-mcp
- スター
- 0
- ツール
- 24
- ダウンロード数(30日間)
- —
- 最新バージョン
- —
- 最終コミット
- 2026年11月9日
- ライセンス
- MIT
PostgreSQL MCPとは
PostgreSQLはMCPサーバーです。 AIアシスタントに対し、スキーマの探索、データプロファイリング、および安全な読み取り/書き込み操作のための、構造化されたPostgreSQLデータベースへのアクセスを提供します。. 24個のツールを提供しており、search_schema, describe_table, list_tableなどがあります。
プロジェクトのREADMEから生成された概要
PostgreSQL MCP server について
このMCP serverは、AIアシスタントをPostgreSQLデータベースに接続し、スキーマの探索やデータ管理を可能にします。開発者は、単純なテーブルの説明から、複雑なリレーションシップの分析、クエリのパフォーマンス調査まで、幅広いタスクを実行するための構造化されたインターフェースを利用できます。このサーバーは、ローカルのstdio通信とリモートのHTTPトランスポートの両方をサポートしており、さまざまなクライアント構成への柔軟な統合が可能です。
セキュリティは、POSTGRESQL_ACCESS_LEVEL変数によって制御される階層的なアクセスモデルを通じて管理されます。ユーザーは、スキーマ検索やデータプロファイリングのためのREADONLYモード、行の挿入や更新を行うためのDML-RWモード、またはテーブルの作成や削除を行うためのDDL-RWモードで操作できます。誤ったデータ損失を防ぐため、POSTGRESQL_REQUIRE_CONFIRMATIONが有効な場合、書き込みを実行する前に影響を受ける行を表示する変更確認システムが含まれています。
技術的な機能には、JSON実行プランによるクエリの解説、jsonbデータの自動デコード、およびクライアントへの過負荷を防ぐための権限のある行制限が含まれます。開発者は、ホスト、ポート、SSLモードなどの接続詳細を環境変数を通じて設定でき、ベアラートークンを使用してHTTPエンドポイントを保護することも可能です。
できること
- 1データベーススキーマ構造の分析AIに対して、特定のテーブルの検索や、データベース内のカラムおよびキーの説明を依頼します。
- 2低速なSQLクエリの最適化特定のクエリのパフォーマンスが低い理由を理解するために、実行プランを要求します。
- 3テーブル統計のプロファイリング特定のテーブルの行数、NULL値、およびデータの分布の要約を取得します。
プロジェクトの README から作成されています。すべてのユースケースは、その引用と照らし合わせて確認されています。
PostgreSQL MCPツール 24
READMEから検出search_schemadescribe_tablelist_tablelist_databaseslist_environmentsprofile_tableinspect_relationshipsinspect_dependenciesexplain_queryread_datatest_connectionvalidate_environment_config
| search_schema | — | |
| describe_table | — | |
| list_table | — | |
| list_databases | — | |
| list_environments | — | |
| profile_table | — | |
| inspect_relationships | — | |
| inspect_dependencies | — | |
| explain_query | — | |
| read_data | — | |
| test_connection | — | |
| validate_environment_config | — |
24個のツールをすべて表示ツールを折りたたむ
list_schemaslist_extensionslist_viewslist_triggersshow_create_tabletable_sizeinsert_dataupdate_datadelete_datacreate_tablecreate_indexdrop_table
| list_schemas | — | |
| list_extensions | — | |
| list_views | — | |
| list_triggers | — | |
| show_create_table | — | |
| table_size | — | |
| insert_data | — | |
| update_data | — | |
| delete_data | — | |
| create_table | — | |
| create_index | — | |
| drop_table | — |
設定
POSTGRESQL_ACCESS_LEVELPOSTGRESQL_DATABASEPOSTGRESQL_HOSTPOSTGRESQL_HTTP_ADDRPOSTGRESQL_HTTP_PATHPOSTGRESQL_PASSWORDPOSTGRESQL_SSLMODEPOSTGRESQL_TRANSPORTPOSTGRESQL_USER
| 名前 | 説明 | 種類 |
|---|---|---|
| POSTGRESQL_ACCESS_LEVEL | — | |
| POSTGRESQL_DATABASE | — | |
| POSTGRESQL_HOST | — | |
| POSTGRESQL_HTTP_ADDR | — | |
| POSTGRESQL_HTTP_PATH | — | |
| POSTGRESQL_PASSWORD | — | |
| POSTGRESQL_SSLMODE | — | |
| POSTGRESQL_TRANSPORT | — | |
| POSTGRESQL_USER | — |
自動チェック
実行日 2026年11月14日完全なレポート →まだ検証されていません。サーバーには80点のスコア、重大な問題がないこと、および検証に必要な十分なデータが必要です。 チェックの仕組み · 点数を上げるための改善点
- ソースリポジトリがリンクされており、アクセス可能ralscha/postgresql-mcp is public and reachablegithub.com/ralscha/postgresql-mcp ↗合格
- パッケージがこのリポジトリをソースとして指定未チェック
- ビルドの来歴 (Sigstore 証明)未チェック
- オープンソースライセンス (OSI)MITspdx.org/licenses/MIT.html ↗合格
- 過去1年以内にコミットまたはリリースありLast commit or release 2026-11-09github.com/ralscha/postgresql-mcp ↗合格
- OpenSSF Scorecard未チェック
- パッケージ名が有名なパッケージに酷似していない未チェック
- パッケージおよびその依存関係に重大な勧告なし未チェック
- モデルへの隠れた指示がない24 tool descriptions and the README read; no override phrases, credential paths or hidden characters合格
- 破壊的なツールがラベル付けされている未チェック
- リモートエンドポイントが MCP ハンドシェイクに応答未チェック
README
GitHubで見るpostgresql-mcp
An MCP (Model Context Protocol) server that gives AI assistants structured, read-optimized access to PostgreSQL databases. It exposes schema exploration, data profiling, relationship analysis, query explanation, and safe read/write operations through a standardized MCP interface.
Features
- 24 MCP tools covering schema search, table description, data profiling, relationship/dependency inspection, query explanation, connection testing, schema/extension/view/trigger listing, CREATE TABLE DDL generation, table sizing, and tiered write access
- Tiered access model via
POSTGRESQL_ACCESS_LEVEL:READONLY(default),DML-RW(adds insert/update/delete),DDL-RW(adds create/drop table/index) - SQL-safe design with identifier validation, exact named-parameter binding, single-statement checks, and database-enforced read-only transactions
- Authoritative row limits that cap
read_dataresults even when the submitted query contains its own largerLIMIT - Mutation confirmation with preview mode that shows affected rows before executing writes when
POSTGRESQL_REQUIRE_CONFIRMATIONis enabled - Explain plan via
EXPLAIN (FORMAT JSON)for understanding query performance - Connection testing that validates connectivity and reports latency
- Environment listing showing current host, database, and access-level configuration
- Optional HTTP bearer authentication, same-origin protection, request-size limits, and graceful shutdown
Installation
Download the latest release for your platform from the Releases page.
Usage
Environment Variables
| Variable | Required | Default | Description |
|---|---|---|---|
POSTGRESQL_HOST |
Yes | — | PostgreSQL hostname or IP |
POSTGRESQL_DATABASE |
Yes | — | Database name |
POSTGRESQL_USER |
Yes | — | Login username |
POSTGRESQL_PASSWORD |
Yes | — | Login password |
POSTGRESQL_PORT |
No | 5432 |
PostgreSQL port |
POSTGRESQL_SSLMODE |
No | prefer |
SSL mode: disable, allow, prefer, require, verify-ca, verify-full |
POSTGRESQL_ACCESS_LEVEL |
No | READONLY |
READONLY, DML-RW, or DDL-RW |
POSTGRESQL_CONNECTION_TIMEOUT |
No | 30 |
Connection timeout in seconds |
POSTGRESQL_QUERY_TIMEOUT |
No | 120 |
Query timeout in seconds |
POSTGRESQL_MAX_ROWS_DEFAULT |
No | 1000 |
Default row limit for queries |
POSTGRESQL_REQUIRE_CONFIRMATION |
No | true |
Require confirm flag for writes |
POSTGRESQL_TRANSPORT |
No | stdio |
MCP transport: stdio or http |
POSTGRESQL_HTTP_ADDR |
No | 127.0.0.1:8080 |
HTTP listen address when POSTGRESQL_TRANSPORT=http |
POSTGRESQL_HTTP_PATH |
No | /mcp |
Stateless Streamable HTTP endpoint path when POSTGRESQL_TRANSPORT=http |
POSTGRESQL_HTTP_BEARER_TOKEN |
No | — | Require Authorization: Bearer <token> for HTTP requests |
Running as an MCP Server
By default, the server communicates over stdio. Configure your MCP client to launch it:
{
"mcpServers": {
"postgresql": {
"command": "/path/to/bin/postgresql-mcp",
"env": {
"POSTGRESQL_HOST": "localhost",
"POSTGRESQL_DATABASE": "YourDatabase",
"POSTGRESQL_USER": "postgres",
"POSTGRESQL_PASSWORD": "YourPassword",
"POSTGRESQL_SSLMODE": "disable",
"POSTGRESQL_ACCESS_LEVEL": "READONLY"
}
}
}
}
To serve MCP using the stateless Streamable HTTP transport, set POSTGRESQL_TRANSPORT=http:
POSTGRESQL_TRANSPORT=http \
POSTGRESQL_HTTP_ADDR=127.0.0.1:8080 \
POSTGRESQL_HTTP_PATH=/mcp \
/path/to/bin/postgresql-mcp
Then configure a Streamable HTTP MCP client to connect to:
http://localhost:8080/mcp
Set POSTGRESQL_HTTP_BEARER_TOKEN when the endpoint is reachable by anything other than a trusted local client. Binding to a non-loopback address without authentication exposes every tool allowed by POSTGRESQL_ACCESS_LEVEL.
Access Levels
READONLY(default) — Schema exploration, data reading, profiling, relationship inspection, query explanation, connection testing, schema listing, extensions, views, triggers, CREATE TABLE DDL generation, table sizing. 18 tools.DML-RW— All read-only tools plusinsert_data,update_data,delete_data. 21 tools.DDL-RW— All DML tools pluscreate_table,create_index,drop_table. 24 tools.
Mutations (update_data, delete_data, drop_table) require a "confirm": true flag when POSTGRESQL_REQUIRE_CONFIRMATION is enabled (the default). Without confirmation, the server returns a preview of the affected rows instead.
update_data and delete_data predicates use named placeholders. For example, use "where": "id = $id AND tenant = $tenant" with "params": {"id": 42, "tenant": "acme"}. Every placeholder must have a value and every supplied parameter must be used.
Query results decode json/jsonb into structured JSON, encode bytea as base64, and suffix duplicate column names (id, id_2, and so on) so joined results do not silently lose values.
MCP Tools
Read-Only (READONLY)
| Tool | Description |
|---|---|
search_schema |
Search tables and columns by name pattern with pagination |
describe_table |
Get columns, primary keys, foreign keys, and indexes for a table |
list_table |
List tables, optionally filtered by schema and name |
list_databases |
List all databases on the server |
list_environments |
Show current connection and access-level configuration |
profile_table |
Row count, null counts, distinct counts, min/max when supported, with optional data samples |
inspect_relationships |
List foreign keys going out of and into a table |
inspect_dependencies |
Find objects (views, functions) that depend on a table |
explain_query |
Get the JSON execution plan for a read-only query |
read_data |
Execute a read-only SELECT query with row limits |
test_connection |
Ping the server and return latency and server version info |
validate_environment_config |
Validate that all environment variables are correctly configured |
list_schemas |
List all user schemas with owner and description |
list_extensions |
List installed PostgreSQL extensions with version |
list_views |
List views with their SQL definitions |
list_triggers |
List triggers with event, timing, and definition |
show_create_table |
Generate CREATE TABLE DDL including defaults, generated/identity columns, and table constraints |
table_size |
Table and index sizes, toast size, and estimated row counts, optionally for one table |
DML (DML-RW)
| Tool | Description |
|---|---|
insert_data |
Insert one or more rows into a table |
update_data |
Update rows matching a WHERE clause (with optional preview) |
delete_data |
Delete rows matching a WHERE clause (with optional preview) |
DDL (DDL-RW)
| Tool | Description |
|---|---|
create_table |
Create a table with column definitions, primary keys, and identity columns |
create_index |
Create a standard or unique index on specified columns |
drop_table |
Drop a table (with optional preview/confirmation) |
License
MIT License. See LICENSE for details.
PostgreSQL MCPのよくある質問
PostgreSQL MCPが提供するツールは
24個のツールを提供しており、search_schema, describe_table, list_table, list_databases, list_environmentsなどがあります。
どのようなアクセスレベルが利用可能ですか?
このMCP serverは、READONLY(デフォルト)、DML-RW(insert/update/deleteを追加)、DDL-RW(create/drop table/indexを追加)の3段階のアクセスレベルをサポートしています。
書き込み操作の安全性を確保するにはどうすればよいですか?
POSTGRESQL_REQUIRE_CONFIRMATIONをtrueに設定することで、変更確認モードを有効にできます。これにより、書き込みを実行する前に影響を受ける行を表示できます。
HTTP経由でこのサーバーを使用できますか?
はい、POSTGRESQL_TRANSPORT環境変数を'http'に設定することで、ステートレスなstreamable HTTPエンドポイントを介してMCPを提供できます。
大量のクエリ結果はどのように処理されますか?
サーバーは、クエリ自体に大きなLIMIT句が含まれている場合でも、read_dataツールの結果を制限するための権限のある行制限(authoritative row limits)を使用します。