Skip to main content
Glama

patch

Apply a unified diff to a file with context-line verification, preserving encoding and per-line endings. Preview changes with a dry run before writing.

Instructions

Applies a unified diff patch to a file. Parses @@ hunk headers, verifies context lines, and applies changes. Encoding-aware: preserves original file encoding. Line-ending aware: each line keeps its own ending (a mixed CRLF/LF file is not rewritten) and a file without a trailing newline does not gain one. Use dry_run=true to preview without modifying the file.

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

Input Schema

NameRequiredDescriptionDefault
pathNoAlias for file_path
patchYesUnified diff text (output of the diff tool)
dry_runNoPreview patch result without modifying the file: true or false. Default: false
encodingNoCharset override, e.g. CP949; overrides .editorconfig, BOM takes priority
file_pathNoFile to patch. Relative paths use the configured workspace or MCP client root
expected_hashNoExpected raw-file SHA-256; mismatch rejects the patch

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed2 schema fields changedv1.0.5
    • addedInput schema / properties / encoding
      Added value: +{
      +  "description": "Charset override, e.g. CP949; overrides .editorconfig, BOM takes priority",
      +  "type": "string"
      +}
    • addedInput schema / properties / expected_hash
      Added value: +{
      +  "description": "Expected raw-file SHA-256; mismatch rejects the patch",
      +  "type": "string"
      +}
  2. Changed2 schema fields changedv0.9.5
    • addedInput schema / properties / dry_run / type
      Added value: +"boolean"
    • changedInput schema / properties / file_path / description
      Previous value: -"Absolute path to the file to patch"New value: +"File to patch. Relative paths use the configured workspace or MCP client root"
  3. Addedv0.8.7
  4. Removed
  5. Changed1 schema field changedv0.7.12
    • changedOutput schema / (root)
      Previous value: -{
      -  "additionalProperties": false,
      -  "properties": {
      -    "result": {
      -      "type": "string"
      -    }
      -  },
      -  "required": [
      -    "result"
      -  ],
      -  "type": "object"
      -}New value: +null
  6. First observedv0.4.2

TDQS

A3.6/5.0
Behavior4/5

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

With no annotations, the description carries the full burden and does substantial work: it discloses that hunks are parsed and context lines verified, that encoding is preserved, and that per-line endings (mixed CRLF/LF) and absence of a trailing newline are left intact. What it omits is failure behavior — whether a failed context check aborts the whole patch or leaves a partially written file — which matters for a mutation tool.

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-loaded with purpose, then layered detail in descending order of importance: mechanics, encoding, line endings, preview. Every sentence conveys distinct information, though the line-ending sentence is the longest and could be tightened without losing meaning.

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

Completeness3/5

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

For a 6-parameter mutation tool with no annotations and no output schema, the description covers the 'what' well but leaves the agent guessing about atomicity, error/rollback semantics, and what a successful call returns. The safety-relevant gaps are meaningful given nothing else supplies them.

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 coverage is 100%, so all six parameters including the path/file_path alias, expected_hash, and encoding override are already documented in structured fields. The description only reinforces dry_run, which the schema already explains. Baseline 3 is appropriate since the schema does the heavy lifting.

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

Purpose4/5

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

The description opens with a specific verb and resource: 'Applies a unified diff patch to a file', and the following sentence narrows the mechanism to unified-diff semantics (hunk headers, context-line verification). That is enough to separate it from a plain 'write' or 'edit', but it never names the sibling tools (edit, multiedit, write) that an agent would otherwise have to weigh it against.

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

Usage Guidelines3/5

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

The only explicit guidance is 'Use dry_run=true to preview without modifying the file', which is a per-parameter hint rather than tool-selection guidance. There is no statement of when to prefer this over edit/multiedit, or what precondition (e.g. having diff output) must hold. Usage is implied by the phrase 'output of the diff tool' in the schema, not by the description.

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