apply_patch_workspace_file
Apply search/replace edits to a workspace file using hunks or unified diff, with whitespace-tolerant matching and optional dry-run.
Instructions
Apply one or more search/replace hunks to an existing file. Preferred arg: hunks=[{old_string,new_string,replace_all?,exact?}]. Aliases accepted: edits/changes/replacements, or patch as the same array, or a small unified-diff string with context/-/+ lines. Each old_string must match the current file exactly once unless replace_all is true. If an exact match fails purely on whitespace/indentation (tabs vs spaces, trailing space) AND the snippet anchors to exactly one place, the patch is still applied — new_string is reindented to the file's real style and the response notes whitespace_adjusted. Exact matches also restyle new_string indent chars to the file's tab/space convention. Pass exact=true on a hunk to disable tolerant re-anchoring. Preserves untouched content verbatim. Returns a unified diff and revert_token.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Path relative to repo root | |
| repo | No | Repository name (optional; defaults to current MCP workspace) | |
| hunks | No | Array of {old_string, new_string, replace_all?:bool, exact?:bool}. Applied in order. Aliases: edits, changes, replacements. | |
| patch | No | Optional alias: same as hunks (JSON array) OR a small unified-diff string with context/-/+ lines | |
| dry_run | No | If true, do not write; just return the diff that would be produced |