Postgres Analytics MCP Server
Postgres Analytics MCP Server
Model Context Protocol (MCP) サーバーで、AIアシスタント(Claude、Cursor、その他のMCP互換クライアント)がPostgreSQLデータベースを安全に検査・クエリできるようにします。読み取り専用の強制、行数/タイムアウト制限、完全な監査ログを備えています。
シンプルな問いに答えるために作られました:AIエージェントに実際のデータベースを触らせつつ、何も壊せないようにするにはどうすればいいのか?
機能
接続すると、AIクライアントは次のような質問ができます:
「データベースにはどんなテーブルがありますか?」
「最新の注文を10件見せて」
「このクエリが遅いのはなぜ?」
「インデックスがないテーブルはどれ?」
サーバーはMCP経由で5つのツールを公開します:
ツール | 目的 |
list_schemas | すべての非システムスキーマを一覧表示 |
list_tables | 指定されたスキーマ内のテーブルを一覧表示 |
run_query | 読み取り専用のSQLクエリを実行(SELECT/WITHのみ) |
explain_query | クエリ実行計画を返し、遅い場合にフラグを立てる |
get_table_stats | テーブルの行推定値とインデックス/シーケンシャルスキャン回数を返す |
Related MCP server: PostgreSQL MCP Server
なぜこれが存在するのか
企業はますますAIエージェントを内部システム(データベース、Kubernetes、API)に接続するようになっており、難しいのはそれを安全に行うことです。このプロジェクトはその小さく具体的な例です:AIクライアントと本番スタイルのデータベースの間の保護された橋渡しです。
設計上の決定
デフォルトで二重に読み取り専用:すべてのクエリはブロックリストに対して検証され、SELECT、WITH、またはEXPLAINで始まる必要があります。データベース接続自体も第二の防御線として読み取り専用モードで開かれます。
行数制限とクエリタイムアウト:すべてのクエリは設定可能な行数制限とステートメントタイムアウトで上限が設定され、無制限のデータを返したりサーバーをハングさせたりすることはできません。
認証はチャットではなくプロセス環境に存在:APIキーはMCPクライアント設定で環境変数として設定されるため、AIモデルが直接見たり扱ったりすることはありません。
監査ログ:すべてのツール呼び出しは、タイムスタンプ、ツール名、引数、結果とともに記録されます。
セットアップ
要件:Python 3.11+、PostgreSQL
仮想環境を作成し、依存関係をインストール: python -m venv venv venv\Scripts\Activate.ps1 pip install -r requirements.txt
データベースを作成し、サンプルスキーマをロード: psql -U postgres -c "CREATE DATABASE sampledb;" psql -U postgres -d sampledb -f seed.sql
.env.example を .env にコピーし、自分の値で埋める。
直接実行して動作確認: python -m server.main
Claude Desktop への接続
claude_desktop_config.json に追加(Claude Desktop -> 設定 -> 開発者 -> 設定を編集):
"mcpServers": {
"postgres-analytics": {
"command": "C:\\path\\to\\venv\\Scripts\\python.exe",
"args": ["-m", "server.main"],
"env": {
"PYTHONPATH": "C:\\path\\to\\project",
"MCP_API_KEY": "same-value-as-in-.env"
}
}
}スタック
Python、PostgreSQL、MCP Python SDK、psycopg2
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to safely interact with PostgreSQL databases through read-only operations, providing schema discovery, table inspection, and query execution capabilities with structured context awareness.MIT
- AlicenseNot gradedqualityDmaintenanceProvides read-only access to PostgreSQL databases, enabling users to list tables, view table structures and statistics, and execute SELECT queries safely through natural language.225MIT
- FlicenseAqualityDmaintenanceEnables AI agents to inspect and query PostgreSQL databases safely, with features like listing tables, retrieving schemas, and running read-only SQL queries.3
- FlicenseNot gradedqualityDmaintenanceEnables AI assistants to safely interact with PostgreSQL databases, perform queries, inspect schemas, and analyze query performance.2
Related MCP Connectors
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Comprehensive PostgreSQL documentation and best practices, including ecosystem tools
Explore, query, and inspect SQLite databases with ease. List tables, preview results, and view det…
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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/krishamehta09/pg-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server