Edit Document
patch-documentApplies one or more edit operations, in order, to an existing ODocs.co document; people who have it open see each edit in real time. Returns { id, version, ok }, plus a warning when the author name was changed. Two kinds of operation: text-anchored (insert-after / insert-before / replace-text / delete-text), where the server finds the given exact text and resolves it to a position, so no character offsets are needed; and position-based (insert / delete / replace) at an exact character offset. expectedVersion enables conflict detection: if the document changed since that version, the patch is refused with 409 and nothing is applied. Operations are not atomic: they apply one at a time to the live document and are not rolled back. When one fails, the operations before it stay applied (and visible), and the 400 body reports appliedOps: N, the number applied; sending the whole batch again applies those a second time. On an anchor failure the body can also carry nearestMatchOffset and nearestMatchSnippet; they appear only when the anchor matches the document except for whitespace (usually a different newline count), so their absence means the text is not in the document. Anchor matching is exact. LINE BREAKS: each "\n" is a paragraph break, except inside a code block (an insert strictly inside one, or a replace within one, stays in it; at its very start / end a "\n" is a paragraph break). A delete or replace across one JOINS the paragraphs (the first keeps its formatting, except that a range starting at a line start keeps the later line's paragraph); a replace with as many lines as it spans rewrites each line in place, and deleting a whole line with its "\n" joins nothing; identical whole lines at the start / end of find and replace are left out ("2\naf" → "2\nA\nB\naf" only inserts "A\nB\n"). After a join the document can differ from what a position computed before it assumed: list items after a plain paragraph can't join it (one "\n" stays), and a code block's lines joined into a paragraph become hard breaks the plain text doesn't show. While someone has the document open, a patch that would join paragraphs is refused as a whole (409 join_blocked_live_editors, nothing applied); edits within a line and rewrites of whole lines are not affected.
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": {
"id": "<id>",
"operations": "<operations>"
},
"name": "patch-document"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | Document ID | |
| author | No | Name shown on your edits and comments (e.g. "Claude via Greg"), with a robot mark as an agent. Invisible and text-direction characters are removed, line breaks and control characters become spaces, and it is cut to 256 characters. A name that resembles ODocs.co or Octaria (including look-alike spellings) is shown as "Agent (Anonymous)". When any of that happens the result has a `warning` field saying what changed. | |
| operations | Yes | Operations, applied in order. Text-anchored ops (insert-after / insert-before / replace-text / delete-text) name exact text that the server resolves to a position; position-based ops (insert / delete / replace) take character offsets. | |
| expectedVersion | No | The document version from your last read. If the document has changed since, the patch is refused with 409 and nothing is applied (conflict detection). |