loading…
Search for a command to run...
loading…
A comprehensive MCP server for managing PocketBase database schemas and migrations via REST API. It enables users to generate and execute migrations for creatin
A comprehensive MCP server for managing PocketBase database schemas and migrations via REST API. It enables users to generate and execute migrations for creating, modifying, and deleting collections and fields directly through MCP-compatible clients.
A complete MCP (Model Context Protocol) server for managing PocketBase migrations via REST API. Generates and executes migrations to create, modify, and delete PocketBase collections.
# Clone the repository
git clone https://github.com/Step-by-Step-technology/pocketbase-mcp.git
cd pocketbase-mcp
# Install dependencies
npm install
# Compile TypeScript
npm run build
~/.cline_desktop_config.json or equivalent):{
"mcpServers": {
"pocketbase-mcp": {
"command": "node",
"args": ["/absolute/path/to/pocketbase-mcp/dist/index.js"],
"env": {
"POCKETBASE_URL": "http://127.0.0.1:8090",
"POCKETBASE_TOKEN": "your_pocketbase_admin_token",
"POCKETBASE_MIGRATIONS_DIR": "/absolute/path/to/pb_migrations"
}
}
}
}
Restart your MCP client (Cline Desktop, Cursor, etc.)
Test the installation:
# Start the server in development mode
npm run dev
# Install globally (if you want to use it as CLI)
npm install -g .
# Then run
pocketbase-mcp
GitHub Repository: https://github.com/Step-by-Step-technology/pocketbase-mcp
| Tool | Description | Status |
|---|---|---|
pocketbase-create-collection-migration |
Generates a migration to create a new collection (supports relation fields) | ✅ Works perfectly |
pocketbase-update-collection |
Generates a migration to modify collection rules | ✅ New |
pocketbase-delete-collection |
Generates a migration to delete a collection | ✅ New |
pocketbase-update-collection-fields |
Generates a migration to modify collection fields (supports relation fields) | ✅ New |
pocketbase-add-field-migration |
Generates a migration to add a single field to a collection (supports relation fields) | ✅ NEW |
pocketbase-remove-field-migration |
Generates a migration to remove a single field from a collection | ✅ NEW |
pocketbase-revert-migration |
Generates a migration to revert a previous migration | ✅ NEW |
pocketbase-execute-any-migration |
Executes any type of migration (creation, modification, deletion) - now supports relation fields | ✅ Improved |
pocketbase-execute-migration |
Executes a creation migration (original tool preserved) | ✅ Works perfectly |
pocketbase-list-migrations |
Lists all available migrations | ✅ Existing |
pocketbase-view-migration |
Displays the content of a migration | ✅ Existing |
pocketbase-list-collections |
Lists all PocketBase collections | ✅ Existing |
pocketbase-view-collection |
Displays collection details | ✅ Existing |
| Tool | Description | Status |
|---|---|---|
pocketbase-fetch-record |
Fetches a specific record from a PocketBase collection | ✅ NEW |
pocketbase-list-records |
Lists all records from a collection with pagination | ✅ NEW |
pocketbase-create-record |
Creates a new record in a PocketBase collection | ✅ NEW |
pocketbase-update-record |
Updates an existing record in a PocketBase collection | ✅ NEW |
pocketbase-get-collection-schema |
Gets the schema (fields and types) of a collection | ✅ NEW |
pocketbase-upload-file |
Uploads a file to a PocketBase collection | ✅ NEW |
pocketbase-download-file |
Downloads a file from a PocketBase collection | ✅ NEW |
Total: 20 complete MCP tools - Migration + CRUD + File management
If you have already cloned the project locally or are working on an existing version:
# Move to the pocketbase-mcp folder
cd pocketbase-mcp
# Install dependencies
npm install
# Compile TypeScript
npm run build
Note: For a complete installation from GitHub, refer to the 📥 Installation from GitHub section above.
Environment variables are configured in the MCP configuration file (cline_mcp_settings.json):
{
"mcpServers": {
"pocketbase-mcp": {
"command": "node",
"args": ["/absolute/path/pocketbase-mcp/dist/index.js"],
"env": {
"POCKETBASE_URL": "http://127.0.0.1:8090",
"POCKETBASE_TOKEN": "your_pocketbase_admin_token",
"POCKETBASE_MIGRATIONS_DIR": "/absolute/path/pb_migrations"
}
}
}
}
Required variables:
POCKETBASE_URL: URL of your PocketBase instance (e.g., http://127.0.0.1:8090)POCKETBASE_TOKEN: PocketBase admin token (obtained via admin interface)POCKETBASE_MIGRATIONS_DIR: Absolute path to the migrations directorypocketbase-mcp/
├── src/
│ ├── index.ts # MCP entry point
│ ├── pocketbase-migration.ts # Migration generator
│ └── pocketbase-tools.ts # All MCP tools
├── dist/ # Compiled files
├── pb_migrations/ # Generated migrations
├── package.json
├── tsconfig.json
├── README.md
└── GUIDE_COMPLET.md
# Development
npm run dev
# Production
npm run build
node dist/index.js
Add to ~/.cline_desktop_config.json:
{
"mcpServers": {
"pocketbase-mcp": {
"command": "node",
"args": ["/absolute/path/pocketbase-mcp/dist/index.js"],
"env": {
"POCKETBASE_URL": "http://127.0.0.1:8090",
"POCKETBASE_TOKEN": "your_token",
"POCKETBASE_MIGRATIONS_DIR": "/absolute/path/pb_migrations"
}
}
}
}
{
"collectionName": "products",
"fields": [
{
"name": "title",
"type": "text",
"required": true,
"max": 200
},
{
"name": "price",
"type": "number",
"required": true,
"min": 0
},
{
"name": "category",
"type": "select",
"required": true,
"values": ["electronics", "clothing", "books", "food", "home"]
}
],
"type": "base"
}
{
"collectionName": "products",
"listRule": "@request.auth.id != ''",
"createRule": "@request.auth.id != ''",
"updateRule": "@request.auth.id != ''",
"deleteRule": "@request.auth.id != ''"
}
{
"collectionName": "products",
"fields": [
{
"name": "title",
"type": "text",
"required": true,
"max": 200
},
{
"name": "description",
"type": "text",
"required": false,
"max": 1000
},
{
"name": "price",
"type": "number",
"required": true,
"min": 0
},
{
"name": "stock",
"type": "number",
"required": false,
"min": 0
}
]
}
{
"collectionName": "old_collection"
}
{
"migrationFile": "1768985344_update_products.js"
}
{
"collectionName": "products",
"field": {
"name": "stock",
"type": "number",
"required": false,
"min": 0
}
}
{
"collectionName": "products",
"fieldName": "stock"
}
{
"migrationFile": "1768987877_add_field_stock_to_products.js"
}
# Use the pocketbase-create-collection-migration tool
# → Generates a file in pb_migrations/
# Use the pocketbase-execute-any-migration tool
# → Executes the migration via REST API
# Use pocketbase-list-collections
# → Verifies that the collection was created
# Use pocketbase-update-collection
# → Generates a modification migration
# → Execute with pocketbase-execute-any-migration
{
"collectionName": "user_posts",
"fields": [
{
"name": "title",
"type": "text",
"required": true,
"max": 200
},
{
"name": "content",
"type": "text",
"required": false,
"max": 5000
}
],
"listRule": "@request.auth.id != ''",
"createRule": "@request.auth.id != ''",
"updateRule": "@request.auth.id = author",
"deleteRule": "@request.auth.id = author"
}
{
"collectionName": "users",
"type": "auth",
"fields": [
{
"name": "username",
"type": "text",
"required": true,
"max": 100
},
{
"name": "avatar",
"type": "file",
"required": false,
"maxSelect": 1
}
]
}
| Variable | Description | Default Value |
|---|---|---|
POCKETBASE_URL |
URL of the PocketBase instance | http://127.0.0.1:8090 |
POCKETBASE_TOKEN |
PocketBase admin token | (required) |
POCKETBASE_ADMIN_TOKEN |
Alternative to token | (optional) |
POCKETBASE_MIGRATIONS_DIR |
Migrations directory | ./pb_migrations |
{
"scripts": {
"build": "tsc",
"dev": "tsx watch src/index.ts",
"start": "node dist/index.js"
}
}
pocketbase-add-field-migrationPurpose: Add a single field to an existing collection
Advantage: Fine granularity - no need to rewrite all fields
Usage example:
{
"collectionName": "products",
"field": {
"name": "stock",
"type": "number",
"required": false,
"min": 0
}
}
pocketbase-remove-field-migrationPurpose: Remove a single field from an existing collection
Advantage: Targeted removal without affecting other fields
Usage example:
{
"collectionName": "products",
"fieldName": "stock"
}
pocketbase-revert-migrationPurpose: Revert a previous migration
Advantage: Safety - ability to undo changes
Usage example:
{
"migrationFile": "1768987877_add_field_stock_to_products.js"
}
pocketbase-execute-any-migrationNew detection: Now recognizes 6 types of migrations:
create - Collection creationupdate - Rule modificationupdate_fields - Modification of all fieldsadd_field - Addition of a single fieldremove_field - Removal of a single fielddelete - Collection deletionCompatibility: Doesn't break existing functionality - the original pocketbase-execute-migration tool is preserved
The MCP server now fully supports relation fields in PocketBase collections. This includes creating, updating, and managing collections with foreign key relationships between collections.
Fixed parseMigrationFields() function in src/pocketbase-migration.ts:
collectionId parameter for relation fieldsmaxSelect and cascadeDelete optionsEnhanced pocketbase-execute-any-migration tool:
Updated pocketbase-update-collection-fields tool:
{
"collectionName": "user_roles",
"fields": [
{
"name": "user_ref",
"type": "relation",
"required": true,
"collectionId": "users",
"maxSelect": 1,
"cascadeDelete": false
},
{
"name": "role_ref",
"type": "relation",
"required": true,
"collectionId": "roles",
"maxSelect": 1,
"cascadeDelete": false
},
{
"name": "assigned_at",
"type": "date",
"required": true
},
{
"name": "assigned_by",
"type": "relation",
"required": true,
"collectionId": "users",
"maxSelect": 1,
"cascadeDelete": false
}
],
"type": "base"
}
{
"collectionName": "posts",
"field": {
"name": "author",
"type": "relation",
"required": true,
"collectionId": "users",
"maxSelect": 1,
"cascadeDelete": true
}
}
The fixes address the following issues:
Bug in parseMigrationFields(): The function was not correctly handling the collectionId parameter for relation fields, causing migrations to fail when creating collections with relations.
Migration Execution: The pocketbase-execute-any-migration tool now properly detects and executes migrations containing relation fields without errors.
Field Configuration: Relation fields now support all PocketBase options:
collectionId: The ID of the related collection (required)maxSelect: Maximum number of related records (default: 1)cascadeDelete: Whether to delete related records when the parent is deleted (default: false)The relation field support has been thoroughly tested with:
users ↔ roles relationshipsA complete user roles system was implemented using the enhanced relation field support:
roles collection: Stores role definitions (level 0-9, level 99 for super admin)user_roles collection: Junction table linking users to roles with relation fieldsThis demonstrates the practical application of the relation field support in building complex database schemas with PocketBase.
The project has been successfully tested with:
To test the MCP server:
# Start the server in development mode
npm run dev
# Then use the tools via Cline Desktop or other MCP client
src/pocketbase-migration.ts: Migration generation logic
createMigrationFile(): Collection creationcreateUpdateMigrationFile(): Collection modificationcreateDeleteMigrationFile(): Collection deletioncreateUpdateFieldsMigrationFile(): Field modificationparseMigrationFields(): Parsing fields from migrationssrc/pocketbase-tools.ts: MCP tool definitions
src/index.ts: Main MCP server
pocketbase-tools.ts# Initialize git
git init
# Add files
git add .
# Initial commit
git commit -m "Initial commit: Complete PocketBase MCP Server"
# Create a repo on GitHub
# Link the remote repo
git remote add origin https://github.com/your-username/pocketbase-mcp.git
# Push the code
git push -u origin main
# Dependencies
node_modules/
# Build outputs
dist/
# Environment variables
.env
.env.local
# PocketBase migrations (optional)
pb_migrations/
# IDE
.vscode/
.idea/
# OS
.DS_Store
Make sure your package.json contains:
{
"name": "pocketbase-mcp",
"version": "1.0.0",
"description": "MCP Server for PocketBase migrations",
"main": "dist/index.js",
"scripts": {
"build": "tsc",
"dev": "tsx watch src/index.ts",
"start": "node dist/index.js"
},
"keywords": ["mcp", "pocketbase", "migrations", "database"],
"author": "Step by Step",
"license": "MIT",
"dependencies": {
"@modelcontextprotocol/sdk": "^1.0.0",
"zod": "^3.22.0"
},
"devDependencies": {
"@types/node": "^20.0.0",
"typescript": "^5.0.0",
"tsx": "^4.0.0"
}
}
Добавь это в claude_desktop_config.json и перезапусти Claude Desktop.
{
"mcpServers": {
"pocketbase-mcp-server": {
"command": "npx",
"args": []
}
}
}