Advanced PocketBase MCP Server
镜像
设置
-
配置环境变量:
POCKETBASE_URL=http://127.0.0.1:8090 POCKETBASE_ADMIN_EMAIL=admin@example.com (可选) POCKETBASE_ADMIN_PASSWORD=yourpassword (可选)
-
连接到服务器:
await mcp.connect("pocketbase")
核心功能
集合管理
创建集合:
await mcp.use_tool("pocketbase", "create_collection", {
"name": "posts",
"schema": [
{
"name": "title",
"type": "text",
"required": true
},
{
"name": "content",
"type": "text",
"required": true
}
]
})
获取集合架构:
schema = await mcp.use_tool("pocketbase", "get_collection_schema", {
"collection": "posts"
})
记录操作
创建记录:
await mcp.use_tool("pocketbase", "create_record", {
"collection": "posts",
"data": {
"title": "My First Post",
"content": "Hello World!"
}
})
查询记录:
results = await mcp.use_tool("pocketbase", "list_records", {
"collection": "posts",
"filter": "created >= '2024-01-01'",
"sort": "-created"
})
高级查询
results = await mcp.use_tool("pocketbase", "query_collection", {
"collection": "posts",
"filter": "title ~ 'important'",
"sort": "-created",
"expand": "author,categories",
"aggregate": {
"totalLikes": "sum(likes)",
"avgRating": "avg(rating)"
}
})
数据导入/导出
导入数据:
await mcp.use_tool("pocketbase", "import_data", {
"collection": "posts",
"data": [
{"title": "Post 1", "content": "Content 1"},
{"title": "Post 2", "content": "Content 2"}
],
"mode": "upsert"
})
备份数据库:
backup = await mcp.use_tool("pocketbase", "backup_database", {
"format": "json"
})
用户认证
auth = await mcp.use_tool("pocketbase", "authenticate_user", {
"email": "user@example.com",
"password": "userpassword"
})
# auth.token 可用于后续请求
最佳实践
- 使用 try/catch 块处理错误
- 为常用查询创建索引
- 定期备份数据库
- 使用迁移进行架构更改
- 验证数据完整性
完整文档
有关更多详细信息和高级功能,请访问 Glama.ai MCP 服务器页面。