Skip to main content
Glama

PocketBase MCP Server

by imatrixme

高级 PocketBase MCP 服务器

铁匠徽章一个功能全面的 MCP 服务器,提供与 PocketBase 数据库交互的复杂工具。该服务器通过模型上下文协议 (MCP) 支持高级数据库操作、模式管理和数据操作。

特征

收藏管理

  • 使用自定义架构创建和管理集合

  • 迁移具有数据保存的收集模式

  • 高级索引管理(创建、删除、列出)

  • 架构验证和类型安全

  • 检索集合架构和元数据

记录操作

  • 记录的 CRUD 操作

  • 具有过滤、排序和聚合功能的高级查询

  • 批量导入/导出功能

  • 关系扩展支持

  • 分页和基于光标的导航

用户管理

  • 用户身份验证和令牌管理

  • 用户帐户创建和管理

  • 密码管理

  • 基于角色的访问控制

  • 会话处理

数据库操作

  • 数据库备份和恢复

  • 多种导出格式(JSON/CSV)

  • 数据迁移工具

  • 索引优化

  • 批量操作

Related MCP server: PocketBase MCP Server

可用工具

收藏管理

  • create_collection :使用自定义架构创建新集合

  • get_collection_schema :获取集合的架构详细信息

  • migrate_collection :迁移带有数据保存的集合模式

  • manage_indexes :创建、删除或列出集合索引

记录操作

  • create_record :在集合中创建新记录

  • list_records :列出带有可选过滤器和分页的记录

  • update_record :更新现有记录

  • delete_record :删除记录

  • query_collection :具有过滤、排序和聚合功能的高级查询

  • import_data :使用创建/更新/插入模式将数据导入集合

用户管理

  • authenticate_user :验证用户并获取身份验证令牌

  • create_user :创建一个新的用户帐户

  • list_auth_methods :列出所有可用的身份验证方法

  • authenticate_with_oauth2 :使用 OAuth2 验证用户身份

  • authenticate_with_otp :使用一次性密码验证用户身份

  • auth_refresh :刷新身份验证令牌

  • request_verification :请求电子邮件验证

  • confirm_verification :使用令牌确认电子邮件验证

  • request_password_reset :请求重置密码

  • confirm_password_reset :使用令牌确认密码重置

  • request_email_change :请求更改电子邮件

  • confirm_email_change :使用令牌确认电子邮件变更

  • impersonate_user :模拟其他用户(仅限管理员)

数据库操作

  • backup_database :使用格式选项创建 PocketBase 数据库的备份

  • import_data :使用各种模式导入数据(创建/更新/更新插入)

配置

服务器需要以下环境变量:

可选的环境变量:

  • POCKETBASE_ADMIN_EMAIL :用于某些操作的管理员电子邮件

  • POCKETBASE_ADMIN_PASSWORD :管理员密码

  • POCKETBASE_DATA_DIR :自定义数据目录路径

使用示例

收藏管理

// Create a new collection await mcp.use_tool("pocketbase", "create_collection", { name: "posts", schema: [ { name: "title", type: "text", required: true }, { name: "content", type: "text", required: true } ] }); // Manage indexes await mcp.use_tool("pocketbase", "manage_indexes", { collection: "posts", action: "create", index: { name: "title_idx", fields: ["title"], unique: true } });

高级查询

// Query with filtering, sorting, and aggregation await mcp.use_tool("pocketbase", "query_collection", { collection: "posts", filter: "created >= '2024-01-01'", sort: "-created", aggregate: { totalLikes: "sum(likes)", avgRating: "avg(rating)" }, expand: "author,categories" });

数据导入/导出

// Import data with upsert mode await mcp.use_tool("pocketbase", "import_data", { collection: "posts", data: [ { title: "First Post", content: "Hello World" }, { title: "Second Post", content: "More content" } ], mode: "upsert" }); // Backup database await mcp.use_tool("pocketbase", "backup_database", { format: "json" // or "csv" });

架构迁移

// Migrate collection schema 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 } ], dataTransforms: { // Optional field transformations during migration tags: "JSON.parse(oldTags)" } });

身份验证方法

// List available authentication methods await mcp.use_tool("pocketbase", "list_auth_methods", { collection: "users" }); // Authenticate with password await mcp.use_tool("pocketbase", "authenticate_user", { email: "user@example.com", password: "securepassword", collection: "users" }); // Authenticate with OAuth2 await mcp.use_tool("pocketbase", "authenticate_with_oauth2", { provider: "google", code: "auth_code_from_provider", codeVerifier: "code_verifier_from_pkce", redirectUrl: "https://your-app.com/auth/callback", collection: "users" }); // Request password reset await mcp.use_tool("pocketbase", "request_password_reset", { email: "user@example.com", collection: "users" }); // Confirm password reset await mcp.use_tool("pocketbase", "confirm_password_reset", { token: "verification_token", password: "new_password", passwordConfirm: "new_password", collection: "users" }); // Refresh authentication token await mcp.use_tool("pocketbase", "auth_refresh", { collection: "users" });

错误处理

所有工具均包含全面的错误处理功能,并配有详细的错误消息。错误信息均已正确输入,包括:

  • 无效请求错误

  • 身份验证错误

  • 数据库操作错误

  • 架构验证错误

  • 网络错误

类型安全

该服务器包含所有操作的 TypeScript 定义,确保使用工具时的类型安全。每个工具的输入模式都经过严格的类型和验证。

最佳实践

  1. 始终使用 try/catch 块进行适当的错误处理

  2. 执行操作前验证数据

  3. 使用适当的索引以获得更好的查询性能

  4. 定期备份数据库

  5. 使用迁移进行架构更改

  6. 遵循用户管理的安全最佳实践

  7. 监控和优化数据库性能

发展

  1. 克隆存储库

  2. 安装依赖项: npm install

  3. .env.example复制到.env并配置

  4. 构建: npm run build

  5. 启动您的 PocketBase 实例

  6. MCP 服务器将自动连接到您的 PocketBase 实例

通过 Smithery 安装

要通过Smithery自动为 Claude Desktop 安装 PocketBase Server:

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

贡献

  1. 分叉存储库

  2. 创建功能分支

  3. 提交你的更改

  4. 推送到分支

  5. 创建拉取请求

-
security - not tested
A
license - permissive license
-
quality - not tested

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/imatrixme/pocketbase-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server