Skip to main content
Glama

util_patch_apply

Read-only

Apply a unified diff — Apply a unified diff (git diff / diff -u output) to a file's text and get the patched text back, like GNU patch. text= original file content (empty for a new file), patch= the diff. Hunks are located by context with line-offset search and fuzz (fuzz=0-3, default 2, drops outer context lines); already-applied hunks are detected; CRLF and missing-final-newline markers are preserved. Optional: reverse=true (un-apply), ignore_whitespace=true, atomic=true (422 and no result if any hunk fails), file= (pick one file from a multi-file patch). Returns status applied|partial|failed|already_applied, result text, per-hunk report (line, offset, fuzz), lines added/removed and the rejected hunks. Offline. Price: $0.002 USDC (Base, via x402).

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": {
      "text": "<text>",
      "patch": "<patch>"
    },
    "name": "util_patch_apply"
  }
}

Input Schema

NameRequiredDescriptionDefault
textYesalpha beta gamma
patchYes@@ -1,3 +1,3 @@ alpha -beta +BETA gamma

Schema Changelog

Changes observed during successful MCP inspections.

  1. Added

TDQS

A4.6/5.0
Behavior5/5

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

Goes well past the annotations by disclosing hunk-location strategy, the fuzz default of 2 with its 0-3 range and effect, already-applied detection, CRLF and missing-final-newline preservation, atomic-failure semantics (422, no result), and the full status vocabulary. The only tension is 'Offline.' against openWorldHint=true, which the x402/Base payment call plausibly explains, so this is not a contradiction.

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?

Front-loads the core action and return value in the first clause, then packs options, edge-case behavior, and outputs into dense but scannable segments. The single long paragraph is efficient, though the em-dash chaining and mid-sentence option list make it slightly harder to parse than it needs to be.

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?

With no output schema, the description fully compensates by enumerating the return payload: status (applied|partial|failed|already_applied), result text, per-hunk report with line/offset/fuzz, lines added/removed, and rejected hunks. Cost and transport (offline, $0.002 USDC via x402) are also stated, so nothing material is missing for correct invocation.

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?

Adds real meaning beyond the schema, whose two property descriptions are only literal sample values: it explains that text is the original file content and may be empty for a new file, and that patch is unified-diff output. It also documents reverse, ignore_whitespace, atomic, file, and fuzz, none of which appear in the input schema, which is useful detail but creates a mismatch an agent could trip over.

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 and resource ('Apply a unified diff ... to a file's text and get the patched text back, like GNU patch') and pins the input format (git diff / diff -u). The 'like GNU patch' anchor plus the returned-text framing makes it unmistakable versus a JSON patch or JSON diff sibling.

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 clear operating context: text is the original content (empty for a new file), patch is the diff, and reverse=true un-applies. It never names an alternative or an explicit when-not-to-use case (e.g. structured JSON patches belong to a different tool), so it stops short of full routing guidance.

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

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.

Resources