Together AI assistants (MCP)
AI assistants
@rebodocs/mcp gives an assistant the operations a person has in the editor, as 51 tools of the Model Context Protocol. “Fill this contract” or “turn this list into a table” is done on the real document, its layout and formatting intact, not on a copy of its text.
Which way?
The same tools reach a document three ways. The first two run a server on your machine; the third puts Claude in your own application.
Files, from your assistant
- Claude Desktop, Code, Cursor
- rebodocs-mcp, on your machine
- contract.docx
The assistant opens a .docx, changes it in memory and saves it as DOCX, PDF or Markdown. No editor needs to be open.
Set it up ↓The editor someone has open
- Your assistant
- rebodocs-mcp, on your machine
- the editor in the browser
The person switches on “AI” in the status bar, and the assistant works on what they are looking at: each change a step to undo, the view going to it.
Set it up ↓Claude in your application
- A chat in your page
- your backend
- the Claude API
For everyone who uses your application, with your API key. The page holds the conversation and runs the tools on the editor; the server keeps nothing.
Add it ↓Be the assistant
The sample document in the real editor, and the tools an assistant calls, run on it by the same code the server and the chat run. What comes back is word for word what the assistant reads.
Opening the editor…
Paragraphs go by number, as read_document shows them, and every tool that changes text answers with what it did: the assistant does not have to read the whole document again after each step. A wrong argument comes back as a plain sentence, for it to correct itself. Of the 45 tools of a document, 35 change it and the rest read. The descriptions of the tools are what the server tells an assistant, in English.
Set it up
For the first two ways: the server starts when your assistant does. Choose yours, and copy what it needs.
Your assistant
Put it in
~/Library/Application Support/Claude/claude_desktop_config.json (on Windows, %APPDATA%\Claude\claude_desktop_config.json). Restart it after changing it.
{
"mcpServers": {
"rebodocs": {
"command": "npx",
"args": [
"-y",
"@rebodocs/mcp",
"--root",
"/Users/you/Documents/contracts"
]
}
}
}It comes from npm, with the engine as its dependency: there is nothing to clone. Then ask the assistant: “Open /Users/you/Documents/contracts/lease.docx and fill it for Ana López”.
Options of the server
- --root DIR
- A folder files may be read from and written to; several can be given. Give one: without, anywhere on the machine.
- --fonts DIR
- A folder to look for fonts in before the system’s, to lay out and make PDFs.
- --port N
- Where the editor in the browser connects. 7411 by default, or REBODOCS_MCP_PORT.
- --no-editor
- Files only: do not listen for an editor.
- --origin URL
- A page allowed to connect, besides localhost.
- --host ADDR
- To listen for editors, and with --http for clients, on other machines. A --token of 12 characters or more is then required, or REBODOCS_MCP_TOKEN.
- --http N
- Listen for assistants over HTTP at http://127.0.0.1:N/mcp (Streamable HTTP), each with a session of its own, instead of over standard input and output. With --token, a client gives it as “Authorization: Bearer”.
- --timeout S
- How many seconds to wait for the editor to answer a tool: 30 by default.
- --editor-url URL
- The address of your editor, told to the assistant when no editor is connected, so it can say where to open it.
Over HTTP
For a client that connects to a server instead of starting one, or one on another machine: with --http the server listens at /mcp (the protocol’s Streamable HTTP), and each client has a session of its own, with its own open files. The editors in the browser are the same for all of them.
# The server, listening for assistants at http://127.0.0.1:7412/mcp
npx -y @rebodocs/mcp --root /path/to/documents --http 7412
# Claude Code, pointed at it
claude mcp add --transport http rebodocs http://127.0.0.1:7412/mcp
# From another machine: --host and a --token of 12 characters or more,
# which the client gives as "Authorization: Bearer <token>"
npx -y @rebodocs/mcp --root /srv/documents --http 7412 --host 0.0.0.0 --token "$REBODOCS_MCP_TOKEN"The button, in your own editor
The editor connects only when the person switches “AI” on, and does not remember it between reloads. Each thing the assistant does is one step to undo.
// The “AI” button, for a server on the person's machine
<DocsEditor features={{ assistant: true }} />
// …or one on another machine, started with --host and --token
<DocsEditor features={{ assistant: { url: 'http://10.0.0.5:7411', token } }} />What an assistant may touch
An assistant does what its tools let it, where the server lets it. These are the limits, and who sets each.
Only the folders you name
With --root, a path outside those folders is refused, and the assistant is told why. Without it, the server may use any file the machine lets it.
Nothing written until it saves
An opened file is changed in memory. save_document writes it, and never over a file that is there unless the assistant says overwrite; new_document will not take a path that exists.
Only this machine, unless you say
The server listens on 127.0.0.1. A page connects from localhost, or from an --origin you name. To listen for other machines (--host) it will not start without a --token of 12 characters or more.
The person switches it on
The editor connects only when “AI” is switched on, and not again after a reload. Each change is a step to undo, and the view goes to it.
Suggestions, not edits
With track_changes on, what the tools change stays marked, signed “Assistant”, for the person to accept or reject.
A way back
On a file, undo goes back from the last changes, up to 50; in the editor, each change is a step the person undoes. edit_document makes all its edits or none.
The client knows what only reads
Each tool says whether it only reads, whether doing it again changes more, and whether it can lose work: only save_document and close_document can. A client can let the reading ones run without asking.
In your application: who, and how often
assistantRoute asks allow who may use it and gives each user perMinute steps, told apart by key; the key stays on your server, and the conversation in the page.
Every tool
What the server tells the assistant about each, read from the source of @rebodocs/mcp when this page was built. “Try it” loads one in the editor above.
Files
The server’s own: a chat in your application has no files, so it has none of these.
Opens a Word file (.docx) to read it and change it. It is kept in memory: nothing is written until save_document. Gives its overview.
Starts an empty document, to write in and save. Gives it the path it will be saved to.
Writes a document to a file: Word (.docx), PDF (.pdf) or Markdown (.md), by the ending of the path. A DOCX that was opened keeps everything that was not changed exactly as it was. It does not write over a file that is there unless "overwrite" is true.
Undoes the last changes the tools made to a file that is open, one at a time or several: the way back from a mistake without opening the file again and losing the rest. Up to 50 changes. In the editor in the browser, each change is a step the person undoes there.
The documents that can be worked on now: the files that are open, with whether each has changes not saved, and whether an editor is connected.
Forgets a file that is open, with any changes that were not saved.
Reading
A summary of the document: how long it is, its headings with the paragraph each is at, its template variables, its notes and its paragraph styles. Start here.
The text of the document, one paragraph a line, each with its number in brackets and, in parentheses, its style and its table cell when it has them. A long document comes in parts: ask for the next with "from".
How paragraphs look: for each, its style, alignment, indents, the room before and after it and its line spacing; then each stretch of its text that looks different, with its font, its size and whether it is bold, italic, underlined or coloured. Read it before rewriting or adding text that has to look like what is there.
How the document falls on its pages, as it prints: for each page, the paragraphs on it, how it starts and ends and how much room is left at its foot; and what may want mending: a paragraph cut by the end of a page, a heading left at the foot of one with its text on the next, a page with only a line or two, a table that runs over pages, a page with nothing on it. Read it after changes that move text, before a document goes out.
Every place a text is found, with the paragraph it is in and the words around it.
The links of the document: the text of each, where it goes and its paragraph.
The notes of the document: the id of each, who wrote it, the text it is about and what it says.
The template variables of the document, written between double braces: the name of each, how many times it is used and the formats it is given (capitals, a date, money…).
What changed between this document and another version of it in a .docx file ("path"): the paragraphs put in, taken out and changed, of the text and of its headers, footers, notes at the foot of the page and text boxes, and the notes on the text (as add_note makes), with what was taken out as [-…-] and what was put in as {+…+}. Tracked changes are compared as if accepted, as Word does. By default the file is the earlier version; with "file_is" "later", it is the later one.
Text
Puts a text in place of another, in the formatting of what was there: its font, its size and its marks. The text to find has to be inside one paragraph. An empty "replace" deletes it. To write a whole paragraph anew, as in a translation, rewrite_paragraph keeps more of its look.
Writes the whole text of a paragraph anew, as to translate it or say it otherwise, and keeps how it looks: its style, alignment, indents and spacing, and the font, size and colour most of its text has. Words that were set apart (bold, italic…) are kept so by giving the text in "segments". A paragraph with a picture is changed with replace_text instead.
Writes new paragraphs after a paragraph. Each has its text and, when wanted, a style (a heading, for one) or a list. With "like_paragraph" a new one looks like a paragraph that is there: its alignment, indents, spacing, list, and the font, size and colour of most of its text. Text between double braces, like {{cliente}}, is a template variable.
Deletes whole paragraphs, from one to another. Not for the paragraphs of a table.
Makes several changes in one go, each as the tool it names would make it, and all of them or none. Every paragraph number in them is the one read_document showed before the first edit: the numbers do not move as the edits before insert or delete paragraphs, so there is no need to read again between them. A text to find is looked for as the document is when its edit comes. Each edit is an object with "tool" (replace_text, rewrite_paragraph, insert_paragraphs, delete_paragraphs, set_style, set_list, format_text, format_paragraphs, set_link, add_note, insert_page_break, move_section, set_cell_text, renumber_clauses) and the arguments of that tool beside it. The text of the document only: for a header or a footer, use each tool alone with "area".
Moves a heading and everything under it, down to the next heading of its level or above (a clause with its text, a chapter with its clauses), to another place, as dragging it in the outline of the editor does. The paragraphs keep their look, their notes and their pictures. After it, renumber_clauses puts the numbers of the headings in order.
Puts in order the numbers written at the start of the headings of clauses, after one was put in, taken out or moved: "Primera.", "Segunda."… in words, "CLÁUSULA 3.", or "IV.", each kept as it is written (its capitals, "Primera" or "Primero", "Décima Primera" or "Undécima"). The headings of one series are those that begin the same way and have the same style; the longest is renumbered, or the one of "paragraph". It says the places of the text that name a clause by its number ("según la cláusula Tercera"), for you to check: it does not change them.
Gives paragraphs a paragraph style: a heading, a title, the normal text. get_overview lists the styles of the document.
Makes paragraphs the items of a list with bullets or with numbers, or takes them out of the list they are in.
Makes a text a link to a web page, a mail address or a telephone; or, with an empty "url", takes its link away.
Formatting
Changes how a text looks: its font, its size, bold, italic, underlined, struck through, its colour or the highlight behind it. The text is one found by "find", or whole paragraphs, from "from" to "to". Give only what is to change.
Changes how paragraphs sit on the page: their alignment, indents, the room before and after them, their line spacing, their tab stops, and whether they keep with the next one. Give only what is to change.
Comments and tracked changes
Puts a note on a text: a comment in the margin, as in Word, that does not change the document. The way to review a document, or to ask about something in it.
Takes a note away; the text it was about stays.
Switches tracked changes on or off, as Word's "Track changes". While on, every change made to the text, by any tool, stays marked for a person to accept or reject: what was put in as {+…+} and what was taken out as [-…-] in read_document.
The tracked changes of the document, numbered: who made each, whether it put text in, took it out, moved it or changed its formatting, the text, and the paragraph it is in. Text one person put in and another took out is two changes. accept_changes and reject_changes take these numbers.
Accepts tracked changes: what was put in stays, unmarked, and what was taken out goes. With "changes", the ones of those numbers in list_changes; with "author", all of that person's; without either, all of them. A move is accepted whole.
Rejects tracked changes: what was put in goes, and what was taken out comes back. With "changes", the ones of those numbers in list_changes; with "author", all of that person's; without either, all of them. A move is rejected whole.
Templates
Puts a value in place of each template variable that is given one, everywhere in the document (its headers, footers, notes and text boxes too), in the format the variable asks for, and writes out each block given one: {{#name}} … {{/name}} is repeated for each item of a list (a row of a table, paragraphs, or text), kept for true and taken out for false; {{^name}} … {{/name}} the other way round. Dates go as YYYY-MM-DD and numbers plain (1234.5): the format writes them out. Variables and blocks with no value stay as they are.
Tables and pictures
Puts in a table after a paragraph, with the text of each cell. Every row must have the same number of cells.
Changes the shape or the look of a table that is there. "paragraph" is any paragraph of the cell to act on (read_document says which cell each is in). Actions: insert_row_above, insert_row_below, insert_column_left, insert_column_right, delete_row, delete_column, merge_cells (from "paragraph" to "to_paragraph"), split_cell (undoes a merge), set_column_widths (with "widths_cm", one for each column), set_row_height (with "height_cm", 0 for as tall as it holds, and "exact"), header_row_on and header_row_off (the rows down to this one repeat at the top of each page), align_cells_top, align_cells_center, align_cells_bottom, text_level, text_up and text_down (the text of the cells set level, or vertically to read from the bottom up or from the top down; its lines are as long as the row is tall), shade_cells (with "shade"), cell_lines (with "line_style", "line_width_pt" and "line_color"; "line_style" none takes them away), show_borders, hide_borders (the whole table), keep_together (the whole table on one page, as a block of signatures should be: no row is cut, and each row stays with the next), allow_split (undoes it) and delete_table. The actions on cells take "to_paragraph" for several. The text of a cell is changed with replace_text and insert_paragraphs.
Writes the text of a cell of a table, by its table, row and cell, as read_document shows them ("table 1, row 2, cell 3"): what the cell had goes, empty or not, and the text takes the look most of it had. A new line in "text" starts another paragraph in the cell. The way to fill the cells of a row just put in.
Puts in a block of signatures after a paragraph: side by side, each with its title (such as ASESOR and CLIENTE), a line to sign on and the name under it.
Puts a picture from a file (PNG, JPEG or GIF) in a paragraph of its own after a paragraph. It goes at its own size, or as wide as the text when it is wider, unless "width_cm" says otherwise.
Changes a picture that is in the document: "resize" it (with "width_cm"; its height follows), "move" it to a paragraph of its own after another (with "after_paragraph"), "align" the paragraph it is in (with "align"), "describe" it for whoever cannot see it (with "description", what a screen reader says; empty takes it away), or "delete" it. read_document shows a picture as [image], or [image: its description].
Pages and columns
Changes the size of the paper, its orientation, or its margins; and, for one section of a document of several, whether it has a header and footer of its own and whether its first page has its own. Give only what is to change. Without "section", the page of every section changes.
Gives the document a letterhead: a picture from a file (PNG, JPEG or GIF), stretched over the whole page behind the text of every page, in place of the one it had. For a PNG, the top and bottom margins grow to clear what it prints there. With "remove", takes it away; the rest of the header stays. get_overview says whether the document has one.
Sets text in columns, as a newsletter: one column, two, three, with a line between them or not. With "from" and "to" only those paragraphs go in columns, in a section of their own on the same page; with "paragraph" alone, the whole section that paragraph is in.
Makes the text from a place start at the top of the next column, in a section set in columns: before a text found with "find", or at the start of a paragraph.
Puts the number of the page in the header or the footer of every page, moves it, changes how it reads, or takes it away.
Makes the text after a paragraph start on a new page.
Puts a note at the foot of the page: its number goes in the text right after a text found with "find" (or at the end of paragraph "at_paragraph"), and the note says "text". Notes are numbered by where they are in the text.
Puts a note at the end of the document, after its text (or at the end of its section, when the document puts them there): its number (i, ii, iii) goes in the text right after a text found with "find" (or at the end of paragraph "at_paragraph"), and the note says "text". Notes at the end are numbered by where they are in the text, apart from those at the foot of the page.
Puts a text box in: a box with a thin black line, anchored to a paragraph (at the end of "after_paragraph"; 1 when left out), at the left of the column, with the text of that paragraph going round it. It is as tall as its text. Its text is "text"; each line of it a paragraph. Change it later with area "textbox".
Puts in a table of contents after a paragraph: the headings of the document, each with its page and a link to it. A document has one.
Writes the table of contents again from the headings and the pages the document has now. Do it after changing headings, or text that moves them to other pages.
Keeping the look
An assistant sees the text by default, not how it looks. read_formatting tells it, paragraph by paragraph: style, alignment, indents, spacing, and each stretch with its font, size and marks.
Writes a paragraph anew, as in a translation, keeping its alignment, indents and spacing, and the font, size and colour most of its text had. Given in segments, the words that were bold or italic stay so.
With like_paragraph, new paragraphs look like one that is there.
Keeps the look of the text it replaces.
See it in the editor above: “How it looks” reads paragraph 4, “Translate, keeping the bold” writes paragraph 10 in Spanish with its bold and red words still so, and “Add one like it” puts in a bullet that matches the ones around it. The chat in your application tells Claude so before every conversation: read the formatting before rewriting, and change fonts, sizes or spacing only when asked.
Working on a contract
Contracts have numbered clauses, tables of amounts and signatures that must not be cut by a page. These tools are for that, besides reading and writing text.
Several changes in one call, all or none: replace, rewrite, insert, delete, style, format, notes, moving a clause, a cell. Every paragraph number in them is the one of a single reading, so the assistant does not read again after each insertion.
Puts in order the numbers written at the start of the headings, after a clause was put in, taken out or moved: “Primera.”, “CLÁUSULA 3.” or “IV.”, each kept as written. It lists the places of the text that name a clause by a number that changed, without changing them.
Moves a heading with everything under it, as dragging it in the outline does: the clause keeps its look and its notes.
Writes a cell by its table, row and cell, empty or not: the way to fill a row just put in.
How the document falls on its pages, in words: a paragraph cut by a page, a heading left at the foot of one, a last page of a line, a table over two pages.
With keep_together, a block of signatures stays whole on one page, and goes to the next only when it does not fit; format_paragraphs keeps a paragraph whole with keep_lines_together, or with the next with keep_with_next.
“Several at once” and “How it falls on pages”, in the editor above, run the first and the last of them on the sample document.
In your own application
The “AI” button reaches a server on the person’s machine. To have Claude in your application, for anyone who uses it, the page talks to your backend, and your backend to the Claude API.
- 1
The person asks
createAssistantChat sends the conversation so far to POST /api/assistant, on your server.
- 2
Your route asks Claude
assistantRoute (or assistantHandler, in Next.js) checks who may ask (allow) and how often (perMinute), and sends the conversation to Claude with the tools of the document. The answer comes back as Claude writes it: a line of JSON for each piece of text and each tool it asks for, and the whole answer at the end.
- 3
The page runs the tools
Each tool Claude asks for is run on the editor the person has open, as a step they can undo; in a shared room, the others see it as the person’s own change.
- 4
…until it is done
The results go back to Claude in the next step, until it has nothing more to do: 40 steps at most for one question (maxSteps). The conversation lives in the page; the server keeps nothing.
On your server
npm install @rebodocs/mcp, and a route that takes the conversation to Claude with your key. It asks Claude Opus 5.5 at medium effort unless given another model or effort, and gives each user 40 steps a minute (perMinute). Without key, a user is the address the request comes from, which behind a proxy is the same for everyone: give it the user of your session. context tells Claude what your application knows, after its instructions. toolSearch: true has Claude search for the tools of tables, pages and reviewing when it needs one, instead of reading all of them on every step.
import { assistantHandler, assistantRoute } from '@rebodocs/mcp/claude';
// ANTHROPIC_API_KEY in the environment.
// Next.js: app/api/assistant/route.ts
export const POST = assistantHandler({
allow: async (request) => !!(await sessionOf(request)),
key: async (request) => (await sessionOf(request))!.userId, // perMinute counts per user
context: async (request) => `The adviser is ${(await sessionOf(request))!.name}.`,
});
// A server of Node's own: answers POST /api/assistant.
const assistant = assistantRoute({ allow: (request) => isSignedIn(request) });
http.createServer(async (request, response) => {
if (await assistant(request, response)) return;
// …the rest of your server
});In the page
import { createAssistantChat } from '@rebodocs/react';
const chat = createAssistantChat(handle.editor, { onChange: redraw });
await chat.send('Translate the document into English, keeping its format.');
chat.entries; // what to show: the person, Claude, each tool it used
chat.busy; // true while it works; chat.stop() ends it after this stepYour key, your bill. Whoever runs the server pays for what open pages ask. Give allow your session check, and keep perMinute low. To see it working, npm run assistant runs the demo.
What to know
- Paragraph numbers move after an insertion or a deletion. edit_document makes several edits in the numbers of one reading; after it, or after one tool alone, an assistant reads again before using an old number.
- Lengths in the tools are in centimetres and points, as people say them; the editor’s own API is in points.
- While changes are tracked, what the tools change is tracked too, signed “Assistant”.
- A chat in your application cannot insert a picture or a letterhead from a path, or compare with a file: those need the server’s disk.
- read_pages says how the text falls on the pages in words; there is no picture of a page for an assistant to look at.
- A client that cancels a call stops the server waiting for the editor; a change the editor already made stays, as a step to undo.
- In a shared room, an assistant works through the editor of the person who asked: the others see its changes as that person’s, but not the conversation.