Skip to content

Commit 68cf651

Browse files
ochafikclaude
andcommitted
fix: add annotations before awaiting tile load in ontoolinput
Annotations were added after `await waitForTilesLoaded()` which blocks up to 10 seconds. If the host doesn't forward `_meta.initialAnnotations` to ontoolresult, annotations wouldn't appear until tiles finish loading. Now annotations are added immediately after camera positioning, before the tile-loading await. Also adds field validation in ontoolinputpartial to prevent creating broken entities from truncated streaming data. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f9cadb3 commit 68cf651

1 file changed

Lines changed: 26 additions & 7 deletions

File tree

examples/map-server/src/mcp-app.ts

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,6 +1510,22 @@ app.ontoolinputpartial = (params) => {
15101510
const safe = args.annotations.slice(0, -1);
15111511
for (const ann of safe) {
15121512
if (!ann.id || !ann.type) continue;
1513+
// Validate required fields per type to avoid creating broken entities
1514+
if (
1515+
ann.type === "marker" &&
1516+
(ann.latitude == null || ann.longitude == null)
1517+
)
1518+
continue;
1519+
if (
1520+
ann.type === "circle" &&
1521+
(ann.latitude == null || ann.longitude == null || ann.radiusKm == null)
1522+
)
1523+
continue;
1524+
if (
1525+
(ann.type === "route" || ann.type === "area") &&
1526+
(!ann.points || ann.points.length === 0)
1527+
)
1528+
continue;
15131529
// Idempotent upsert: addAnnotation already handles existing IDs
15141530
addAnnotation(viewer, ann);
15151531
}
@@ -1559,15 +1575,9 @@ app.ontoolinput = async (params) => {
15591575
hasReceivedToolInput = true;
15601576
log.info("Positioning camera to bbox:", bbox);
15611577
setViewToBoundingBox(viewer, bbox);
1562-
await waitForTilesLoaded(viewer);
1563-
hideLoading();
1564-
log.info(
1565-
"Camera positioned, tiles loaded. Height:",
1566-
viewer.camera.positionCartographic.height,
1567-
);
15681578
}
15691579

1570-
// Add initial annotations from tool input
1580+
// Add annotations immediately (before waiting for tiles so they appear ASAP)
15711581
if (args.annotations && args.annotations.length > 0) {
15721582
for (const ann of args.annotations) {
15731583
addAnnotation(viewer, ann);
@@ -1578,6 +1588,15 @@ app.ontoolinput = async (params) => {
15781588
"initial annotation(s) from tool input",
15791589
);
15801590
}
1591+
1592+
if (bbox) {
1593+
await waitForTilesLoaded(viewer);
1594+
hideLoading();
1595+
log.info(
1596+
"Camera positioned, tiles loaded. Height:",
1597+
viewer.camera.positionCartographic.height,
1598+
);
1599+
}
15811600
}
15821601
};
15831602

0 commit comments

Comments
 (0)