Skip to main content
Glama
wonderwhy-er

Claude Desktop Commander MCP

by wonderwhy-er

edit_block

Destructive

Apply surgical edits to files.

Instructions

                    Apply surgical edits to files.

                    Small, focused edits are easier to verify than large multi-purpose replacements.
                    old_string can include enough surrounding context to uniquely identify the intended text.

                    FORMAT HANDLING (by extension):

                    EXCEL FILES (.xlsx, .xls, .xlsm) - Range Update mode:
                    Takes:
                    - file_path: Path to the Excel file
                    - range uses FROM:TO format - "SheetName!A1:C10" or "SheetName!C1:C1"
                    - content: 2D array, e.g., [["H1","H2"],["R1","R2"]]

                    TEXT FILES - Find/Replace mode:
                    Takes:
                    - file_path: Path to the file to edit
                    - old_string: Text to replace
                    - new_string: Replacement text
                    - expected_replacements: Optional number of replacements (default: 1)

                    DOCX FILES (.docx) - XML Find/Replace mode:
                    Takes same parameters as text files (old_string, new_string, expected_replacements).
                    Operates on the pretty-printed XML inside the DOCX — the same XML you see from
                    read_file with offset/length. Copy XML fragments from read output as old_string.
                    After editing, the XML is repacked into a valid DOCX.
                    Also searches headers/footers if not found in document body.
                    Examples:
                    - Replace text: old_string="<w:t>Old Text</w:t>" new_string="<w:t>New Text</w:t>"
                    - Change style: old_string='<w:pStyle w:val="Normal"/>' new_string='<w:pStyle w:val="Heading1"/>'
                    - Add content: include surrounding XML context in old_string, add new elements in new_string

                    By default, replaces only ONE occurrence of the search text.
                    To replace multiple occurrences, provide expected_replacements with
                    the exact number of matches expected.

                    UNIQUENESS REQUIREMENT: When expected_replacements=1 (default), include the minimal
                    amount of context necessary (typically 1-3 lines) before and after the change point,
                    with exact whitespace and indentation.

                    When editing multiple sections, make separate edit_block calls for each distinct change
                    rather than one large replacement.

                    When a close but non-exact match is found, a character-level diff is shown in the format:
                    common_prefix{-removed-}{+added+}common_suffix to help you identify what's different.

                    Similar to write_file, there is a configurable line limit (fileWriteLineLimit) that warns
                    if the edited file exceeds this limit. If this happens, consider breaking your edits into
                    smaller, more focused changes.

                    Absolute paths are the most reliable because they do not depend on the current working directory. Paths are automatically normalized regardless of slash direction. Relative paths depend on the current working directory, and tilde paths (~/...) may not resolve in every context. Absolute paths are generally the most reliable.
                    This command can be referenced as "DC: ..." or "use Desktop Commander to ..." in your instructions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
rangeNo
originNo
contentNo
optionsNo
file_pathYes
new_stringNo
old_stringNo
expected_replacementsNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv0.2.43
    • addedInput schema / properties / origin
      Added value: +{
      +  "enum": [
      +    "ui",
      +    "llm"
      +  ],
      +  "type": "string"
      +}
  2. Changed4 schema fields changedv0.2.17
    • addedInput schema / properties / content
      Added value: +{}
    • addedInput schema / properties / options
      Added value: +{
      +  "additionalProperties": {},
      +  "type": "object"
      +}
    • addedInput schema / properties / range
      Added value: +{
      +  "type": "string"
      +}
    • changedInput schema / required
      Previous value: -[
      -  "file_path",
      -  "old_string",
      -  "new_string"
      -]New value: +[
      +  "file_path"
      +]
  3. First observedv1.0.0

TDQS

A4.4/5.0
Behavior5/5

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

Annotations already declare destructiveHint=true and readOnlyHint=false, but the description adds substantial context beyond that: default single-occurrence replacement, expected_replacements semantics, the uniqueness requirement for matching, a character-level diff on near-matches, the configurable fileWriteLineLimit warning, and DOCX XML repacking behavior. This is rich behavioral disclosure that annotations alone cannot convey.

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

Conciseness3/5

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

The purpose and core editing rules are front-loaded, and the format-handling sections are genuinely useful for a polymorphic tool. However, it is verbose and contains redundancy, notably restating absolute-path reliability twice and repeating the single-replacement default in two places, which dilutes an otherwise well-structured description.

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?

For a complex 8-parameter tool with no output schema and 0% schema coverage, the description is substantially complete: it explains the three editing modes, the uniqueness/replacement model, failure feedback, and path handling. The main gap is the undocumented 'origin' enum and 'options' object, which an agent cannot interpret from any source.

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?

Schema description coverage is 0%, so the description must carry the burden, and it does for most parameters: file_path, old_string, new_string, expected_replacements (with default 1), range (with FROM:TO format and examples), and content (2D array format). It leaves 'origin' (the one enum) and 'options' (nested object) undocumented, so it falls short of full coverage despite strong compensation.

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?

States a specific verb+resource ('Apply surgical edits to files') and immediately differentiates from the sibling write_file by contrasting small focused edits against 'large multi-purpose replacements.' It further distinguishes itself as a polymorphic editor by enumerating the file types it handles (Excel, text, DOCX), so an agent can identify it without opening the schema.

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?

Gives concrete usage context: prefer small focused edits, use separate edit_block calls for multiple sections, include minimal surrounding context, and route by extension to the correct parameter mode. It does not explicitly state when to choose a sibling like write_file instead, but the implied split (surgical edits vs. full-file write) is clear.

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