Skip to main content
Glama
zix-chen
by zix-chen

Apply patch

apply_patch
Destructive

Stage, validate, and atomically apply V4A patches, with context-based hunks and match quality feedback for safe file edits.

Instructions

Stage, validate, and atomically apply a V4A patch envelope. Each hunk locates itself by its context, so the context must be unique in the file; when it is not, add a scope header (@@ def my_function) naming the enclosing block, or add '*** End of File' to anchor the hunk at the end. A blank context line may be written as "" or as a single space. Matching is graded exact, then ignoring trailing whitespace, then ignoring indentation width, and the grade actually used comes back as match_quality. Success returns each file's revision, total_lines, and changed_ranges. Several updates to one path in one envelope chain in order. Full format reference: docs/tools-and-schemas.md. Example: *** Begin Patch *** Update File: app.py @@ -old +new *** End Patch

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
patchYes
dry_runNo
idempotency_keyNoNames this exact request so a retry after a lost response replays the recorded result (flagged idempotent_replay) instead of doing the work twice. Use a new key for new work: the key is bound to the arguments that first used it, and reusing it with any other argument — including a different dry_run — is refused with IDEMPOTENCY_KEY_REUSED. Only a successful non-dry-run result is recorded, and only the 64 most recently used keys are kept across all tools.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
okYes
cleanNo
errorNo
dry_runNo
summaryNo
removalsNo
warningsNo
additionsNo
affected_filesNo
already_appliedNo
idempotent_replayNo
revision_algorithmNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.1

TDQS

A3.8/5.0
Behavior4/5

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

Annotations already declare destructiveHint=true, idempotentHint=false, and readOnlyHint=false, so the safety bar is lower. The description still adds real behavioral detail beyond the annotations: atomic application, the graded matching order (exact → trailing whitespace → indentation), that the used grade is returned as match_quality, that multiple updates to one path chain in order, and the returned fields. It never explicitly warns that hunks overwrite file content, which is the one gap.

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 the core action, then progressively more specific constraints and a pointer to the full format reference. Dense but each sentence carries a distinct rule about patch authoring. The inline example is justified given the custom patch grammar, though it adds length.

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?

An output schema exists, so the mention of revision/total_lines/changed_ranges is surplus but harmless. The custom V4A format is documented well enough to author a valid patch, idempotency replay and the IDEMPOTENCY_KEY_REUSED error are covered by the schema param text, and a reference doc is cited for full grammar. Only the dry_run semantics and the destructive-overwrite warning are thin.

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 only 33%, so the description must compensate for 'patch' and 'dry_run'. It does so substantively for 'patch': V4A envelope structure, unique-context requirement, scope headers, end-of-file anchoring, blank-line conventions, and an inline example. 'dry_run' is only implied by 'Stage, validate' and is not spelled out, which keeps this below a 5.

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?

Opens with a specific verb triad and resource: 'Stage, validate, and atomically apply a V4A patch envelope.' An agent immediately knows this is the patch-application tool. It does not, however, distinguish itself from the sibling 'apply_changes', leaving the boundary between the two patch-oriented tools to inference.

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?

Usage guidance is framed as format mechanics (add a scope header, use '*** End of File', how blank context lines are written) rather than when-to-use steering. There is no statement of when to reach for apply_patch instead of apply_changes, write_file, or exec_command. A reader can infer it handles multi-hunk patches, but the routing is implicit.

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