使用说明
@node2flow/postgrest mcp
MCP服务器 PostgREST --一个将PostgreSQL数据库转换为RESTful API的独立web服务器。10个工具,用于通过模型上下文协议进行模式发现、CRUD操作、过滤、资源嵌入和RPC。
快速开始
克劳德桌面/光标
添加到MCP配置中:
{
"mcpServers": {
"postgrest": {
"command": "npx",
"args": ["-y", "@node2flow/postgrest-mcp"],
"env": {
"POSTGREST_URL": "http://localhost:3000",
"POSTGREST_TOKEN": "your-jwt-token"
}
}
}
}
注: JWT令牌是可选的。如果PostgREST配置了匿名角色(
db-anon-role),模式和读取操作无需身份验证即可工作。
HTTP模式
POSTGREST_URL=http://localhost:3000 POSTGREST_TOKEN=your-jwt npx @node2flow/postgrest-mcp --http
MCP端点: http://localhost:3000/mcp
Cloudflare工作人员
可用网址: https://postgrest-mcp-community.node2flow.net/mcp
POST https://postgrest-mcp-community.node2flow.net/mcp?POSTGREST_URL=http://your-server:3000&POSTGREST_TOKEN=your-jwt
工具(10)
架构(2)--无需身份验证(具有匿名角色)
| 工具 | 说明 |
|---|---|
pg_get_schema |
获取OpenAPI模式——列出所有表、视图、函数 |
pg_describe_table |
获取表/视图的列详细信息、类型和约束 |
读取(3)--只读
| 工具 | 说明 |
|---|---|
pg_list_records |
使用过滤器、选择、排序、分页查询记录 |
pg_count_records |
计数记录(精确、计划或估计) |
pg_call_function |
通过RPC调用PostgreSQL函数/过程 |
写入(5)-需要授权
| 工具 | 描述 | 风险 |
|---|---|---|
pg_insert_records |
插入一条或多条记录 | 安全 |
pg_update_records |
更新与筛选器匹配的记录 | 安全(需要筛选器) |
pg_upsert_records |
插入或更新冲突 | 安全 |
pg_delete_records |
删除与筛选器匹配的记录 | 破坏性的 |
pg_replace_record |
完全替换(PUT)单个记录 | 安全 |
筛选器语法
PostgREST对查询参数使用了强大的过滤语法:
# Comparison
age=gt.18 # greater than
status=eq.active # equals
price=lte.100 # less than or equal
# Pattern matching
name=ilike.*john* # case-insensitive LIKE
email=like.*@gmail.com # case-sensitive LIKE
# Lists and NULL
id=in.(1,2,3) # IN list
deleted_at=is.null # NULL check
# Logic
or=(age.lt.18,age.gt.65) # OR conditions
not.status=eq.inactive # NOT
# Full-text search
content=fts.postgresql # full-text search
# Array/JSONB
tags=cs.{tech,api} # array contains
资源嵌入(JOIN)
使用查询相关表 select 参数:
*,orders(*) — embed all columns from related table
id,name,orders(id,total,status) — specific columns from embed
id,author:user_id(name,email) — renamed embed
嵌入式资源筛选器:
select: id,name,orders(*)
filter: orders.status=eq.completed
配置
| 参数 | 必填 | 说明 |
|---|---|---|
POSTGREST_URL |
是 | PostgREST服务器URL(例如。 http://localhost:3000) |
POSTGREST_TOKEN |
没有 | 经过身份验证的请求的JWT令牌 |
JWT身份验证
PostgREST使用JSON Web令牌(JWT)进行无状态身份验证。
- 配置
jwt-secret在您的PostgREST配置中 - 使用适当的JWT生成
role声称 - 通过以下方式传递令牌
POSTGREST_TOKEN环境变量
智威汤逊声称:
role--数据库角色名称(RLS需要)exp--令牌过期(Unix时间戳)- SQL中可通过以下方式访问自定义声明
current_setting()
提示: 使用
db-anon-role在PostgREST配置中,用于无令牌的公共只读访问。
安全
- 更新和删除需要筛选器 --防止意外的满表操作
- 使用
pg_count_records在删除之前验证筛选器匹配 - 使用
return="representation"看看发生了什么变化 - 使用
pg_describe_table在插入之前检查所需的列
什么是PostgREST?
PostgREST 是一个独立的web服务器,它:
- 转PostgreSQL 表格 转换为CRUD端点(GET、POST、PATCH、PUT、DELETE)
- 回合 观点 转换为只读端点
- 回合 函数 进入RPC端点(
/rpc/function_name) - 使用PostgreSQL 行级安全性 (RLS)用于授权
- 自动生成 开放应用程序接口 规格
许可证
MIT许可证-请参阅 许可证
版权所有(c)2026 Node2Flow