Skip to main content
Glama
arathald

mcp-editor

by arathald

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";
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It states the tool 'undoes' an edit, implying mutation/reversal, but doesn't specify whether this is destructive, requires specific permissions, has limitations (e.g., only one undo level), or what happens on failure. This leaves significant behavioral gaps for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose with zero wasted words. It's appropriately front-loaded and earns its place by clearly communicating the core functionality.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a mutation tool with no annotations and no output schema, the description is insufficient. It doesn't address critical context like what 'undo' entails (revert to previous state? delete last change?), error conditions, or return values. Given the complexity of file editing operations, more behavioral detail is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with the single parameter 'path' clearly documented in the schema. The description doesn't add any parameter-specific details beyond what the schema provides (e.g., it doesn't clarify path format requirements or edit history implications), so it meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('undo') and target ('last edit to a file'), providing a specific verb+resource combination. However, it doesn't explicitly differentiate from sibling tools like 'create' or 'insert', which are also file operations but with different purposes.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., requires an edit history), exclusions (e.g., cannot undo deletions), or suggest when other tools like 'string_replace' might be more appropriate for different editing needs.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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