Skip to main content
Glama

pocketbase-mcp

一个用于 PocketBase 的 模型上下文协议 (MCP) 服务器 —— 让 Claude 等 AI 助手能够通过简洁的 Python 接口全面访问您的 PocketBase 后端。


概述

pocketbase-mcp 弥合了 LLM 与您的 PocketBase 实例之间的鸿沟。连接后,AI 助手可以通过自然语言列出集合、执行记录的 CRUD 操作、管理身份验证、处理文件上传以及管理您的数据库。

基于 FastMCP(标准的 Python MCP 框架)构建,并使用 httpx 与 PocketBase REST API 进行异步 HTTP 通信。


Related MCP server: PocketBase MCP Server

功能

  • 记录 — 在任何集合中列出、获取、创建、更新、删除记录以及进行批量操作

  • 集合 — 列出、检查、创建、更新和删除集合架构

  • 身份验证 — 通过电子邮件/密码或 API 密钥以超级用户或普通用户身份进行身份验证

  • 文件 — 生成文件令牌并检索带有可选图像转换的文件 URL

  • 设置 — 读取和更新应用程序设置

  • 过滤与分页 — 直接传递 PocketBase 过滤表达式、排序、展开和分页参数

  • 实时感知 — 考虑到 SSE 订阅模式,为未来扩展而设计


要求

  • Python 3.11+

  • 正在运行的 PocketBase 实例(本地或远程)

  • uv(推荐)或 pip


安装

使用 pip

pip install pocketbase-mcp

配置

服务器通过环境变量进行配置:

变量

必需

默认值

描述

POCKETBASE_URL

是

—

PocketBase 实例的基础 URL(例如 http://127.0.0.1:8090)

POCKETBASE_SUPERUSER_EMAIL

否

—

用于管理操作的超级用户电子邮件

POCKETBASE_SUPERUSER_PASSWORD

否

—

超级用户密码

POCKETBASE_API_KEY

否

—

长效 API 密钥(电子邮件/密码的替代方案)

在 .env 文件中设置它们或直接导出:

export POCKETBASE_URL=http://127.0.0.1:8090
export POCKETBASE_SUPERUSER_EMAIL=admin@example.com
export POCKETBASE_SUPERUSER_PASSWORD=your-password

运行服务器

stdio 传输(默认 — 适用于 Claude Desktop、Claude Code 等)

pocketmcp

使用 MCP Inspector(用于开发和测试)

# Terminal 1
pocketmcp

# Terminal 2
npx @modelcontextprotocol/inspector
# Connect to: http://localhost:8000/mcp

连接到 Claude

Claude Desktop

将以下内容添加到您的 claude_desktop_config.json 中:

{
  "mcpServers": {
    "pocketbase": {
      "command": "uv",
      "args": ["run", "/absolute/path/to/pocketbase-mcp/server.py"],
      "env": {
        "POCKETBASE_URL": "http://127.0.0.1:8090",
        "POCKETBASE_SUPERUSER_EMAIL": "admin@example.com",
        "POCKETBASE_SUPERUSER_PASSWORD": "your-password"
      }
    }
  }
}

可用工具

记录

工具

描述

list_records

列出集合中的记录,支持过滤、排序和分页

get_record

通过 ID 获取单条记录

create_record

创建新记录

update_record

更新现有记录

delete_record

通过 ID 删除记录

batch_records

在一个请求中执行多个创建/更新/插入/删除操作

集合

工具

描述

list_collections

列出所有集合

get_collection

通过名称或 ID 获取集合架构

create_collection

创建带有字段和 API 规则的新集合

update_collection

更新集合的架构或规则

delete_collection

删除集合

身份验证

工具

描述

auth_with_password

使用电子邮件和密码验证用户或超级用户

auth_with_api_key

使用长效 API 密钥进行验证

get_auth_store

返回当前的身份验证状态

文件

工具

描述

get_file_url

生成附加到记录的文件的 URL

create_file_token

创建用于访问受保护文件的短效令牌

设置

工具

描述

get_settings

检索所有应用程序设置

update_settings

更新应用程序设置


项目结构

pocketbase-mcp/
├── server.py            # MCP server entry point (FastMCP)
├── tools/
│   ├── records.py       # Record CRUD tools
│   ├── collections.py   # Collection management tools
│   ├── auth.py          # Authentication tools
│   ├── files.py         # File tools
│   └── settings.py      # Settings tools
├── client.py            # Async PocketBase HTTP client (httpx)
├── config.py            # Environment variable loading
├── pyproject.toml
└── README.md

使用示例

连接到 Claude 后,您可以通过自然语言与 PocketBase 实例进行交互:

"列出 posts 集合中所有 status = 'published' 的记录,并按 created 降序排列。"

"在 users 中创建一个新记录,姓名为 'Alice',角色为 'editor'。"

"向我展示 products 集合的架构。"

"从 comments 中删除 ID 为 ae40239d2bc4477 的记录。"

"将 PocketBase 设置中的应用名称更新为 'My App'。"


PocketBase 兼容性

此 MCP 服务器的目标版本为 PocketBase v0.36.9+。批量 API 要求在您的 PocketBase 控制面板的 设置 → 应用程序 中明确启用。


安全说明

  • 切勿将凭据提交到版本控制系统。请使用环境变量或 .env 文件(将 .env 添加到 .gitignore)。

  • 对于生产环境部署,优先使用 API 密钥身份验证,而不是电子邮件/密码。

  • PocketBase 中的集合 API 规则决定了经过身份验证的用户实际可以访问的内容 — pocketbase-mcp 会遵守这些规则。


贡献

欢迎贡献!在提交重大更改的拉取请求之前,请先开启一个 issue。

  1. Fork 本仓库

  2. 创建功能分支 (git checkout -b feat/my-feature)

  3. 提交您的更改

  4. 开启拉取请求


许可证

MIT 许可证。详情请参阅 LICENSE。

Related MCP Connectors

Related MCP Servers

  • A
    license
    D
    quality
    Not graded
    maintenance
    A comprehensive MCP server that provides sophisticated tools for interacting with PocketBase databases. This server enables advanced database operations, schema management, and data manipulation through the Model Context Protocol (MCP).
    14
    826 npm
    70
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    A comprehensive server that enables advanced database operations with PocketBase, providing tools for collection management, record operations, user management, and database administration through the Model Context Protocol.
    826 npm
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    A Model Context Protocol server that enables Claude AI to interact with PocketBase databases by listing and accessing collections through natural language.
    7 npm
    1
    MIT
  • -
    license
    B
    quality
    Not graded
    maintenance
    A comprehensive Model Context Protocol server for PocketBase that provides both user and administrative functionality, enabling authentication, collection/record management, file operations, and system administration through a standardized interface.
    38
    7 npm
    -