Provides comprehensive tools for managing PocketBase instances, allowing for the generation, execution, and reverting of migrations, as well as the listing and viewing of collections and fields via the REST API.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@PocketBase MCP Servercreate a 'blog_posts' collection with title, content, and author fields"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
š PocketBase MCP Server
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.
š„ Installation from GitHub
Clone and install
Quick setup
Create an MCP configuration file (
~/.cline_desktop_config.jsonor equivalent):
Restart your MCP client (Cline Desktop, Cursor, etc.)
Test the installation:
# Start the server in development mode npm run dev
š¦ Global installation (optional)
GitHub Repository: https://github.com/Step-by-Step-technology/pocketbase-mcp
⨠Features
ā Available Tools (20 complete tools)
šļø Migration Tools (13 tools)
Tool | Description | Status |
| Generates a migration to create a new collection (supports relation fields) | ā Works perfectly |
| Generates a migration to modify collection rules | ā New |
| Generates a migration to delete a collection | ā New |
| Generates a migration to modify collection fields (supports relation fields) | ā New |
| Generates a migration to add a single field to a collection (supports relation fields) | ā NEW |
| Generates a migration to remove a single field from a collection | ā NEW |
| Generates a migration to revert a previous migration | ā NEW |
| Executes any type of migration (creation, modification, deletion) - now supports relation fields | ā Improved |
| Executes a creation migration (original tool preserved) | ā Works perfectly |
| Lists all available migrations | ā Existing |
| Displays the content of a migration | ā Existing |
| Lists all PocketBase collections | ā Existing |
| Displays collection details | ā Existing |
š CRUD Tools (7 tools)
Tool | Description | Status |
| Fetches a specific record from a PocketBase collection | ā NEW |
| Lists all records from a collection with pagination | ā NEW |
| Creates a new record in a PocketBase collection | ā NEW |
| Updates an existing record in a PocketBase collection | ā NEW |
| Gets the schema (fields and types) of a collection | ā NEW |
| Uploads a file to a PocketBase collection | ā NEW |
| Downloads a file from a PocketBase collection | ā NEW |
Total: 20 complete MCP tools - Migration + CRUD + File management
š Installation (Alternative)
If you have already cloned the project locally or are working on an existing version:
Prerequisites
Node.js 18+
PocketBase running
PocketBase admin token
Local installation
Note: For a complete installation from GitHub, refer to the š„ Installation from GitHub section above.
Configuration
Environment variables are configured in the MCP configuration file (cline_mcp_settings.json):
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 directory
š¦ Project Structure
š ļø Usage
Start the MCP Server
Cline Desktop Configuration
Add to ~/.cline_desktop_config.json:
š Complete Examples
1. Create a Collection
2. Modify Collection Rules
3. Modify Collection Fields
4. Delete a Collection
5. Execute a Migration
6. Add a Field to a Collection
7. Remove a Field from a Collection
8. Revert a Migration
š Complete Workflow
Step 1: Create a Migration
Step 2: Execute the Migration
Step 3: Verify
Step 4: Modify if necessary
šÆ Advanced Use Cases
Creation Migration with Authentication Rules
Authentication Collection Migration
āļø Technical Configuration
Environment Variables
Variable | Description | Default Value |
| URL of the PocketBase instance |
|
| PocketBase admin token | (required) |
| Alternative to token | (optional) |
| Migrations directory |
|
NPM Scripts
š New Features (January 2026)
⨠Addition of 3 New Tools
1. pocketbase-add-field-migration
Purpose: 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 } }
2. pocketbase-remove-field-migration
Purpose: Remove a single field from an existing collection
Advantage: Targeted removal without affecting other fields
Usage example:
{ "collectionName": "products", "fieldName": "stock" }
3. pocketbase-revert-migration
Purpose: Revert a previous migration
Advantage: Safety - ability to undo changes
Usage example:
{ "migrationFile": "1768987877_add_field_stock_to_products.js" }
š§ Improvement of pocketbase-execute-any-migration
New 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 deletion
Compatibility: Doesn't break existing functionality - the original
pocketbase-execute-migrationtool is preserved
š Relation Fields Support (January 2026)
⨠Enhanced Support for Relation Fields
The MCP server now fully supports relation fields in PocketBase collections. This includes creating, updating, and managing collections with foreign key relationships between collections.
Key Improvements
Fixed in
src/pocketbase-migration.ts:Correctly handles
collectionIdparameter for relation fieldsProperly serializes relation field configurations
Supports
maxSelectandcascadeDeleteoptions
Enhanced :
Now correctly processes migration files containing relation fields
Properly handles the execution of migrations with complex field relationships
Updated :
Supports adding/modifying relation fields in existing collections
Maintains backward compatibility with existing collections
š Relation Field Examples
Creating a Collection with Relation Fields
Adding a Relation Field to an Existing Collection
š ļø Technical Details
The fixes address the following issues:
Bug in : The function was not correctly handling the
collectionIdparameter for relation fields, causing migrations to fail when creating collections with relations.Migration Execution: The
pocketbase-execute-any-migrationtool 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)
ā Testing
The relation field support has been thoroughly tested with:
ā Creating collections with relation fields: Works perfectly
ā Adding relation fields to existing collections: Works perfectly
ā Executing migrations with relation fields: Works perfectly
ā Real-world use case: User roles system with
usersārolesrelationships
šÆ Real-World Example: User Roles System
A complete user roles system was implemented using the enhanced relation field support:
roles: Stores role definitions (level 0-9, level 99 for super admin)user_roles: Junction table linking users to roles with relation fieldsAccess rules: Configured with proper authentication rules
Default role assignment: All new users automatically get level 1 (basic user)
This demonstrates the practical application of the relation field support in building complex database schemas with PocketBase.
š§Ŗ Testing
The project has been successfully tested with:
ā Manual tests of all features
ā Real migrations executed on PocketBase
ā Complete validation of the 13 MCP tools
ā Tests of new features:
Field addition: ā Works
Field removal: ā Works
Migration revert: ā Works
To test the MCP server:
š§ Development
Code Structure
src/pocketbase-migration.ts: Migration generation logiccreateMigrationFile(): Collection creationcreateUpdateMigrationFile(): Collection modificationcreateDeleteMigrationFile(): Collection deletioncreateUpdateFieldsMigrationFile(): Field modificationparseMigrationFields(): Parsing fields from migrations
src/pocketbase-tools.ts: MCP tool definitions10 complete tools with Zod validation
Robust error handling
REST API to PocketBase
src/index.ts: Main MCP serverServer configuration
Connection management
Logging and monitoring
Add a New Tool
Add the definition in
pocketbase-tools.tsImplement the business logic
Test manually with MCP tools
Document in the README
š Project Statistics
10 complete MCP tools
4 types of migrations supported (creation, modification, deletion, field modification)
100% TypeScript with Zod validation
Complete REST API to PocketBase
Robust error handling
Complete documentation
š Deployment on GitHub
Prepare the Project for GitHub
Files to Include in .gitignore
Package.json for Publication
Make sure your package.json contains: