Pgport

io.github.CloudCorpRecords由 GitHub 帳號 CloudCorpRecords 發布v0.1.0更新於 Oct 29, 2026

Read-only SQL queries against a PostgreSQL database.

已驗證STDIO僅桌面資料庫

概覽

AI 產生的概覽

對 PostgreSQL 資料庫執行單一唯讀 SQL 查詢並回傳結果列,拒絕任何可能修改資料的語句。

可以做什麼
  • 對 PostgreSQL 資料庫執行一筆唯讀的 SELECT 或 WITH 查詢,以依欄位名為鍵的 JSON 陣列回傳結果列。
  • 自行查詢 information_schema 來了解資料表結構,因為伺服器本身不掌握任何 schema 資訊。
  • 在語句離開行程前拒絕非 SELECT 語句、多語句與寫入類關鍵字,並把通過的查詢放在明確的唯讀交易中執行。
  • 將防護攔截、缺少連線資訊、缺少 psql 用戶端與資料庫錯誤都當成工具錯誤回報,而不是編造結果列。
適用情境
適合讓助理根據即時 PostgreSQL 資料庫回答問題,同時在結構上無法更動資料,例如分析時瀏覽資料表、統計筆數或抽取樣本列。
執行需求
透過 npx 或 Docker 映像以 stdio 在本機執行。需要 PostgreSQL 連線字串,可作為命令參數傳入,或透過 PGPORT_DATABASE_URL 環境變數提供(也可用 DATABASE_URL)。PATH 中必須有 psql 命令列用戶端;缺少時伺服器仍可啟動,但查詢會失敗。
安裝前請注意
連線字串通常包含資料庫憑證,應視為機密。唯讀防護以關鍵字比對為基礎,可能拒絕把保留字當成識別名的合法查詢。回傳值是 psql 輸出的字串,型別資訊不會保留。

安裝

在 SourceWeft 中

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

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

bash
npx @reneturcios/pgport query postgres://user@localhost:5432/mydb "SELECT 1"

Or run the container image:

bash
docker run -i ghcr.io/cloudcorprecords/pgport

The container defaults to the MCP server (see below). Pass CLI arguments to use it as a CLI instead.

CLI

bash
# Run one read-only query; rows print as JSONpgport query postgres://alice@localhost/shop "SELECT id, name FROM products ORDER BY id"
# See what tables exist and which columns each one haspgport schemas postgres://alice@localhost/shop
# Start the MCP server (connection string optional, see below)pgport mcp postgres://alice@localhost/shop
pgport --version

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 SELECT or WITH.
  • 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, or VACUUM appears as a whole word outside a string literal. Single-quoted literals are blanked out before scanning, so SELECT 'delete me' is a perfectly good query; a column literally named update is 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:

bash
npx -y @reneturcios/pgport mcp postgres://alice@localhost/shop

MCP client configuration:

json
{  "mcpServers": {    "pgport": {      "command": "npx",      "args": ["-y", "@reneturcios/pgport", "mcp"],      "env": { "PGPORT_DATABASE_URL": "postgres://alice@localhost/shop" }    }  }}

Tools

ToolInputWhat it returns
querysql (string, required) — one read-only SQL statementThe result rows as a JSON array of objects keyed by column name. Guard violations, a missing connection, a missing psql, and database errors all come back as tool errors — never as made-up rows.

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

bash
npm installnpm run build   # tsc -> dist/npm test        # node test runner over test/*.test.ts, no network, no live databasenpm run dev     # run the CLI from source via tsx

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
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

1
  1. v0.1.0最新Oct 29, 2026

評分

已滿足適用檢查項的 50%

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

  • 近 30 天內可連通25 分

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

  • 已宣告認證方式10 分

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

  • 已列出工具15 分

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

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