undo_edit
Reverse the most recent change made to a file, restoring its previous state. Specify the file path to correct unintended modifications.
Instructions
Undo the last edit to a file
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Absolute path to the file |
Implementation Reference
- src/editor.ts:188-199 (handler)The main handler function for the 'undo_edit' tool. It validates the path, checks if there is edit history for the file, pops the last previous version from the history, writes it back to the file, and returns a success message with the restored content.async undoEdit(args: UndoEditArgs): Promise<string> { await validatePath('undo_edit', args.path); if (!this.fileHistory[args.path] || this.fileHistory[args.path].length === 0) { throw new ToolError(`No edit history found for ${args.path}.`); } const oldText = this.fileHistory[args.path].pop()!; await writeFile(args.path, oldText); return `Last edit to ${args.path} undone successfully. ${makeOutput(oldText, String(args.path))}`; }
- src/server.ts:126-138 (registration)Registration of the 'undo_edit' tool in the listTools handler, including its name, description, and input schema.name: "undo_edit", description: "Undo the last edit to a file", inputSchema: { type: "object", properties: { path: { type: "string", description: "Absolute path to the file" } }, required: ["path"] } }
- src/server.ts:174-179 (registration)Dispatch logic in the CallToolRequest handler that validates arguments using isUndoEditArgs and calls the editor's undoEdit method.case "undo_edit": if (!request.params.arguments || !isUndoEditArgs(request.params.arguments)) { throw new ToolError("Invalid arguments for undo_edit command"); // Fixed } result = await this.editor.undoEdit(request.params.arguments); break;
- src/types.ts:36-38 (schema)TypeScript interface defining the input arguments for the 'undo_edit' tool.export interface UndoEditArgs extends Record<string, unknown> { path: string; }
- src/types.ts:64-66 (schema)Type guard function to validate if arguments match UndoEditArgs for the 'undo_edit' tool.export function isUndoEditArgs(args: Record<string, unknown>): args is UndoEditArgs { return typeof args.path === "string"; }