Advanced PocketBase MCP Server

Advanced PocketBase MCP Server

pocketbase-mcp-server

smithery 徽章 pocketbase-mcp-server MCP 服务器

概述

PocketBase MCP 服务器使您能够通过 Model Context Protocol (MCP) 与 PocketBase 数据库进行交互,提供高级数据库操作、模式管理和数据操作功能。

配置

必要配置

POCKETBASE_URL="http://127.0.0.1:8090"  # 您的 PocketBase 实例 URL

可选配置

POCKETBASE_ADMIN_EMAIL="admin@example.com"
POCKETBASE_ADMIN_PASSWORD="yourpassword"
POCKETBASE_DATA_DIR="/path/to/data"

主要功能

  • 集合管理: 创建/迁移集合模式,管理索引
  • 记录操作: 完整的 CRUD 操作,高级查询,批量导入/导出
  • 用户管理: 身份验证,用户创建,密码管理,角色控制
  • 数据库操作: 备份/恢复,数据迁移,批量操作

使用示例

1. 创建新集合

await mcp.use_tool("pocketbase", "create_collection", {
  name: "posts",
  schema: [
    { name: "title", type: "text", required: true },
    { name: "content", type: "text", required: true }
  ]
});

2. 查询数据

await mcp.use_tool("pocketbase", "query_collection", {
  collection: "posts",
  filter: "created >= '2024-01-01'",
  sort: "-created",
  expand: "author,categories"
});

3. 用户身份验证

await mcp.use_tool("pocketbase", "authenticate_user", {
  email: "user@example.com",
  password: "securepassword",
  collection: "users"
});

4. 导入数据

await mcp.use_tool("pocketbase", "import_data", {
  collection: "posts",
  data: [
    { title: "First Post", content: "Hello World" },
    { title: "Second Post", content: "More content" }
  ],
  mode: "upsert"
});

5. 迁移集合模式

await mcp.use_tool("pocketbase", "migrate_collection", {
  collection: "posts",
  newSchema: [
    { name: "title", type: "text", required: true },
    { name: "content", type: "text", required: true },
    { name: "tags", type: "json", required: false }
  ]
});

通过 Smithery 安装

npx -y @smithery/cli install pocketbase-server --client claude

最佳实践

  1. 使用 try/catch 块处理错误
  2. 在执行操作前验证数据
  3. 为提高查询性能设置适当索引
  4. 定期备份数据库
  5. 使用迁移进行模式更改

错误处理

所有工具提供详细的错误消息,包括请求错误、身份验证错误、数据库操作错误、模式验证错误和网络错误。