Skip to main content
Glama

Patch

patch
Destructive

Apply a single-file unified diff to an existing UTF-8 text file all-or-nothing: if any hunk mismatches its context, nothing is written. Use when you already hold a unified diff.

Instructions

Apply a single-file unified diff to one existing UTF-8 text file. Use when you hold a unified diff. Do not use it for one exact snippet; use edit instead. For pattern matches use replace_text; for new files, create. All or nothing: if any hunk mismatches its context, nothing is written; INVALID_INPUT usually names it. Header line numbers may be off. A diff of context lines only writes nothing and records no undo. File lines x diff lines over 10,000,000 fails with TOO_LARGE. Returns path, linesAdded, linesRemoved, size, lineCount, mimeType, kind, modified, resourceUri when linkable, and an undo id for undo (30 minutes) or undoUnavailable; dryRun adds the resulting diff.

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

Input Schema

NameRequiredDescriptionDefault
diffYesSingle-file unified diff, at least one @@ hunk, hunks in file order. Multi-file diffs are rejected; a leading BOM is ignored.
pathYesExisting text file to patch. Overrides the ---/+++ names in diff.
dryRunNoCheck every hunk and return the resulting diff; write nothing. Counts come from the recomputed diff unless it times out.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed3 schema fields changedv2.20.0
    • changedInput schema / properties / diff / description
      Previous value: -"Single-file unified diff to apply (as produced by the diff tool or edit dry-run)"New value: +"Single-file unified diff, at least one @@ hunk, hunks in file order. Multi-file diffs are rejected; a leading BOM is ignored."
    • changedInput schema / properties / dryRun / description
      Previous value: -"Preview the diff without writing (default: false)"New value: +"Check every hunk and return the resulting diff; write nothing. Counts come from the recomputed diff unless it times out."
    • changedInput schema / properties / path / description
      Previous value: -"File to apply the diff to"New value: +"Existing text file to patch. Overrides the ---/+++ names in diff."
  2. Changed1 schema field changedv2.18.2
    • changedInput schema / properties / dryRun / description
      Previous value: -"Preview the result without writing (default: false)"New value: +"Preview the diff without writing (default: false)"
  3. Changed1 schema field changedv2.17.0
    • addedInput schema / properties / diff / maxLength
      Added value: +1048576
  4. Changed1 schema field changedv2.4.1
    • addedInput schema / $schema
      Added value: +"https://json-schema.org/draft/2020-12/schema"
  5. Addedv2.0.0

TDQS

A4.8/5.0
Behavior5/5

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

Goes far beyond the destructive/readOnly/idempotent annotations: discloses all-or-nothing atomicity, that INVALID_INPUT names the mismatched hunk, that header line numbers may be off, that a context-only diff writes nothing and records no undo, the TOO_LARGE threshold, and the 30-minute undo window vs undoUnavailable. This is exactly the mutation-safety context the annotations 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.

Conciseness4/5

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

Front-loaded with purpose then exclusions then failure modes, and every sentence carries operational weight. The final sentence is a long comma-separated return list, slightly dense but still scannable and justified by the absent output schema.

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?

For a destructive three-parameter write tool with no output schema, it covers atomicity, error codes, limits, undo, dryRun, and return shape. An agent has everything needed to call it correctly and recover from failure.

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 coverage is 100%, so baseline is 3, but the description still adds meaning: `path` overriding the ---/+++ names, `dryRun` returning the resulting diff, and the consequence of a diff containing only context lines. Return fields and undo linkage are also enumerated since no output schema exists.

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 with tight scope: 'Apply a single-file unified diff to one existing UTF-8 text file.' It immediately distinguishes itself from `edit`, `replace_text`, and `create`, so an agent can pick it without opening schemas.

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?

Gives an explicit positive condition ('Use when you hold a unified diff') plus three named exclusions routing to alternatives: `edit` for one exact snippet, `replace_text` for pattern matches, `create` for new files. Nothing is left to inference.

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