PostgreSQL Query MCP Server
MCP Postgres クエリサーバー
Claude Desktop およびその他の MCP クライアントで動作するように設計された、読み取り専用モードで PostgreSQL データベースをクエリするためのモデル コンテキスト プロトコル (MCP) サーバー実装。
概要
このプロジェクトは、以下を提供するモデル コンテキスト プロトコル (MCP) サーバーを実装します。
PostgreSQL データベースへの安全な読み取り専用インターフェース
MCPプロトコルによるClaude Desktopとの統合
SELECTクエリのみが実行されるようにするSQLクエリ検証
クエリタイムアウト保護(10秒)
Related MCP server: PostgreSQL MCP Server
前提条件
Node.js (v14以降)
npm (Node.js に付属)
PostgreSQL データベース (接続詳細はコマンドラインから提供)
インストール
# Clone the repository
git clone https://github.com/RathodDarshil/mcp-postgres-query-server.git
cd mcp-postgres-query-server
# Install dependencies
npm install
# Build the project
npm run buildClaudeデスクトップに接続しています
Claude Desktop を自動的に起動して MCP サーバーに接続するように設定できます。
Claude Desktop 構成ファイルにアクセスします。
クロードデスクトップを開く
設定 > 開発者 > 設定の編集に移動します
これにより、デフォルトのテキストエディタで設定ファイルが開きます。
claude_desktop_config.jsonのmcpServersセクションに postgres-query-server を追加します。
{
"mcpServers": {
"postgres-query": {
"command": "node",
"args": [
"/path/to/your/mcp-postgres-query-server/dist/index.js",
"postgresql://username:password@hostname:port/database"
]
}
}
}/path/to/your/プロジェクト ディレクトリへの実際のパスに置き換えます。PostgreSQL 接続文字列を実際のデータベース資格情報に置き換えます。
ファイルを保存し、Claude Desktopを再起動します。設定のMCPサーバー選択ドロップダウンにMCPサーバーが表示されるはずです。
構成例
postgres-query を使用した構成ファイルの完全な例を次に示します。
{
"mcpServers": {
"postgres-query": {
"command": "node",
"args": [
"/Users/darshilrathod/mcp-servers/mcp-postgres-query-server/dist/index.js",
"postgresql://user:password@localhost:5432/mydatabase"
]
}
}
}構成の更新
Claude Desktop の構成を更新するには:
クロードデスクトップを開く
設定 > 開発者 > 設定の編集に移動します
設定ファイルに変更を加える
ファイルを保存する
変更を有効にするには、Claude Desktopを再起動してください。
MCPサーバーのコードを更新した場合は、再起動する前に必ず
npm run buildで再構築してください。
特徴
読み取り専用データベースアクセス: セキュリティのため、SELECTクエリのみが許可されます
クエリ検証: 潜在的に有害なSQL操作を防止します
タイムアウト保護: 10秒以上実行されたクエリは自動的に終了します
MCPプロトコルサポート: モデルコンテキストプロトコルの完全な実装
JSONレスポンスフォーマット: クエリ結果は構造化されたJSON形式で返されます
API
ツール
クエリ-Postgres
構成された PostgreSQL データベースに対して読み取り専用の SQL クエリを実行します。
パラメータ:
query(文字列): 実行するSQL SELECTクエリ
応答:
以下を含む JSON オブジェクト:
rows: 結果セットの行rowCount: 返される行数fields: 列のメタデータ
例:
query-postgres: SELECT * FROM users LIMIT 5発達
メインサーバーの実装はsrc/index.tsにあります。主なコンポーネントは次のとおりです。
PostgreSQL接続プールの設定
クエリ検証ロジック
MCP サーバーの構成
ツールとリソースの定義
サーバーの動作を変更するには、次の操作を行います。
isReadOnlyQuery()のクエリ検証ロジックを編集します。MCP サーバーに追加のツールやリソースを追加する
クエリのタイムアウト期間を変更します(現在は10秒)
セキュリティに関する考慮事項
サーバーはすべてのクエリを検証し、読み取り専用であることを確認します。
データベースへの接続にはSSLを使用します
クエリタイムアウトによりリソース枯渇を防止
書き込み操作は許可されていません
データベースの資格情報はファイルに保存されず、コマンドライン引数を介して直接渡されます。
ライセンス
ISC
貢献
貢献を歓迎します!お気軽にプルリクエストを送信してください。
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Tools
Related MCP Servers
- -license-qualityAmaintenanceA Model Context Protocol server that provides read-only access to PostgreSQL databases. This server enables LLMs to inspect database schemas and execute read-only queries.66,13689,405MIT
- Alicense-qualityDmaintenanceA Model Context Protocol server that provides read-only access to PostgreSQL databases, enabling LLMs to inspect database schemas and execute read-only queries.66,136MIT
- Alicense-qualityDmaintenanceA Model Context Protocol server that provides read-only access to PostgreSQL databases, enabling LLMs to inspect database schemas and execute read-only queries.66,136MIT
- Alicense-qualityDmaintenanceA Model Context Protocol server providing read-only access to PostgreSQL databases, enabling LLMs to inspect database schemas and execute read-only SQL queries.66,136MIT
Related MCP Connectors
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Analytical memory for AI agents: a real Postgres queried in plain English over MCP. One command.
MCP server for managing Prisma Postgres.
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/RathodDarshil/mcp-postgres-query-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server