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),
    },
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. While 'Add, remove, or modify fields' implies a potentially destructive mutation operation, it doesn't disclose critical behavioral traits like whether this operation requires specific permissions, whether it's reversible, what happens to existing data during migration, or potential downtime implications. For a complex schema migration tool with zero annotation coverage, this is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise at just 7 words, front-loading the core functionality with zero wasted language. Every word earns its place by communicating the essential action and target.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a complex schema migration tool with 9 parameters, no annotations, and no output schema, the description is inadequate. It doesn't explain the migration process, data preservation implications, error handling, or what happens to existing records during field modifications. The description should provide more context about this potentially complex and impactful operation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description mentions 'fields' but doesn't elaborate on what 'Add, remove, or modify' means in terms of the 9 parameters. With 100% schema description coverage, the schema already documents all parameters thoroughly. The description adds minimal value beyond what's in the structured schema, meeting the baseline expectation when schema coverage is high.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Add, remove, or modify fields') and the target resource ('from a collection'), providing a specific verb+resource combination. However, it doesn't explicitly distinguish this tool from sibling tools like 'update_record' or 'create_collection', which might also modify collection structures in different ways.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With sibling tools like 'update_record' (for modifying individual records) and 'create_collection' (for creating new collections), there's no indication of when this schema migration tool is appropriate versus those other operations.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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

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