fix(mcp-server): review fixes for the shell's commits and export timeout

A write taken in place that leaves the canvas as it is gets no autosave from draw.io, so the marker for its copy stayed armed and ate the user's next paper-size edit: arm it only when the write changed the document. The 15 s export timeout now retires the export's sequence number, so a result POST that answers late no longer restores the document a second time.
This commit is contained in:
dayuan.jiang
2026-10-11 20:56:07 +09:00
parent e533aac6c4
commit 3422b5c55b
2 changed files with 68 additions and 3 deletions
+10 -3
View File
@@ -348,12 +348,17 @@ export function createMcpSync(options: SyncOptions): McpSync {
const loadFromServer = (xml: string, how: "decide" | "full") => {
lastXml = xml
latestXml = xml
const before = canvas.currentXml()
const decision: LoadDecision =
how === "decide"
? decideLoad(canvas.currentXml(), xml, canvas.currentPageId())
? decideLoad(before, xml, canvas.currentPageId())
: { mode: "load" }
canvas.load(xml, decision)
awaitingCommitCopy = decision.mode === "commit"
// draw.io autosaves its copy only when the write changed its
// document: after one that left the canvas as it was, the next
// autosave is the user's
awaitingCommitCopy =
decision.mode === "commit" && !sameDiagram(before, xml)
// currentVersion is the write's version
thumbExport = { stateId, version: currentVersion, xml }
setTimeout(captureThumbnail, 500)
@@ -595,9 +600,11 @@ export function createMcpSync(options: SyncOptions): McpSync {
// The whole export, result delivery included, ends in time: a result
// POST that never answers must not keep the projection on screen
// past the server's deadline (15 s). Only for this export: a later
// one may be running by then.
// one may be running by then. The export is over: its result POST
// answering after this must not restore the document a second time.
setTimeout(() => {
if (pendingMcpExport && seq === mcpExportSeq) {
mcpExportSeq++
pendingMcpExport = null
restoreFromProjection()
}