
Pgport
io.github.CloudCorpRecords由 GitHub 帳號 CloudCorpRecords 發布v0.1.0更新於 Oct 29, 2026
Read-only SQL queries against a PostgreSQL database.
概覽
對 PostgreSQL 資料庫執行單一唯讀 SQL 查詢並回傳結果列,拒絕任何可能修改資料的語句。
- 可以做什麼
- 對 PostgreSQL 資料庫執行一筆唯讀的 SELECT 或 WITH 查詢,以依欄位名為鍵的 JSON 陣列回傳結果列。
- 自行查詢 information_schema 來了解資料表結構,因為伺服器本身不掌握任何 schema 資訊。
- 在語句離開行程前拒絕非 SELECT 語句、多語句與寫入類關鍵字,並把通過的查詢放在明確的唯讀交易中執行。
- 將防護攔截、缺少連線資訊、缺少 psql 用戶端與資料庫錯誤都當成工具錯誤回報,而不是編造結果列。
- 適用情境
- 適合讓助理根據即時 PostgreSQL 資料庫回答問題,同時在結構上無法更動資料,例如分析時瀏覽資料表、統計筆數或抽取樣本列。
- 執行需求
- 透過 npx 或 Docker 映像以 stdio 在本機執行。需要 PostgreSQL 連線字串,可作為命令參數傳入,或透過 PGPORT_DATABASE_URL 環境變數提供(也可用 DATABASE_URL)。PATH 中必須有 psql 命令列用戶端;缺少時伺服器仍可啟動,但查詢會失敗。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Pgport,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
pgport
pgport lets an agent — or you, at a terminal — ask a PostgreSQL
database questions without ever being able to change it. It accepts a
connection string, runs a single read-only query, and hands back the
rows. Anything that is not one plain SELECT or WITH ... SELECT
statement is refused before it leaves the process, and the statement
that does run executes inside an explicit read-only transaction.
There is no bundled database driver. Under the hood pgport shells out
to the psql command-line client, so a machine that wants live answers
needs psql on its PATH. Without it — or without a connection
string — the server still starts and lists its tool; only the query
itself reports the problem.
Install
Or run the container image:
The container defaults to the MCP server (see below). Pass CLI arguments to use it as a CLI instead.
CLI
Exit codes: 0 on success, 1 when the query, the connection string,
or psql itself fails (the error says which), 2 for usage errors.
The connection string is a normal PostgreSQL URL:
postgres:// or postgresql://, with host, optional port (default
5432), database name from the path, and optional user and password in
the userinfo. For the mcp command the string can be left off the
command line and supplied through the PGPORT_DATABASE_URL
environment variable instead (plain DATABASE_URL works too).
The read-only guard
A query is accepted only if all of these hold:
- After leading whitespace and comments are stripped, its first
keyword is
SELECTorWITH. - It is a single statement: a semicolon followed by anything other than whitespace ends the conversation.
- None of
INSERT,UPDATE,DELETE,DROP,ALTER,CREATE,TRUNCATE,GRANT,REVOKE,COPY, orVACUUMappears as a whole word outside a string literal. Single-quoted literals are blanked out before scanning, soSELECT 'delete me'is a perfectly good query; a column literally namedupdateis not — the guard would rather refuse an odd name than be talked around.
Accepted queries run as
BEGIN TRANSACTION READ ONLY; <sql>; COMMIT; through
psql -v ON_ERROR_STOP=1 --csv, and the CSV output is parsed into row
objects. Values come back as the strings psql rendered.
MCP server
One bin serves both faces. The mcp subcommand starts a stdio MCP
server:
MCP client configuration:
Tools
The server deliberately knows nothing about your schema at the MCP
layer: ask the database itself, for example
SELECT table_name FROM information_schema.tables, or use the CLI
schemas command, which groups information_schema.columns rows
into a per-table column list.
Development
The core logic lives behind an injectable executor interface, which is what the test suite drives: connection-string parsing, the guard, pass-through querying, error propagation, and schema grouping are all covered with a fake executor.
License
MIT — see LICENSE.
來源:README.md,提交 c99b56c
工具
0版本歷史
1- v0.1.0最新Oct 29, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分