diff --git a/packages/mcp-server/src/drawing-guide.ts b/packages/mcp-server/src/drawing-guide.ts index ac721e47..614cf0f8 100644 --- a/packages/mcp-server/src/drawing-guide.ts +++ b/packages/mcp-server/src/drawing-guide.ts @@ -29,7 +29,7 @@ export const DRAWING_GUIDE = `# Draw.io drawing guide - After a successful create_new_diagram or edit_diagram call, do not describe the diagram; the user sees it in the preview. One short sentence at most. - For artistic requests (a cat, a logo, a scene), compose the picture from standard shapes and connectors while keeping it clear. - To clear the canvas to one blank page, call create_new_diagram with only the two root cells ; the previous diagram stays in History. -- The preview page has History (it saves a snapshot before every AI change and can restore any of the last 20 versions) and Download. You can make changes freely; nothing is lost. +- The preview keeps the last 20 versions (a snapshot before every AI change) and can restore any of them. You can make changes freely; nothing is lost. - If the user asks to undo or go back, call restore_version instead of re-sending the earlier XML from memory. ## The XML you send diff --git a/packages/mcp-server/src/http-server.ts b/packages/mcp-server/src/http-server.ts index 4464c8cf..f0b062de 100644 --- a/packages/mcp-server/src/http-server.ts +++ b/packages/mcp-server/src/http-server.ts @@ -110,15 +110,21 @@ const PACKAGE_VERSION: string = JSON.parse( ).version /** - * The preview page start_session opens: the classic page (src/preview), or - * the canvas shell with DRAWIO_PREVIEW_UI=shell. The shell becomes the - * default once it does everything the classic page does. + * The preview page start_session opens: the canvas shell (shell/, the web + * app's canvas), or with DRAWIO_PREVIEW_UI=classic the classic page + * (src/preview), kept for one more release. */ export type PreviewUi = "classic" | "shell" -export const PREVIEW_UI: PreviewUi = - (process.env.DRAWIO_PREVIEW_UI ?? "").toLowerCase() === "shell" - ? "shell" - : "classic" + +export function previewUiFromEnv( + env: NodeJS.ProcessEnv = process.env, +): PreviewUi { + return (env.DRAWIO_PREVIEW_UI ?? "").toLowerCase() === "classic" + ? "classic" + : "shell" +} + +export const PREVIEW_UI: PreviewUi = previewUiFromEnv() export function previewUrl( port: number, diff --git a/packages/mcp-server/src/index.ts b/packages/mcp-server/src/index.ts index d5ffafdc..1cdd09be 100644 --- a/packages/mcp-server/src/index.ts +++ b/packages/mcp-server/src/index.ts @@ -1268,7 +1268,7 @@ server.registerTool( content: [ { type: "text", - text: "The classic preview page cannot read the selection; start the server with DRAWIO_PREVIEW_UI=shell. Ask the user which shapes they mean, or call get_diagram.", + text: "The classic preview page (DRAWIO_PREVIEW_UI=classic) cannot read the selection. Ask the user which shapes they mean, or call get_diagram.", }, ], } diff --git a/packages/mcp-server/tests/e2e/shell.spec.ts b/packages/mcp-server/tests/e2e/shell.spec.ts index d4558f26..d14bad8a 100644 --- a/packages/mcp-server/tests/e2e/shell.spec.ts +++ b/packages/mcp-server/tests/e2e/shell.spec.ts @@ -1,8 +1,8 @@ /** - * The canvas shell as start_session opens it with DRAWIO_PREVIEW_UI=shell: - * the built server (dist/index.js, or the copy MCP_SERVER_ENTRY names: CI - * installs the packed tarball in an empty directory) runs over stdio as an - * MCP client would start it, and headless Chromium opens the URL it returns. + * The canvas shell as start_session opens it by default: the built server + * (dist/index.js, or the copy MCP_SERVER_ENTRY names: CI installs the packed + * tarball in an empty directory) runs over stdio as an MCP client would + * start it, and headless Chromium opens the URL it returns. */ import { mkdtempSync, readFileSync, rmSync } from "node:fs" import { tmpdir } from "node:os" @@ -26,7 +26,6 @@ test.beforeAll(async () => { env: { ...process.env, DRAWIO_DATA_DIR: dataDir, - DRAWIO_PREVIEW_UI: "shell", // Away from the web app's dev server and other test runs PORT: String(6100 + Math.floor(Math.random() * 400)), BROWSER: "none", diff --git a/packages/mcp-server/tests/http-server.test.ts b/packages/mcp-server/tests/http-server.test.ts index 1ec04470..0620288b 100644 --- a/packages/mcp-server/tests/http-server.test.ts +++ b/packages/mcp-server/tests/http-server.test.ts @@ -27,6 +27,7 @@ import { keepInHistory, onSessionRecreate, onStateChange, + previewUiFromEnv, previewUrl, requestExport, requestSelection, @@ -928,7 +929,15 @@ describe("canvas shell page", () => { } }) - it("is what start_session opens with DRAWIO_PREVIEW_UI=shell", () => { + it("is what start_session opens, unless DRAWIO_PREVIEW_UI=classic", () => { + expect(previewUiFromEnv({})).toBe("shell") + expect(previewUiFromEnv({ DRAWIO_PREVIEW_UI: "shell" })).toBe("shell") + expect(previewUiFromEnv({ DRAWIO_PREVIEW_UI: "classic" })).toBe( + "classic", + ) + expect(previewUiFromEnv({ DRAWIO_PREVIEW_UI: "Classic" })).toBe( + "classic", + ) expect(previewUrl(6002, "mcp-x", "shell")).toBe( "http://localhost:6002/shell/?mcp=mcp-x", ) diff --git a/packages/mcp-server/tests/server-wiring.test.ts b/packages/mcp-server/tests/server-wiring.test.ts index c8dbeae1..7f7efe98 100644 --- a/packages/mcp-server/tests/server-wiring.test.ts +++ b/packages/mcp-server/tests/server-wiring.test.ts @@ -95,9 +95,9 @@ beforeAll(async () => { ...process.env, DRAWIO_DATA_DIR: dataDir, // For the session tests at the end: no browser window, the - // canvas shell as the preview, a port away from other servers + // default preview (the canvas shell), a port away from other + // servers BROWSER: "none", - DRAWIO_PREVIEW_UI: "shell", PORT: String(6500 + Math.floor(Math.random() * 400)), }, }) as ChildProcessWithoutNullStreams