write_file
Apply verified operational-transform updates to an Overleaf document by replacing full text or targeted old/new text edits, optionally recording tracked changes.
Instructions
Replace a text document with a verified OT update that changes only the words that differ, optionally recorded as tracked changes, one per changed group of words; where a changed word touches a comment or tracked change, the update is one edit from the first change to the last instead. Supply the new text through exactly one of content (the whole text), localPath (a local file holding it, never sent through the tool call), or edits: 1 to 100 { oldText, newText } applied in order to the document at revision, each oldText matching exactly once in the text the edits before it left, with whitespace and line endings exact; an empty newText deletes. An oldText that does not match is INVALID_ARGUMENT with details.kind edit_not_found, one that matches more than once edit_ambiguous, each with details.editIndex (0-based), and nothing is sent; otherwise the result is written as content would be. A write that hit a timeout, a lost socket, or an error Overleaf reported on the document after the update was sent is never resent: the live document is observed instead, and recoveredAfterTimeout: true means the intended text was confirmed. An update Overleaf refused as too large is UPDATE_TOO_LARGE with details.outcome not_applied: nothing was stored. On a ShareJS (legacy editor) document, text that adds a character outside the Basic Multilingual Plane, such as an emoji, adds another copy of one the document holds, or changes their order is INVALID_ARGUMENT with details.line (1-based) and nothing is sent, because Overleaf would store it as U+FFFD; editing text on either side of one the document already holds is fine. With writeMode tracked, a write Overleaf applied without recording it as tracked changes by this account is PROTOCOL_UNSUPPORTED with details.kind applied_untracked and details.liveRevision: it is live and not reverted, so read the file before writing again; if another update followed the write before that check, it is REVISION_CONFLICT with details.outcome unknown instead. A review-only collaborator can write only with writeMode tracked, and a read-only one cannot write: either is PERMISSION_DENIED before anything is sent.
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": {
"projectId": "<projectId>",
"filePath": "<filePath>",
"revision": "<revision>"
},
"name": "write_file"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| edits | No | Targeted changes, 1 to 100, applied in order; exactly one of content, localPath, edits | |
| content | No | Complete replacement text; exactly one of content, localPath, edits | |
| filePath | Yes | Project-relative path using forward slashes | |
| revision | Yes | Opaque revision returned by a prior read or write | |
| localPath | No | Local UTF-8 text file holding the complete replacement; exactly one of content, localPath, edits | |
| projectId | Yes | Overleaf project ID | |
| writeMode | No | Use tracked to record inserted and deleted text as Overleaf tracked changes; defaults to untracked | untracked |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| protocol | Yes | ||
| revision | Yes | ||
| writeMode | Yes | ||
| trackChangesActive | Yes | ||
| recoveredAfterTimeout | No |