![]() |
Working with an AI agent: the MCP server | ![]() |
TeXmacs Upsilon can serve its documents to an AI agent, such as Claude Code, Claude Desktop or any other client of the Model Context Protocol (MCP). The command is
texmacs --mcp |
It starts a TeXmacs without a window, which the agent talks to through its standard input and output. You do not type anything in a terminal: the agent starts the program itself, once you have told it, in its configuration, which command to run (see Installing and connecting an agent).
The agent reads and edits your documents by their structure. It asks for the outline of a document (the title, the sections and the labels), reads the sections that it needs, finds text and tags, lists the labels, the references and the citations (with the broken ones), and changes the document by replacing, inserting or deleting a node, or by changing a word or a sentence in a paragraph. Every node it reads has a handle and a hash, and an edit says which node and which version of it it is meant for.
An agent can also edit a .tm file as text. That works for small changes, but the file of TeXmacs is a serialized tree, with its own encoding of accents and symbols, and an editor of text does not know it. Through the server:
the agent reads the outline first and then only the part that matters, instead of the whole file, which saves time and cost on long documents;
an edit names a node, not a position in the text of the file; if you changed that node in the meantime, the edit is refused with the current content, and nothing is lost;
what the agent writes is parsed first and is never saved as a broken file: accents, symbols, formulas and tags stay valid;
if you have the file open in TeXmacs, the agent works on the open document: its edits reach your window at once, you see them appear, and you can accept or reject them (see Working together with the agent);
the content the agent writes is checked by rules which protect your definitions, your links and your files (see What an agent may not do).
The server is part of TeXmacs Upsilon only (see TeXmacs Upsilon features). The developer notes are in the file docs/mcp-server.md of the sources, and the security model is described on the page MCP-security of the wiki of the repository.