Skip to main content
Glama
fadlee

PocketBase MCP Server

by fadlee

migrate_collection

Modify collection structure by adding, removing, or updating fields, including data transformations and access rules for PocketBase databases.

Instructions

Add, remove, or modify fields from a collection

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collectionYesCollection name
createRuleNoOptional new rule for creating records
dataTransformsNoField transformation mappings for converting old field values to new ones
deleteRuleNoOptional new rule for deleting records
fieldsYesNew collection fields configuration
listRuleNoOptional new rule for listing records
nameNoOptional new collection name if you want to rename the collection
updateRuleNoOptional new rule for updating records
viewRuleNoOptional new rule for viewing records

Implementation Reference

  • The createMigrateCollectionHandler function returns the core async tool handler that updates the collection schema (fields, rules, name) and optionally transforms existing data fields.
    export function createMigrateCollectionHandler(pb: PocketBase): ToolHandler { return async (args: MigrateCollectionArgs) => { try { const { collection, fields, dataTransforms = {}, name, ...rules } = args; // Prepare update data const updateData: any = { fields, ...rules, }; if (name) updateData.name = name; // Update collection schema const updatedCollection = await pb.collections.update(collection, updateData); // If there are data transforms, apply them if (Object.keys(dataTransforms).length > 0) { const records = await pb.collection(collection).getFullList(); for (const record of records) { const updates: any = {}; let hasUpdates = false; for (const [oldField, newField] of Object.entries(dataTransforms)) { if (record[oldField] !== undefined) { updates[newField] = record[oldField]; hasUpdates = true; } } if (hasUpdates) { await pb.collection(collection).update(record.id, updates); } } } return createJsonResponse({ success: true, collection: updatedCollection, message: `Collection '${collection}' migrated successfully`, }); } catch (error: unknown) { throw handlePocketBaseError("migrate collection", error); } }; }
  • JSON schema defining the input parameters for the migrate_collection tool, including collection name, new fields configuration, data transforms, and optional rules.
    export const migrateCollectionSchema = { type: "object", properties: { collection: { type: "string", description: "Collection name", }, fields: { type: "array", description: "New collection fields configuration", items: { type: "object", properties: { name: { type: "string", description: "Field name", }, type: { type: "string", description: "Field type", enum: [ "text", "number", "bool", "email", "url", "date", "select", "relation", "file", "json", "editor", "autodate", ], }, required: { type: "boolean", description: "Whether the field is required", }, options: { type: "object", description: "Field-specific options", }, }, required: ["name", "type"], }, }, dataTransforms: { type: "object", description: "Field transformation mappings for converting old field values to new ones", }, name: { type: "string", description: "Optional new collection name if you want to rename the collection", }, listRule: { type: "string", description: "Optional new rule for listing records", }, viewRule: { type: "string", description: "Optional new rule for viewing records", }, createRule: { type: "string", description: "Optional new rule for creating records", }, updateRule: { type: "string", description: "Optional new rule for updating records", }, deleteRule: { type: "string", description: "Optional new rule for deleting records", }, }, required: ["collection", "fields"], };
  • src/server.ts:179-184 (registration)
    Tool registration object in the MCP server configuration array, linking the name, description, schema, and handler factory.
    { name: "migrate_collection", description: "Add, remove, or modify fields from a collection", inputSchema: migrateCollectionSchema, handler: createMigrateCollectionHandler(pb), },

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/fadlee/pocketbase-mcp'

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