fix(mcp-server): review fixes for the preview URL and the theme menu

The stalled-tab note names the page start_session opened (the shell
with DRAWIO_PREVIEW_UI=shell) instead of the classic page. With the
shell not built, start_session opens the classic page and the server
says so at startup, as it does for a missing dist/drawio. BROWSER=none
skips the system browser, as Vite and CRA dev servers do: the e2e tests
set it. Without a fixed DRAWIO_UI, the shell's draw.io URL carries
themes=1 so Extras > Theme is offered, as on the classic page.
This commit is contained in:
dayuan.jiang
2026-10-11 20:56:07 +09:00
parent b6bd032c2c
commit 3ef14318f9
6 changed files with 45 additions and 4 deletions
+8 -1
View File
@@ -122,7 +122,9 @@ export function previewUrl(
sessionId: string,
ui: PreviewUi = PREVIEW_UI,
): string {
const path = ui === "shell" ? "/shell/" : ""
// The classic page stands in while the shell is not built (a run from
// the sources), as embed.diagrams.net does for a missing dist/drawio
const path = ui === "shell" && shellDir !== null ? "/shell/" : ""
return `http://localhost:${port}${path}?mcp=${sessionId}`
}
@@ -430,6 +432,11 @@ export function startHttpServer(port = 6002): Promise<number> {
"No bundled draw.io (dist/drawio missing); the preview loads it from embed.diagrams.net",
)
}
if (PREVIEW_UI === "shell" && shellDir === null) {
log.warn(
"The canvas shell is not built (dist/shell missing); start_session opens the classic page",
)
}
resolve(port)
})
})
+4 -3
View File
@@ -382,9 +382,10 @@ registerWriteTool(
lastSeenXml: "",
}
// Open browser
// Open the browser. BROWSER=none (the convention of CRA and Vite
// dev servers) skips it: the e2e tests and headless hosts set it
const browserUrl = previewUrl(port, sessionId)
await open(browserUrl)
if (process.env.BROWSER !== "none") await open(browserUrl)
// A saved diagram comes back from its file. lastSeenXml stays
// empty, so edit_diagram asks for get_diagram first.
@@ -1287,7 +1288,7 @@ function previewStalled(sessionId: string): boolean {
* already succeeded must not run again, so it points to screenshot_diagram.
*/
function previewStalledNote(sessionId: string, next = "then retry") {
return `The preview tab is not responding (browsers pause background tabs). Ask the user to bring the preview tab to the front (http://localhost:${getServerPort()}?mcp=${sessionId}), ${next}.`
return `The preview tab is not responding (browsers pause background tabs). Ask the user to bring the preview tab to the front (${previewUrl(getServerPort(), sessionId)}), ${next}.`
}
function previewStalledError(sessionId: string) {