Skip to main content
Glama
mabeldata

PocketBase MCP Server

by mabeldata

create_migration

Generate a timestamped, empty migration file in PocketBase to manage database schema changes with a descriptive filename for tracking purposes.

Instructions

Create a new, empty PocketBase migration file with a timestamped name.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
descriptionYesA brief description for the migration filename (e.g., "add_user_email_index").

Implementation Reference

  • Main handler for 'create_migration' tool: validates input, calls createNewMigration, and returns success message with file path.
    async function handleCreateMigration(args: CreateMigrationArgs): Promise<ToolResult> {
        if (!args.description) {
            throw invalidParamsError("Missing required argument: description");
        }
        const filePath = await createNewMigration(args.description);
        return {
            content: [{ type: 'text', text: `Created new migration file: ${filePath}` }],
        };
    }
  • ToolInfo definition including name, description, and inputSchema for 'create_migration' used for MCP tool registration.
    {
        name: 'create_migration',
        description: 'Create a new, empty PocketBase migration file with a timestamped name.',
        inputSchema: {
            type: 'object',
            properties: {
                description: { type: 'string', description: 'A brief description for the migration filename (e.g., "add_user_email_index").' },
            },
            required: ['description'],
        },
    },
  • Routing logic in handleToolCall that dispatches 'create_migration' calls to the migration tools handler.
    } else if (name === 'create_migration' || name === 'create_collection_migration' || name === 'add_field_migration' || name === 'list_migrations') {
        return handleMigrationToolCall(name, toolArgs, pb);
  • Includes migration tools (including 'create_migration') in the overall tool list via listMigrationTools() in registerTools().
    ...listMigrationTools(), // Uncommented
  • Core helper function createNewMigration that generates filename and content, called by the tool handler.
    export async function createNewMigration(description: string): Promise<string> {
        const timestamp = helpers.generateTimestamp();
        // Sanitize description for filename
        const sanitizedDescription = description
            .toLowerCase()
            .replace(/[^a-z0-9_]+/g, '_') // Replace non-alphanumeric/underscore with underscore
            .replace(/^_+|_+$/g, ''); // Trim leading/trailing underscores
    
        if (!sanitizedDescription) {
            throw new Error("Migration description cannot be empty or only contain invalid characters.");
        }
    
        const filename = `${timestamp}_${sanitizedDescription}.js`;
        const content = helpers.generateMigrationTemplate(); // Generate basic template
    
        return helpers.createMigrationFile(filename, content);
    }

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