Skip to main content
Glama

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
NameRequiredDescriptionDefault
pathYesAbsolute path to the file

Implementation Reference

  • 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;
  • TypeScript interface defining the input arguments for the 'undo_edit' tool.
    export interface UndoEditArgs extends Record<string, unknown> {
        path: string;
    }
  • 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";
    }
Install Server

Other 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/arathald/mcp-editor'

If you have feedback or need assistance with the MCP directory API, please join our Discord server