Back to MCP Servers
postgresql mcp logo
mcp-server215

postgresql mcp

Postgres MCP Pro 是一個功能強大的 PostgreSQL 模型上下文協議 (MCP) 伺服器,為 AI 代理提供可配置的讀寫存取、進階效能分析、索引調優、執行計畫解釋以及安全的 SQL 執行功能。

概述

PostgreSQL MCP(通常稱為 Postgres MCP Pro)是一款開源的 模型上下文協定(Model Context Protocol,MCP)伺服器,旨在為 AI 代理提供安全且智能的 PostgreSQL 資料庫存取功能。

其功能遠超基本的查詢執行,提供可設定的唯讀或讀寫模式、全面的效能診斷、自動化索引建議,以及生產環境級別的安全功能。專為支援完整的開發生命週期而打造 —— 從結構描述探索與編碼,到測試、部署及持續維護。

流行的實作版本包括最初的 Anthropic 參考版本(現因安全考量已廢棄/封存)、社群分支,以及由 Crystal DBA 開發的強化版本(如 Postgres MCP Pro)。

功能特色

-- 可配置的存取模式:嚴格的唯讀交易(防止資料修改)或具有交易安全性的受控讀寫模式。 -- 結構描述與資料探索:列出資料表、檢查結構描述、欄位、索引、約束條件,並執行自然語言驅動的查詢。 -- 效能分析:執行緩衝快取、真空狀態、複製延遲、連線使用率、序列限制等健康檢查。 -- 索引調校與執行計畫解釋:先進的索引建議引擎,可測試數千種組合;支援假設性索引及詳細的查詢執行計畫解釋。 -- 安全的 SQL 執行:唯讀封裝器、查詢驗證,以及防範危險操作的安全措施。 -- 為 AI 代理優化:專為低令牌使用量、清晰的輸出格式設計的工具,並能與 Claude、Cursor、Gemini 及其他 MCP 客戶端無縫整合。 -- Docker 與簡易部署:提供官方 Docker 映像,確保一致且無依賴的運行環境。 -- 可擴展性:支援社群版 Postgres、RDS、Aurora 及大多數 PostgreSQL v12+ 以上版本。

使用場景

-- AI 輔助資料庫開發:讓您的 AI 代理探索結構描述、建議最佳查詢,或使用自然語言產生資料庫遷移指令。 -- 效能調校:詢問「分析慢速查詢」或「為此資料表推薦索引」—— 即可獲得附有執行計畫解釋的可執行洞察。 -- 生產環境監控:執行健康檢查、偵測膨脹,或監控真空/自動真空操作,無需手動編寫 SQL。 -- 安全的資料分析:授予唯讀存取權限,供報告、分析或客戶支援代理使用,而無需擔憂資料完整性風險。 -- 完整開發工作流程:從專案初始設定與測試,到部署及持續優化 —— 全程由對話式 AI 驅動。

安裝與快速入門

使用 Docker(推薦)

拉取並執行官方映像:

docker run -p 8080:8080 crystaldba/postgres-mcp --connection-string "postgresql://user:pass@localhost:5432/mydb"

Python / uv 安裝方式

uv pip install postgres-mcp
uv run postgres-mcp "postgresql://user:password@localhost:5432/dbname"

客戶端配置(Claude Desktop、Cursor 等)

將配置加入您的 MCP 設定檔(例如 ~/.cursor/mcp.json 或 Claude 設定),並使用指向運行中伺服器的適當命令/參數。

完整文件、連線範例與安全最佳實務可在儲存庫中找到。

安全性須知

  • 對於不受信任的代理程式,建議優先使用唯讀模式。
  • 原始的 Anthropic 參考實作存在已知的 SQL 注入漏洞(已在分支版本及後續版本中修補)。
  • 請始終使用具備最低權限的連線字串,並考慮實施網路層級的存取限制。

相關連結

  • GitHub(Postgres MCP Pro):crystaldba/postgres-mcp
  • 其他知名實作:pgEdge Postgres MCP、AWS Labs Aurora MCP,以及各社群分支版本。
  • 模型上下文協定:官方 MCP 規範。

Postgres MCP 將您的資料庫轉變為 AI 代理程式的首要工具,讓智能資料互動變得如同與助手對話般簡單。

Tags

mcppostgresqlpostgresmcp-serversql資料庫ai代理索引調優效能分析claudecursor

Related Entries

Keep exploring similar tools and resources in this category.

Browse MCP Servers
Cursor MCP logo

Cursor MCP

MCP Servers

Cursor MCP is Cursor's Model Context Protocol client support for connecting the Cursor editor and Cursor CLI agent to external MCP servers. Official docs cover stdio, SSE, Streamable HTTP, mcp.json configuration, OAuth, Marketplace plugins, and CLI management commands.

Higgsfield MCP logo

Higgsfield MCP

MCP Servers

Higgsfield MCP is Higgsfield AI's hosted MCP connector for generating images, videos, reusable characters, and creative assets from Claude or MCP-compatible agents. It uses a Higgsfield account and platform credits, with no API key documented for the official MCP connector.

Agent Reach logo

Agent Reach

MCP Servers

Agent Reach is an open-source CLI and Agent Skill that installs, routes, and health-checks upstream tools for web, social, GitHub, video transcript, RSS, and search access. It is not documented as a standalone MCP server; some channels use MCP-backed upstream tools such as mcporter/Exa, xiaohongshu-mcp, and linkedin-scraper-mcp.

Design Bridge MCP logo

Design Bridge MCP

MCP Servers

Design Bridge MCP connects Framer projects to Claude, Cursor, and other MCP-compatible assistants for AI-driven canvas and project automation.

RevenueCat MCP Server logo

RevenueCat MCP Server

MCP Servers

RevenueCat MCP Server lets AI assistants manage RevenueCat subscription infrastructure through natural language, including projects, apps, products, entitlements, offerings, paywalls, and analytics.

TinyFish logo

TinyFish

MCP Servers

TinyFish 為相容 MCP 的 AI 助手提供網頁自動化、網路搜尋、內容擷取以及遠端瀏覽器會話工具。代管的 MCP 伺服器使用 OAuth 2.1,而可選的本地 @tiny-fish/mcp 代理支援 API 金鑰驗證,適用於僅限本地、CI 及無頭設定。