rollback
Revert to a previous checkpoint version when a merge produces incorrect results, allowing you to undo changes by specifying how many versions to roll back.
Instructions
Revert to a previous checkpoint version. Useful if a merge produced incorrect results.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| steps | No | Number of versions to roll back (default: 1) |
Implementation Reference
- src/core/ProjectBrain.ts:291-327 (handler)Core implementation of the rollback tool logic: retrieves checkpoint history, validates the number of steps, restores the target checkpoint state from Redis, and returns a success message or error.async rollback(steps: number = 1): Promise<string> { const sessionId = this.ensureInitialized(); try { logger.info('Rolling back checkpoint', { sessionId, steps }); const history = await this.redis.getCheckpointHistory(sessionId); if (history.length === 0) { return 'No checkpoint history available to rollback.'; } if (steps > history.length) { return `Only ${history.length} checkpoints available. Cannot rollback ${steps} steps.`; } // Get the target checkpoint (index is steps because history[0] is current) const targetCheckpoint = history[steps]; // Restore the state await this.redis.updateStateWithLock(sessionId, async () => { return targetCheckpoint.state; }); logger.info('Rollback completed', { targetVersion: targetCheckpoint.version, targetTimestamp: targetCheckpoint.timestamp, }); return `Rolled back to version ${targetCheckpoint.version} (${new Date( targetCheckpoint.timestamp ).toLocaleString()})`; } catch (error) { logger.error('Rollback failed', { error, sessionId }); throw new Error(`Rollback failed: ${error}`); } }
- src/index.ts:144-150 (handler)MCP server handler for the 'rollback' tool call: parses input using the schema and delegates execution to ProjectBrain.rollback().case 'rollback': { const input = RollbackInputSchema.parse(args || {}); const result = await this.brain.rollback(input.steps); return { content: [{ type: 'text', text: result }], }; }
- src/index.ts:85-99 (registration)Registration of the 'rollback' tool in the MCP ListToolsRequestHandler, defining name, description, and input schema.{ name: 'rollback', description: 'Revert to a previous checkpoint version. Useful if a merge produced incorrect results.', inputSchema: { type: 'object', properties: { steps: { type: 'number', description: 'Number of versions to roll back (default: 1)', default: 1, }, }, }, },
- src/types/schema.ts:100-105 (schema)Zod schema definition for RollbackInput and corresponding TypeScript type inference.export const RollbackInputSchema = z.object({ steps: z.number().int().positive().default(1), }); export type CheckpointInput = z.infer<typeof CheckpointInputSchema>; export type RollbackInput = z.infer<typeof RollbackInputSchema>;