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).
- Create and manage collections with custom schemas
- Migrate collection schemas with data preservation
- Advanced index management (create, delete, list)
- Schema validation and type safety
- Retrieve collection schemas and metadata
- CRUD operations for records
- Advanced querying with filtering, sorting, and aggregation
- Batch import/export capabilities
- Relationship expansion support
- Pagination and cursor-based navigation
- User authentication and token management
- User account creation and management
- Password management
- Role-based access control
- Session handling
- Database backup and restore
- Multiple export formats (JSON/CSV)
- Data migration tools
- Index optimization
- Batch operations
create_collection
: Create a new collection with custom schemaget_collection_schema
: Get schema details for a collectionmigrate_collection
: Migrate collection schema with data preservationmanage_indexes
: Create, delete, or list collection indexes
create_record
: Create a new record in a collectionlist_records
: List records with optional filters and paginationupdate_record
: Update an existing recorddelete_record
: Delete a recordquery_collection
: Advanced query with filtering, sorting, and aggregationimport_data
: Import data into a collection with create/update/upsert modes
authenticate_user
: Authenticate a user and get auth tokencreate_user
: Create a new user account
backup_database
: Create a backup of the PocketBase database with format optionsimport_data
: Import data with various modes (create/update/upsert)
The server requires the following environment variables:
POCKETBASE_URL
: URL of your PocketBase instance (e.g., "http://127.0.0.1:8090")
Optional environment variables:
POCKETBASE_ADMIN_EMAIL
: Admin email for certain operationsPOCKETBASE_ADMIN_PASSWORD
: Admin passwordPOCKETBASE_DATA_DIR
: Custom data directory path
// 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)"
}
});
All tools include comprehensive error handling with detailed error messages. Errors are properly typed and include:
- Invalid request errors
- Authentication errors
- Database operation errors
- Schema validation errors
- Network errors
The server includes TypeScript definitions for all operations, ensuring type safety when using the tools. Each tool's input schema is strictly typed and validated.
- Always use proper error handling with try/catch blocks
- Validate data before performing operations
- Use appropriate indexes for better query performance
- Regularly backup your database
- Use migrations for schema changes
- Follow security best practices for user management
- Monitor and optimize database performance
- Clone the repository
- Install dependencies:
npm install
- Copy
.env.example
to.env
and configure - Build:
npm run build
- Start your PocketBase instance
- The MCP server will automatically connect to your PocketBase instance
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request