mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-10-11 20:19:51 +08:00
feat(mcp-server): the canvas shell is the default preview, the classic page behind DRAWIO_PREVIEW_UI=classic
This commit is contained in:
@@ -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 <mxCell id="0"/><mxCell id="1" parent="0"/>; 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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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.",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user