Skip to main content
Glama
mabeldata

PocketBase MCP Server

by mabeldata

revert_to_migration

Reverts database schema migrations up to a specified target using applied migration filenames, allowing precise control over schema rollbacks in PocketBase MCP Server.

Instructions

Revert migrations up to a specific target.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
appliedMigrationsNoArray of already applied migration filenames.
targetMigrationYesName of the migration to revert to (exclusive). Use empty string to revert all.

Implementation Reference

  • Primary handler function for the 'revert_to_migration' MCP tool. Validates input arguments and calls the revertToMigration utility, formatting the response.
    async function handleRevertToMigration(args: RevertToMigrationArgs, pb: PocketBase): Promise<ToolResult> {
        if (args.targetMigration === undefined) {
            throw invalidParamsError("Missing required argument: targetMigration");
        }
        
        try {
            const appliedMigrations = args.appliedMigrations || [];
            const result = await revertToMigration(args.targetMigration, pb, appliedMigrations);
            
            if (result.length === 0) {
                return {
                    content: [{ type: 'text', text: 'No migrations to revert.' }],
                };
            }
            
            return {
                content: [{ type: 'text', text: `Reverted migrations:\n${result.join('\n')}` }],
            };
        } catch (error: any) {
            throw new Error(`Failed to revert migrations: ${error.message}`);
        }
    }
  • JSON schema definition for the 'revert_to_migration' tool inputs, used for MCP validation.
    {
        name: 'revert_to_migration',
        description: 'Revert migrations up to a specific target.',
        inputSchema: {
            type: 'object',
            properties: {
                targetMigration: { 
                    type: 'string', 
                    description: 'Name of the migration to revert to (exclusive). Use empty string to revert all.' 
                },
                appliedMigrations: { 
                    type: 'array', 
                    items: { type: 'string' },
                    description: 'Array of already applied migration filenames.' 
                },
            },
            required: ['targetMigration'],
        },
    },
  • Main tools registration where migration tools (including revert_to_migration) are included via listMigrationTools().
    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 };
    }
  • Routing logic in main handleToolCall that directs 'revert_to_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);
  • Core utility function implementing the logic to revert multiple migrations up to a target migration by sorting and calling revertMigration on each.
    export async function revertToMigration(
        targetMigration: string,
        pb: PocketBase,
        migrationsDir: string,
        appliedMigrations: string[] = []
    ): Promise<string[]> {
        try {
            // If no migrations have been applied, nothing to revert
            if (appliedMigrations.length === 0) {
                return [];
            }
            
            // Sort applied migrations in reverse chronological order
            const sortedMigrations = [...appliedMigrations].sort((a, b) => {
                const tsA = parseInt(a.split('_')[0], 10);
                const tsB = parseInt(b.split('_')[0], 10);
                return tsB - tsA; // Descending order
            });
            
            const targetIndex = sortedMigrations.indexOf(targetMigration);
            if (targetIndex === -1 && targetMigration !== '') {
                throw new Error(`Target migration not found: ${targetMigration}`);
            }
            
            // Determine which migrations to revert
            const migrationsToRevert = targetMigration === '' 
                ? sortedMigrations // Revert all if target is empty
                : sortedMigrations.slice(0, targetIndex);
            
            const reverted: string[] = [];
            
            // Revert each migration
            for (const migration of migrationsToRevert) {
                await revertMigration(migration, pb, migrationsDir);
                reverted.push(migration);
            }
            
            return reverted;
        } catch (error: any) {
            console.error('Error reverting migrations:', error);
            throw new Error(`Failed to revert migrations: ${error.message}`);
        }
    }
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 offers limited behavioral insight. It mentions reversion but doesn't disclose critical traits like whether this is destructive, requires specific permissions, has side effects, or how it handles errors. For a tool that likely alters database state, this is a significant gap in safety and operational 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?

The description is a single, efficient sentence that front-loads the core purpose without unnecessary words. Every part earns its place by specifying the action and target, making it easy to parse quickly.

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?

Given the complexity of a migration reversion tool with no annotations and no output schema, the description is incomplete. It fails to address behavioral risks, output format, or error handling, leaving the agent with insufficient information for safe and effective invocation in a database context.

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 input schema fully documents parameters. The description adds no additional meaning beyond implying the tool uses 'targetMigration' for reversion scope. It doesn't clarify parameter interactions or provide examples, resulting in a baseline score as the schema handles 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 action ('revert') and target ('migrations'), specifying scope with 'up to a specific target'. It distinguishes from the sibling 'revert_migration' by implying batch reversion versus single migration, though not explicitly named. However, it lacks explicit differentiation from other migration tools like 'apply_all_migrations'.

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?

No explicit guidance on when to use this tool versus alternatives is provided. The description implies usage for reverting multiple migrations, but it doesn't specify prerequisites, conditions, or compare with sibling tools like 'revert_migration' or 'apply_all_migrations'. This leaves the agent with minimal context for selection.

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