Skip to main content
Glama
StrawHatAI

Claude Desktop Commander MCP

by StrawHatAI

edit_block

Apply surgical text replacements to files using diff-based patches. Verify changes after application for precise file 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

  • Entry point handler for the 'edit_block' tool in the tool dispatch switch statement. Parses input, delegates to parseEditBlock and performSearchReplace, and returns success response.
    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}` }],
      };
    }
  • Core function that performs the search-and-replace edit on the target file by reading content, replacing the first occurrence of search text with replace text, 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);
    }
  • Parses the structured blockContent string to extract the target filePath and the search/replace pair based on the specified 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 }
        };
    }
  • Zod schema defining the input for edit_block tool: a single blockContent string containing the edit instructions.
    export const EditBlockArgsSchema = z.object({
      blockContent: z.string(),
    });
  • src/server.ts:198-204 (registration)
    Registration of the 'edit_block' tool in the server's tool list, providing name, description, and JSON schema for inputs.
    {
      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),
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 of behavioral disclosure. It effectively describes key traits: it's a mutation tool (implied by 'apply replacements'), includes verification ('will verify changes after application'), and has constraints on change size. However, it doesn't mention error handling, permissions, or rate limits, leaving some gaps.

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 front-loaded with the core purpose and efficiently structured into three sentences that each add value: purpose, guidelines, and format. There is no wasted text, making it highly concise and well-organized.

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 complexity of a mutation tool with no annotations or output schema, the description is largely complete: it covers purpose, usage, behavior, and parameter semantics. However, it lacks details on error cases, return values, or edge cases, which could be helpful for full contextual understanding.

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

Parameters4/5

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

The input schema has 0% description coverage for the single parameter 'blockContent', but the description compensates by explaining the parameter's format and semantics in detail ('Format: filepath, then <<<<<<< SEARCH...'). This adds significant meaning beyond the schema, though it doesn't explicitly name the parameter.

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. It specifies the scope ('small changes <20% of file size') and method ('multiple blocks for separate changes'), making it highly specific.

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

Usage Guidelines5/5

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

The description provides explicit guidance on when to use this tool ('best for small changes <20% of file size') and implies alternatives by contrasting with other file operations like write_file. It also specifies the format and structure for usage, offering clear context for application.

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/StrawHatAI/claude-dev-tools'

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