Edit diagram
edit_diagramEdit a specific page in the current draw.io diagram using ID-based add, update, or delete cell operations, applying changes only when every operation succeeds.
Instructions
Edit a specific page in the current diagram by ID-based operations (update/add/delete cells).
All-or-nothing: if any operation fails, nothing is applied and every failure is listed.
Freshness: the server remembers the last diagram state you have seen, and rejects this call only if the user edited the diagram in the browser since then. You do NOT need to call get_diagram before every edit: a rejected call changes nothing and includes the current XML of the page, so you can rebuild your operations and retry.
Call get_diagram first only when you don't know the current diagram content (cell IDs, structure) — e.g. the diagram wasn't created in this conversation, or you're unsure your memory of it is accurate.
Multi-page targeting:
page_id / page_name / page_index are optional; when all omitted, the FIRST page is targeted
Use list_pages to discover what pages exist
Operations:
add: Add a new cell. Provide cell_id (new unique id within the page) and new_xml. One cell per operation.
update: Replace an existing cell by its id. Provide cell_id and complete new_xml.
delete: Remove a cell by its id. Only cell_id is needed. Its children and connected edges are deleted too, so give only a container's id.
For add/update, new_xml is the complete mxCell in the compact form (a shape with x, y, w, h; an edge with source and target). No XML comments. Every " inside new_xml must be escaped as " in the JSON.
Example - Add a rectangle on the default (first) page: {"operations": [{"operation": "add", "cell_id": "rect-1", "new_xml": "<mxCell id="rect-1" value="Hello" style="rounded=1;" x="100" y="100" w="120" h="60"/>"}]}
Example - Delete a cell on the default page: {"operations": [{"operation": "delete", "cell_id": "rect-1"}]}
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page_id | No | Target a page by its id (as returned by list_pages or add_page). Wins over page_name and page_index when multiple are set. | |
| page_name | No | Target a page by its display name (e.g. "CNN"). Used only when page_id is not set. | |
| operations | Yes | Array of operations to apply | |
| page_index | No | Target a page by its 0-based tab index. Used only when page_id and page_name are not set. | |
| screenshot | No | Also return a PNG of the result so you can check it for overlaps and edges crossing shapes. Needs the preview tab open and in front; adds 2 to 10 s. Default: the DRAWIO_AUTO_SCREENSHOT environment variable. |