undo_edit
Revert the most recent changes made to a specified file, restoring it to its previous state using the absolute file path.
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 restores the previous version of the file by popping from the file history and writing it back.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/types.ts:36-38 (schema)TypeScript interface defining the input schema for undo_edit arguments.export interface UndoEditArgs extends Record<string, unknown> { path: string; }
- src/types.ts:64-66 (helper)Type guard helper to validate if arguments match UndoEditArgs.export function isUndoEditArgs(args: Record<string, unknown>): args is UndoEditArgs { return typeof args.path === "string"; }
- src/server.ts:125-138 (registration)Tool registration in the ListTools response, including 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 CallToolRequest handler that validates arguments 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;