Postgres

io.github.ofershap由 GitHub 帳號 ofershap 發布v1.0.0更新於 Oct 24, 2026

PostgreSQL MCP — query databases, inspect schemas, explain queries.

已驗證STDIO僅桌面資料庫開發者工具

概覽

AI 產生的概覽

一個本機 MCP 伺服器,讓 AI 助理查詢 PostgreSQL 資料庫、檢視結構與資料表,並解釋查詢計畫。

可以做什麼
執行 SQL 查詢(SELECT、WITH、EXPLAIN、SHOW、ANALYZE),以文字表格回傳結果,支援單次呼叫覆寫連線字串,並在關閉唯讀時允許寫入。列出非系統結構及結構中的資料表、欄位與概略資料列數。檢視單一資料表的欄位、型別、是否可為空、預設值、主鍵與精確資料列數。以文字格式解釋查詢計畫,可選擇搭配 ANALYZE。
適用情境
適用於使用本機或開發環境 PostgreSQL 資料庫時,希望助理不必離開 IDE 或聊天用戶端就能瀏覽結構、執行唯讀查詢並理解查詢計畫。
執行需求
透過 npm 套件 mcp-pg-server 以 npx 在本機執行,需要 Node.js。需要 PostgreSQL 連線,透過 DATABASE_URL 環境變數或單次呼叫的 connectionString 提供。需要能連線到資料庫主機的網路。
安裝前請注意
DATABASE_URL 含有資料庫憑證,請勿放入共用設定。預設為唯讀,但設定 readonly=false 後會啟用 INSERT、UPDATE、DELETE 與 DDL,可能造成寫入與破壞性變更。建議指向開發資料庫而非正式環境。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Postgres,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

mcp-server-postgres

[npm version] [npm downloads] [CI] [TypeScript] [License: MIT]

Query PostgreSQL, inspect schemas, and explain queries from your AI assistant. A daily-driver MCP for local and dev Postgres — same belt as docker and sqlite servers, not an enterprise DBA suite.

bash
DATABASE_URL=postgres://user:pass@localhost:5432/mydb npx mcp-pg-server

Works with Claude Desktop, Cursor, VS Code Copilot, and any MCP client. Connects via DATABASE_URL or per-call connectionString.

Why

Postgres is the default for most new backends, local dev stacks, and agent workflows that need a real SQL database. You already run it in Docker or on localhost — this server lets your assistant query it, read schemas, and explain plans without leaving the IDE. Read-only by default so exploration stays safe; opt into writes when you need them.

Tools

ToolWhat it does
queryExecute SQL (SELECT, WITH, EXPLAIN, SHOW, ANALYZE). Returns a text table.
schemaTables in a schema (default public) with columns and approximate row counts
table_infoOne table: columns, types, null/default, PK, exact row count
explainEXPLAIN (FORMAT TEXT), optional ANALYZE
list_schemasList non-system schemas

Quick Start

Cursor

Add to .cursor/mcp.json:

json
{  "mcpServers": {    "postgres": {      "command": "npx",      "args": ["mcp-pg-server"],      "env": {        "DATABASE_URL": "postgres://user:pass@localhost:5432/mydb"      }    }  }}

Claude Desktop

Add to claude_desktop_config.json (macOS: ~/Library/Application Support/Claude/claude_desktop_config.json):

json
{  "mcpServers": {    "postgres": {      "command": "npx",      "args": ["mcp-pg-server"],      "env": {        "DATABASE_URL": "postgres://user:pass@localhost:5432/mydb"      }    }  }}

VS Code

Configure the MCP server in your VS Code settings to run npx mcp-pg-server with DATABASE_URL set.

Example prompts

  • "Show me the schema of the public tables"
  • "Query users: SELECT * FROM users LIMIT 10"
  • "Explain this join query"
  • "What schemas exist in this database?"
  • "How many rows are in the orders table?"

Safety

Read-only by default. The query tool accepts only SELECT, WITH, EXPLAIN, SHOW, and ANALYZE in readonly mode. Set readonly=false to enable INSERT, UPDATE, DELETE, and DDL.

Pass connectionString on any tool to override DATABASE_URL for a single call.

Development

bash
npm installnpm run typechecknpm run buildnpm testnpm run formatnpm run lint

See also

More MCP servers and developer tools on my portfolio.

Author

[Made by ofershap]

[LinkedIn] [GitHub]

License

MIT © 2026 Ofer Shapira

來源:README.md,提交 6b813b6

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

1
  1. v1.0.0最新Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分