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
貢献
貢献を歓迎します!お気軽にプルリクエストを送信してください。
Available Tools
1 toolquery-postgresD
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Tool has no description.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Tool has no description.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Tool has no description.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Tool has no description.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Tool has no description.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Tool has no description.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
1 tool update
- First observed
query-postgres
TDQS
Scored across 1 tool
With only one tool, there is no possibility of ambiguity or overlap between tools. The tool's purpose is singular and clear, eliminating any risk of misselection.
A single tool inherently has perfect naming consistency, as there are no other tools to compare it against. The name 'query-postgres' follows a clear verb-noun pattern without any conflicting conventions.
A single tool is too few for a PostgreSQL server's apparent scope, which typically involves multiple operations like querying, inserting, updating, and deleting data. This minimal set severely limits functionality and agent workflows.
The tool surface is severely incomplete for a PostgreSQL domain, covering only querying. Obvious gaps include create, update, delete, schema management, and transaction handling, which will cause frequent agent failures in database interactions.
Maintenance
Related MCP Connectors
Query 40 databases from Claude, ChatGPT, or Cursor — on any device. Read-only, encrypted, audited.
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Query your Postgres from ChatGPT or Claude without exposing the database or handing over credentials. Run npx boltschema connect next to your database and it dials out over HTTPS — no inbound firewall rule, no open port, works with localhost and VPC-private databases. Read-only is enforced by a SQL guard, a Postgres READ ONLY transaction, and a scoped role generated for you.
Text-to-SQL MCP server: read-only queries on PostgreSQL, MySQL and SQL Server with your real schema
Related MCP Servers
- -licenseNot gradedqualityAmaintenanceA 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.122,323 npm91,120MIT
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that provides read-only access to PostgreSQL databases, enabling LLMs to inspect database schemas and execute read-only queries.122,323 npmMIT
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that provides read-only access to PostgreSQL databases, enabling LLMs to inspect database schemas and execute read-only queries.122,323 npmMIT
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server providing read-only access to PostgreSQL databases, enabling LLMs to inspect database schemas and execute read-only SQL queries.122,323 npmMIT