Skip to main content
Glama

Apply Patch

apply_patch
Destructive

Apply a unified diff patch to files for automated code changes. Validate patches with dry run before committing to prevent errors. Supports fuzzy matching and line-ending conversion for reliable patching.

Instructions

Apply a unified diff patch to one or more files. Single-file: throws on failure. Multi-file: best-effort per file with results[]. Workflow: diff_filesapply_patch(dryRun:true)apply_patch. On failure, regenerate the patch from current file content.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to file to patch
patchYesUnified diff with @@ hunk headers. Generate with `diff_files`.
fuzzFactorNoMaximum fuzzy mismatches per hunk
autoConvertLineEndingsNoAuto-convert line endings to match target file
dryRunNoValidate patch without writing. Check `applied` before committing.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
okYes
pathNo
appliedNo
hunksAppliedNoHunks applied
linesAddedNoLines added
linesRemovedNoLines removed
resultsNoPer-file results for multi-file patches
Behavior5/5

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

Adds context beyond annotations: single-file throws, multi-file best-effort with results array, recommends regenerating patch on failure. No contradiction.

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

Conciseness5/5

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

Three sentences, front-loaded purpose, each sentence adds essential behavioral info or workflow. No redundancy.

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?

Covers purpose, workflow, failure modes, and suggestions. Output schema present for return values. Complete for a patch tool.

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%, description adds value for 'patch' by specifying generation with diff_files, but other params rely on schema. Baseline 3, plus credit for workflow context.

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?

Clearly states the tool applies a unified diff patch to files. Distinguishes single-file vs multi-file behavior and aligns with sibling tools like diff_files.

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?

Provides explicit workflow: diff_files → apply_patch(dryRun:true) → apply_patch. Explains failure modes per file type. No explicit when-not-to-use vs edit, but workflow is strong.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/j0hanz/filesystem-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server