Skip to main content
Glama

Self-Healing Fuzzy Unified Diff & Search/Replace Code Patcher

apply_fuzzy_code_patch
Read-onlyIdempotent

Apply code diffs and SEARCH/REPLACE blocks by resolving line-number drift and whitespace mismatches with similarity matching. Use to heal failed code edits.

Instructions

Applies unified diffs (@@ ... @@) or SEARCH/REPLACE blocks to source code using sliding-window token similarity to resolve drifted line numbers, align indentation, and verify bracket balance. Use when healing and applying a code edit or diff that failed exact line matching due to line-number drift or whitespace differences; for inspecting function signatures, call trees, and cyclomatic complexity without modifying code, use analyze_ast_symbol_graph instead. Read-only call (32 KB, 60 RPM): accepts 'original_code' (with enum defaults), uses '?demo=true' or L402 (20 sats); HTTP 400 if invalid.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "original_code": "<original_code>",
      "patch": "<patch>"
    },
    "name": "apply_fuzzy_code_patch"
  }
}

Input Schema

NameRequiredDescriptionDefault
patchYesUnified diff hunk or <<<<<<< SEARCH ... ======= ... >>>>>>> REPLACE block to apply.
fuzz_strategyNoLine-matching tolerance and indentation behavior; defaults to 'whitespace_normalized_auto_indent' when omitted.
original_codeYesComplete original source file content before patching.

Output Schema

NameRequiredDescriptionDefault
hunks_totalYesTotal patch hunks parsed from the input patch.
patched_codeYesResulting source code after applying all matched hunks.
hunks_appliedYesNumber of hunks successfully anchored and applied.
syntax_balance_verifiedYesTrue when post-patch {}, (), and [] delimiters remain balanced.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv1.3.3

TDQS

A4.6/5.0
Behavior5/5

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

Annotations already establish read-only, non-destructive, idempotent behavior, and the description adds operational context beyond that: 32 KB size, 60 RPM, demo/L402 payment handling, and HTTP 400 on invalid input. It also discloses the matching mechanism and bracket-balance verification, which helps the agent anticipate behavior.

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

Conciseness4/5

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

The description is compact and front-loads the purpose before usage guidance and operational constraints. The final sentence is dense and packs several details into semicolons, and the phrase 'with enum defaults' is slightly compressed, but there is little waste.

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

Completeness5/5

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

Given rich annotations, a fully described schema, and an output schema, the description supplies the remaining context an agent needs: what the tool does, when to select it, the alternative, operational limits, and error behavior. Nothing important for correct invocation appears to be missing.

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%, so all three parameters are already documented in the schema. The description mentions 'original_code' and enum defaults, but this adds little beyond the schema and is slightly vague about which parameter actually has the enum default.

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 states a specific verb and resource: applying unified diffs or SEARCH/REPLACE blocks to source code. It also explains the core mechanism and explicitly contrasts itself with analyze_ast_symbol_graph for non-modifying code inspection, so the tool is distinguishable from siblings 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 Guidelines5/5

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

It gives a clear trigger for when to use the tool: healing and applying code edits or diffs that failed exact line matching because of line-number drift or whitespace differences. It also names the alternative tool for signature, call-tree, and complexity inspection, making the decision boundary explicit.

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

Deploy Server

Other Tools