Skip to main content
Glama
MrGNSS

Desktop Commander MCP

edit_block

Apply precise text replacements to files using a structured format. Specify search patterns and new content to make verified changes, ideal for targeted modifications.

Instructions

Apply surgical text replacements to files. Best for small changes (<20% of file size). Multiple blocks can be used for separate changes. Will verify changes after application. Format: filepath, then <<<<<<< SEARCH, content to find, =======, new content, >>>>>>> REPLACE.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
blockContentYes

Implementation Reference

  • The main handler for the 'edit_block' tool. It parses the input arguments using EditBlockArgsSchema, extracts filePath and searchReplace pairs by calling parseEditBlock, applies the replacement using performSearchReplace, and returns a success message.
    case "edit_block": {
      const parsed = EditBlockArgsSchema.parse(args);
      const { filePath, searchReplace } = await parseEditBlock(parsed.blockContent);
      await performSearchReplace(filePath, searchReplace);
      return {
        content: [{ type: "text", text: `Successfully applied edit to ${filePath}` }],
      };
    }
  • Zod schema defining the input for the edit_block tool: a string containing the edit block with filepath and SEARCH/REPLACE markers.
    export const EditBlockArgsSchema = z.object({
      blockContent: z.string(),
    });
  • src/server.ts:198-205 (registration)
    Registration of the 'edit_block' tool in the MCP server's tool list, including name, description, and input schema reference.
    {
      name: "edit_block",
      description:
          "Apply surgical text replacements to files. Best for small changes (<20% of file size). " +
          "Multiple blocks can be used for separate changes. Will verify changes after application. " +
          "Format: filepath, then <<<<<<< SEARCH, content to find, =======, new content, >>>>>>> REPLACE.",
      inputSchema: zodToJsonSchema(EditBlockArgsSchema),
    },
  • Helper function that parses the blockContent string into filePath and a single searchReplace object by identifying the SEARCH/REPLACE markers.
    export async function parseEditBlock(blockContent: string): Promise<{
        filePath: string;
        searchReplace: SearchReplace;
    }> {
        const lines = blockContent.split('\n');
        
        // First line should be the file path
        const filePath = lines[0].trim();
        
        // Find the markers
        const searchStart = lines.indexOf('<<<<<<< SEARCH');
        const divider = lines.indexOf('=======');
        const replaceEnd = lines.indexOf('>>>>>>> REPLACE');
        
        if (searchStart === -1 || divider === -1 || replaceEnd === -1) {
            throw new Error('Invalid edit block format - missing markers');
        }
        
        // Extract search and replace content
        const search = lines.slice(searchStart + 1, divider).join('\n');
        const replace = lines.slice(divider + 1, replaceEnd).join('\n');
        
        return {
            filePath,
            searchReplace: { search, replace }
        };
    }
  • Helper function that performs the actual search and replace in the target file by reading the file, finding the first match, replacing it, and writing back.
    export async function performSearchReplace(filePath: string, block: SearchReplace): Promise<void> {
        const content = await readFile(filePath);
        
        // Find first occurrence
        const searchIndex = content.indexOf(block.search);
        if (searchIndex === -1) {
            throw new Error(`Search content not found in ${filePath}`);
        }
    
        // Replace content
        const newContent = 
            content.substring(0, searchIndex) + 
            block.replace + 
            content.substring(searchIndex + block.search.length);
    
        await writeFile(filePath, newContent);
    }
Behavior4/5

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

With no annotations provided, the description carries the full burden and does well by disclosing key behavioral traits: it's a mutation tool (implied by 'replacements'), includes a size constraint (<20% of file size), supports multiple changes, and will 'verify changes after application.' However, it lacks details on error handling or permissions.

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 appropriately sized and front-loaded, starting with the core purpose, followed by usage tips, and ending with the parameter format. Every sentence adds value without redundancy, making it efficient and easy to parse.

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

Completeness4/5

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

Given the tool's complexity (mutation with verification) and no annotations or output schema, the description is mostly complete, covering purpose, usage, behavior, and parameters. It could improve by mentioning error cases or output format, but it's sufficient for an agent to use the tool correctly.

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

Parameters5/5

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

Schema description coverage is 0%, so the description must compensate fully. It explains the single parameter 'blockContent' by detailing its format: 'filepath, then <<<<<<< SEARCH, content to find, =======, new content, >>>>>>> REPLACE,' adding essential meaning beyond the schema's minimal type information.

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

Purpose5/5

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

The description clearly states the tool's purpose with specific verbs ('apply surgical text replacements') and resource ('files'), distinguishing it from siblings like write_file or search_files by focusing on targeted modifications rather than full writes or searches.

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

Usage Guidelines4/5

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

It provides clear context for when to use the tool ('best for small changes (<20% of file size)') and mentions 'multiple blocks can be used for separate changes,' but does not explicitly state when not to use it or name alternatives among siblings like write_file for larger changes.

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/MrGNSS/ClaudeDesktopCommander'

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