
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 分