mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-10-12 04:29:51 +08:00
fix(mcp-server): review fixes for get_selection
Server (src/http-server.ts, src/index.ts, src/selection.ts, src/new-diagram.ts): - overlapping get_selection calls take turns (readSelection, one slot per session as the export slot) instead of replacing each other's request, which left one of them with a false "tab not in front" timeout - an answer is taken only while a request is pending (both ids undefined compared equal) - the tool sees the page start_session actually opens: with dist/shell missing the classic page is in use, which never answers, so the tool says so instead of timing out - the result lists at most 100 cells and counts the rest: a whole large diagram selected would fill the model's context - every <diagram> the model sends without an id gets one, so the page id the shell reports exists in the server's document Shell (shell/mcp-sync-core.ts, shell/use-mcp-sync.ts, contexts/diagram-context.tsx, lib/drawio/editor-bridge.ts): - an answer whose POST failed is sent again at the next poll - no answer while a full load has yet to reach the editor: it still shows the previous document, whose cells and pages the answer would name - a hidden tab (the same session open twice) answers a poll later, so the tab in front answers first; alone, it still answers within the timeout - a cell's container is reported by the model's isLayer, not by comparing with the default parent, which is the group the user entered
This commit is contained in:
@@ -610,7 +610,6 @@ export function readSelectionDetails(): SelectionAnswer | null {
|
||||
const g = graph()
|
||||
if (!g) return null
|
||||
const page = ui?.currentPage
|
||||
const defaultParent = g.getDefaultParent?.()
|
||||
const cells = (g.getSelectionCells() as any[])
|
||||
.filter((cell) => cell?.id)
|
||||
.map((cell) => {
|
||||
@@ -635,8 +634,11 @@ export function readSelectionDetails(): SelectionAnswer | null {
|
||||
}
|
||||
}
|
||||
}
|
||||
// The container the cell is in; a layer is none (and the
|
||||
// default parent is the group the user entered, if any, so it
|
||||
// cannot tell the two apart)
|
||||
const parent = g.model.getParent(cell)
|
||||
if (parent?.id && parent !== defaultParent) {
|
||||
if (parent?.id && !g.model.isLayer(parent)) {
|
||||
info.parent = String(parent.id)
|
||||
}
|
||||
return info
|
||||
|
||||
Reference in New Issue
Block a user