Skip to Content

fs_edit

Replace exact text in a text file (up to 4 MiB): old must occur exactly once, or set replace_all. No regular expressions, no fuzzy matching: when old is missing or ambiguous the file is left as it was and the error says how many times it occurs. Written atomically. expect_sha256 (from fs_stat with hash=true, or the sha256 the last write returned) refuses when the file changed since.

Arguments

Over MCP every tool also takes machine: the machine’s name or id, optional when only one machine is online.

NameTypeRequiredMeaning
expect_sha256stringnoRefuse unless the file’s SHA-256 is this.
newstringyesWhat replaces it.
oldstringyesThe exact text to replace, whitespace included. Must occur once, unless replace_all.
pathstringyesText file on the machine. Absolute, or relative to the user’s home folder.
replace_allbooleannoReplace every occurrence instead of exactly one. Default: false.

Result

NameTypeRequiredMeaning
pathstringyes
replacedintegeryesOccurrences replaced.
sha256stringyesSHA-256 of the new content.
sizeintegeryes

Examples

{ "name": "fs_edit", "arguments": { "machine": "<machine>", "path": "<path>", "old": "<old>", "new": "<new>" } }

Limits

The call times out after 60 s (timed_out). Available since version 0.0.1. A refused or failed call returns one of the error codes.