Skip to main content
Glama
mabeldata

PocketBase MCP Server

by mabeldata

create_collection_migration

Create a PocketBase migration file to add a new collection by specifying its full schema definition, including name, fields, and rules.

Instructions

Create a migration file specifically for creating a new PocketBase collection.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
descriptionNoOptional description override for the filename.
collectionDefinitionYesThe full schema definition for the new collection (including name, id, fields, rules, etc.).

Implementation Reference

  • Tool handler for 'create_collection_migration'. Validates args (requires collectionDefinition with name and id), then delegates to the core createCollectionMigration function and returns a success message.
    async function handleCreateCollectionMigration(args: CreateCollectionMigrationArgs): Promise<ToolResult> {
        if (!args.collectionDefinition) {
            throw invalidParamsError("Missing required argument: collectionDefinition");
        }
         if (!args.collectionDefinition.name || !args.collectionDefinition.id) {
            throw invalidParamsError("collectionDefinition must include 'name' and 'id' properties.");
        }
        const filePath = await createCollectionMigration(args.collectionDefinition, args.description);
        return {
            content: [{ type: 'text', text: `Created collection migration file: ${filePath}` }],
        };
    }
  • TypeScript interface defining the input schema for CreateCollectionMigrationArgs: optional description string and required collectionDefinition Record.
    interface CreateCollectionMigrationArgs {
        description?: string;
        collectionDefinition: Record<string, any>;
    }
  • Tool registration metadata for 'create_collection_migration', including inputSchema with required collectionDefinition (object with required name, id, additionalProperties true).
    name: 'create_collection_migration',
    description: 'Create a migration file specifically for creating a new PocketBase collection.',
    inputSchema: {
        type: 'object',
        properties: {
            description: { type: 'string', description: 'Optional description override for the filename.' },
            collectionDefinition: {
                type: 'object',
                description: 'The full schema definition for the new collection (including name, id, fields, rules, etc.).',
                additionalProperties: true, // Allow any properties for the schema
                 required: ['name', 'id'] // Enforce required schema properties
            },
        },
        required: ['collectionDefinition'],
    },
  • Core logic: creates a migration file for a new collection. Generates timestamp, sanitizes description, builds filename, creates up query (create collection) and down query (delete collection), and writes file via helpers.
    export async function createCollectionMigration(collectionDefinition: Record<string, any>, description?: string): Promise<string> {
        const timestamp = helpers.generateTimestamp();
        const collectionName = collectionDefinition.name;
        if (!collectionName || typeof collectionName !== 'string') {
            throw new Error("Collection definition must have a 'name' property.");
        }
        const collectionId = collectionDefinition.id;
         if (!collectionId || typeof collectionId !== 'string') {
            throw new Error("Collection definition must have an 'id' property.");
        }
    
    
        const desc = description || `create_${collectionName}_collection`;
        const sanitizedDescription = desc
            .toLowerCase()
            .replace(/[^a-z0-9_]+/g, '_')
            .replace(/^_+|_+$/g, '');
    
        const filename = `${timestamp}_${sanitizedDescription}.js`;
    
        // Generate specific up/down queries
        const upQuery = helpers.generateCreateCollectionQuery(collectionDefinition);
        const downQuery = helpers.generateDeleteCollectionQuery(collectionId); // Use ID for down query
    
        const content = helpers.generateMigrationTemplate(upQuery, downQuery);
    
        return helpers.createMigrationFile(filename, content);
    }
  • Routes the 'create_collection_migration' tool name to handleMigrationToolCall in the central dispatcher.
    } else if (name === 'create_migration' || name === 'create_collection_migration' || name === 'add_field_migration' || name === 'list_migrations') {
        return handleMigrationToolCall(name, toolArgs, pb);
Behavior2/5

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

No annotations provided, so description carries full burden. Does not disclose side effects (e.g., writes to disk, applies immediately, requires permissions). Missing behavioral traits beyond basic purpose.

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?

One sentence, front-loaded, no wasted words. Appropriately concise for a simple tool with clear purpose.

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?

No output schema, and description lacks details on what 'create migration file' means (e.g., file location, naming convention, whether it applies the migration). Missing critical context for agent to fully understand tool impact.

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?

Schema description coverage is 100%. Both parameters have descriptions in schema. Description adds no extra meaning beyond schema, but baseline 3 is appropriate as schema already documents them.

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

Purpose5/5

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

Description clearly states it creates a migration file for creating a new PocketBase collection. Specific verb+resource, and distinguishes from general 'create_migration' and other siblings like 'add_field_migration'.

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

Usage Guidelines3/5

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

Implied usage: when creating a new collection via migration. But no explicit when-not-to-use or alternatives. Sibling tools like 'add_field_migration' and 'create_migration' exist, but description doesn't differentiate usage context.

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

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