Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat(mcp): a driver can turn a subtree into a prefab

yhh3ffdb0c9c743
diff --git a/desktop/scripts/editor-mcp-tools.mjs b/desktop/scripts/editor-mcp-tools.mjs
index 5d3beb439..a3261db44 100644
--- a/desktop/scripts/editor-mcp-tools.mjs
+++ b/desktop/scripts/editor-mcp-tools.mjs
@@ -188,6 +188,13 @@ export const TOOLS = [
schema: obj({ destDir: { type: 'string' }, name: { type: 'string' } }, ['destDir']),
js: (i) => `window.__estellaEditor.createSceneFile(${JSON.stringify(i.destDir)}, ${JSON.stringify(i.name ?? null)})
.then((p) => window.__estellaEditor.refreshAssets().then(() => p))` },
+ { name: 'create_prefab_from_entity', write: true,
+ description: 'Extract an entity and its subtree into a `.esprefab` asset under assets/prefabs/ (the Outliner\'s Create Prefab), named after the entity; returns its `@uuid:` ref. '
+ + 'This is what makes a subtree REUSABLE: afterwards `list_entity_templates` offers it as `prefab:<path>`, and creating with that template makes a real INSTANCE — the scene stores a delta, not a copy, so editing the prefab updates every instance. '
+ + 'Without it a driver can build the same panel chrome into twenty scenes but never share it. Refs pointing OUT of the subtree cannot live in a standalone prefab and are cleared.',
+ schema: obj({ entity: { type: 'number' } }, ['entity']),
+ js: (i) => `window.__estellaEditor.createPrefabFromEntity(${Number(i.entity)})
+ .then((ref) => { if (!ref) throw new Error('could not create a prefab from entity ${Number(i.entity)} — it may not exist'); return ref; })` },
{ name: 'create_asset', write: true,
description: 'Create a text asset file under a project-relative directory with the given content. `type` is the meta vocabulary: scene, prefab, shader, material, animclip (.esanim), animation (.estimeline), tileset, statemachine (.esfsm), behaviortree (.esbt), locale, inputmap, tilemap (.tmj). A bare baseName gets the type\'s canonical extension appended. Returns the project-relative path, immediately referenceable (the registry refresh happens before this resolves).',
schema: obj({
diff --git a/desktop/src/main.tsx b/desktop/src/main.tsx
index 7b8afcc6d..f25be2bdc 100644
--- a/desktop/src/main.tsx
+++ b/desktop/src/main.tsx
@@ -190,6 +190,17 @@ if (new URLSearchParams(location.search).has('automation')) {
/** Create a blank scene FILE under `destDir` (Content Browser "New Scene"). */
createSceneFile: (destDir: string, name?: string | null) =>
ProjectStore.createSceneFile(destDir, name ?? undefined),
+ /**
+ * Extract an entity's subtree into a `.esprefab` asset (the Outliner's Create
+ * Prefab), returning its `@uuid:` ref.
+ *
+ * The one authoring step automation could not take: a driver could build a
+ * subtree but never turn it into a reusable one, so anything shared had to be
+ * duplicated per scene. Goes through the editor's own extractor, so component
+ * data and asset refs are serialized by the code that owns that format rather
+ * than by a caller guessing at it.
+ */
+ createPrefabFromEntity: (id: number) => ProjectStore.createPrefabFromEntity(id),
/** The Create-popover catalog: every ready-made entity the editor can spawn —
* including the open project's own components and prefabs, so automation sees
* the same list a person does. */