Skip to main content
Glama

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

Implementation Reference

  • 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))}`; }
  • TypeScript interface defining the input schema for undo_edit arguments.
    export interface UndoEditArgs extends Record<string, unknown> { path: string; }
  • 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;

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

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