Skip to main content
Glama
mabeldata

PocketBase MCP Server

by mabeldata

create_collection_migration

Generate a migration file to define and create a new PocketBase collection, including its schema, fields, and rules, for structured database management.

Instructions

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

Input Schema

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

Implementation Reference

  • The handler function for the 'create_collection_migration' tool. Validates the input arguments and calls the underlying createCollectionMigration helper to generate the migration file.
    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}` }],
        };
    }
  • The tool registration object containing the schema (inputSchema) for validating inputs to the 'create_collection_migration' tool.
    {
        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'],
        },
    },
  • The core helper function that generates and writes the migration file for creating a new collection based on the provided definition.
    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);
    }
  • The dispatch logic in the main tool handler that routes 'create_collection_migration' calls to the migration tool handler.
    } else if (name === 'create_migration' || name === 'create_collection_migration' || name === 'add_field_migration' || name === 'list_migrations') {
        return handleMigrationToolCall(name, toolArgs, pb);
  • The main tool registration function that includes migration tools (via listMigrationTools()), making 'create_collection_migration' available.
    export function registerTools(): { tools: ToolInfo[] } { // Use ToolInfo[]
        const tools: ToolInfo[] = [ // Use ToolInfo[]
            ...listRecordTools(),
            ...listCollectionTools(),
            ...listFileTools(),
            ...listMigrationTools(), // Uncommented
            ...listLogTools(), // Add log tools
            ...listCronTools(), // Add cron tools
        ];
        return { tools };
    }
Behavior2/5

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

With no annotations provided, the description carries full burden but only states what the tool does, not how it behaves. It doesn't disclose whether this creates a file on disk, requires specific permissions, has side effects, or what happens if the collection already exists. For a tool that likely creates migration files (potentially with system impact), this is insufficient behavioral context.

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?

Single sentence that efficiently conveys the core purpose without wasted words. Front-loaded with the main action and resource. Every word earns its place in this compact description.

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

Completeness3/5

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

Given 2 parameters with full schema coverage but no annotations and no output schema, the description is minimally adequate. It states the purpose but lacks behavioral context (permissions, side effects, file location) and doesn't explain what the migration file contains or how it relates to PocketBase's migration system. For a tool that creates migration artifacts, more context would be helpful.

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%, so the schema fully documents both parameters. The description adds no additional parameter semantics beyond what's in the schema (e.g., no examples of collectionDefinition structure, no clarification on filename generation). Baseline 3 is appropriate when schema does the heavy lifting.

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 verb 'Create' and the resource 'migration file' with the specific purpose 'for creating a new PocketBase collection.' It distinguishes from generic 'create_migration' by specifying the collection creation context. However, it doesn't explicitly differentiate from 'add_field_migration' which might be for modifying existing collections.

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?

The description implies usage when creating a new collection migration, but doesn't provide explicit guidance on when to use this versus alternatives like 'create_migration' (generic) or 'add_field_migration' (for field additions). No prerequisites, exclusions, or comparison to sibling tools are mentioned.

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

Related 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