@bendyline/molen-tooling 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/NOTICE.md +15 -0
- package/README.md +91 -0
- package/dist/capture/THIRD-PARTY-NOTICES.md +223 -0
- package/dist/capture/basis/LICENSE.txt +55 -0
- package/dist/capture/basis/basis_transcoder.js +19 -0
- package/dist/capture/basis/basis_transcoder.wasm +0 -0
- package/dist/capture/capture.html +15 -0
- package/dist/capture/harness.js +4671 -0
- package/dist/capture/worldgen-preview.html +15 -0
- package/dist/capture/worldgen-preview.js +4617 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +1276 -0
- package/dist/docs-src/guide/3d-art-guidelines.md +157 -0
- package/dist/docs-src/guide/3d-model-assets.md +286 -0
- package/dist/docs-src/guide/adaptive-performance.md +89 -0
- package/dist/docs-src/guide/agent-loop.md +156 -0
- package/dist/docs-src/guide/aircraft.md +225 -0
- package/dist/docs-src/guide/browser-mount.md +185 -0
- package/dist/docs-src/guide/building-interiors.md +175 -0
- package/dist/docs-src/guide/capability-authoring.md +69 -0
- package/dist/docs-src/guide/determinism.md +285 -0
- package/dist/docs-src/guide/entities.md +47 -0
- package/dist/docs-src/guide/examples.md +58 -0
- package/dist/docs-src/guide/experience-playback.md +57 -0
- package/dist/docs-src/guide/figures.md +164 -0
- package/dist/docs-src/guide/game-samples.md +100 -0
- package/dist/docs-src/guide/graphics-performance.md +167 -0
- package/dist/docs-src/guide/input.md +205 -0
- package/dist/docs-src/guide/materials.md +125 -0
- package/dist/docs-src/guide/project.md +157 -0
- package/dist/docs-src/guide/quickstart.md +63 -0
- package/dist/docs-src/guide/recognizable-places.md +158 -0
- package/dist/docs-src/guide/rendering-backends.md +231 -0
- package/dist/docs-src/guide/scripting.md +330 -0
- package/dist/docs-src/guide/sky.md +192 -0
- package/dist/docs-src/guide/source-bundles.md +42 -0
- package/dist/docs-src/guide/structure-library.md +114 -0
- package/dist/docs-src/guide/surface-rendering.md +203 -0
- package/dist/docs-src/guide/terrain.md +389 -0
- package/dist/docs-src/guide/three-surface.md +70 -0
- package/dist/docs-src/guide/vehicle-interiors.md +126 -0
- package/dist/docs-src/guide/vehicles.md +110 -0
- package/dist/docs-src/guide/weather.md +123 -0
- package/dist/docs-src/guide/worldgen.md +434 -0
- package/dist/docs-src/llms.txt +129 -0
- package/dist/docs-src/schemas/README.md +36 -0
- package/dist/docs-src/schemas/archstyle.md +2340 -0
- package/dist/docs-src/schemas/assert.md +169 -0
- package/dist/docs-src/schemas/asset.md +543 -0
- package/dist/docs-src/schemas/business-catalog.md +162 -0
- package/dist/docs-src/schemas/cameratrack.md +132 -0
- package/dist/docs-src/schemas/command.md +112 -0
- package/dist/docs-src/schemas/components.md +5826 -0
- package/dist/docs-src/schemas/delta.md +204 -0
- package/dist/docs-src/schemas/experience-play.md +452 -0
- package/dist/docs-src/schemas/figure.md +290 -0
- package/dist/docs-src/schemas/interior-catalog.md +230 -0
- package/dist/docs-src/schemas/keyframe.md +314 -0
- package/dist/docs-src/schemas/landmark-catalog.md +56 -0
- package/dist/docs-src/schemas/landmark.md +293 -0
- package/dist/docs-src/schemas/matgraph.md +1163 -0
- package/dist/docs-src/schemas/pack-index.md +82 -0
- package/dist/docs-src/schemas/pack-source.md +139 -0
- package/dist/docs-src/schemas/pack.md +225 -0
- package/dist/docs-src/schemas/pixelgrid.md +108 -0
- package/dist/docs-src/schemas/prefab.md +106 -0
- package/dist/docs-src/schemas/project.md +271 -0
- package/dist/docs-src/schemas/region-atlas.md +612 -0
- package/dist/docs-src/schemas/replay.md +807 -0
- package/dist/docs-src/schemas/scatter.md +541 -0
- package/dist/docs-src/schemas/scene.md +1152 -0
- package/dist/docs-src/schemas/source-bundle.md +266 -0
- package/dist/docs-src/schemas/stylepack.md +420 -0
- package/dist/docs-src/schemas/terrain-package.md +731 -0
- package/dist/docs-src/schemas/terrain.md +313 -0
- package/dist/docs-src/schemas/types.md +218 -0
- package/dist/docs-src/schemas/uvpaint.md +149 -0
- package/dist/docs-src/schemas/worldgen-batch.md +743 -0
- package/dist/index.d.mts +1271 -0
- package/dist/index.mjs +78 -0
- package/dist/mcp-BFnCWrg0.mjs +796 -0
- package/dist/ops-BGxhSP6w.mjs +7246 -0
- package/package.json +96 -0
|
@@ -0,0 +1,796 @@
|
|
|
1
|
+
import { $ as importAsset, A as verifyContentPack, B as describeOps, C as listTypes, D as extractContentPack, E as buildContentPack, F as exportFrames, G as stageAssets, H as checkScripts, I as driveScene, J as formatPacked, K as screenshotAsset, N as previewFigure, O as fetchContentPack, P as listFigurePresets, R as searchDocs, S as checkTypesOp, T as reserveNamespace, V as formatOp, X as inspectAsset, Y as packAsset, Z as listAssets, _ as loadComponentRegistry, b as runReplayFile, c as validateAsset, d as runSimulation, f as screenshotScene, g as listSchemasOp, h as listComponentsOp, i as bakeWorldgen, j as generateTypes, k as inspectContentPack, l as applyUvPaintOp, m as getSchemaOp, n as worldgenStats, ot as playExperience, p as getComponentOp, r as previewWorldgen, u as testTypes, v as scaffoldExperience, w as projectInfo, x as rasterizeMaterial, y as diffSnapshots } from "./ops-BGxhSP6w.mjs";
|
|
2
|
+
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { ENGINE_VERSION } from "@bendyline/molen-kernel";
|
|
6
|
+
import { tmpdir } from "node:os";
|
|
7
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
8
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
9
|
+
//#region src/mcp.ts
|
|
10
|
+
function text(s, isError = false) {
|
|
11
|
+
return {
|
|
12
|
+
content: [{
|
|
13
|
+
type: "text",
|
|
14
|
+
text: s
|
|
15
|
+
}],
|
|
16
|
+
...isError ? { isError } : {}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** Build the molen MCP server (stdio). Mirrors the CLI ops; inputs use the ops' contracts. */
|
|
20
|
+
function createMcpServer() {
|
|
21
|
+
const server = new McpServer({
|
|
22
|
+
name: "molen",
|
|
23
|
+
version: ENGINE_VERSION
|
|
24
|
+
});
|
|
25
|
+
server.registerTool("list_schemas", {
|
|
26
|
+
title: "List schemas",
|
|
27
|
+
description: "List all registered asset schema kinds.",
|
|
28
|
+
inputSchema: {}
|
|
29
|
+
}, async () => text(listSchemasOp().map((s) => `${s.kind} — ${s.title}: ${s.description}`).join("\n")));
|
|
30
|
+
server.registerTool("get_schema", {
|
|
31
|
+
title: "Get schema",
|
|
32
|
+
description: "Get a schema kind: JSON Schema + examples + docs reference.",
|
|
33
|
+
inputSchema: { kind: z.string() }
|
|
34
|
+
}, async ({ kind }) => {
|
|
35
|
+
const r = getSchemaOp(kind);
|
|
36
|
+
if (!r.ok) return text(r.error ?? "unknown kind", true);
|
|
37
|
+
return text(JSON.stringify({
|
|
38
|
+
id: r.id,
|
|
39
|
+
docsRef: r.docsRef,
|
|
40
|
+
examples: r.examples,
|
|
41
|
+
jsonSchema: r.jsonSchema
|
|
42
|
+
}, null, 2));
|
|
43
|
+
});
|
|
44
|
+
server.registerTool("list_components", {
|
|
45
|
+
title: "List components",
|
|
46
|
+
description: "List component vocabulary from the current project or an explicit project/scene.",
|
|
47
|
+
inputSchema: {
|
|
48
|
+
projectPath: z.string().optional(),
|
|
49
|
+
scenePath: z.string().optional()
|
|
50
|
+
}
|
|
51
|
+
}, async (args) => text(listComponentsOp(await loadComponentRegistry(args)).map((c) => `${c.name} — ${c.description}${c.owner ? ` [${c.owner}]` : ""}`).join("\n")));
|
|
52
|
+
server.registerTool("get_component", {
|
|
53
|
+
title: "Get component",
|
|
54
|
+
description: "Get one component schema + examples (the authoring contract for a component).",
|
|
55
|
+
inputSchema: {
|
|
56
|
+
name: z.string(),
|
|
57
|
+
projectPath: z.string().optional(),
|
|
58
|
+
scenePath: z.string().optional()
|
|
59
|
+
}
|
|
60
|
+
}, async ({ name, ...context }) => {
|
|
61
|
+
const r = getComponentOp(name, await loadComponentRegistry(context));
|
|
62
|
+
if (!r.ok) return text(r.error ?? "unknown component", true);
|
|
63
|
+
return text(JSON.stringify(r, null, 2));
|
|
64
|
+
});
|
|
65
|
+
server.registerTool("describe_op", {
|
|
66
|
+
title: "Describe op",
|
|
67
|
+
description: "Machine-readable contracts for the molen operations (CLI + MCP).",
|
|
68
|
+
inputSchema: { name: z.string().optional() }
|
|
69
|
+
}, async ({ name }) => {
|
|
70
|
+
const ops = describeOps(name);
|
|
71
|
+
if (ops.length === 0) return text(`no op matching "${name}"`, true);
|
|
72
|
+
return text(ops.map(formatOp).join("\n\n"));
|
|
73
|
+
});
|
|
74
|
+
server.registerTool("validate_asset", {
|
|
75
|
+
title: "Validate asset",
|
|
76
|
+
description: "Validate a JSON asset document against its schema (kind auto-detected).",
|
|
77
|
+
inputSchema: {
|
|
78
|
+
path: z.string().optional(),
|
|
79
|
+
inline: z.unknown().optional(),
|
|
80
|
+
kind: z.string().optional(),
|
|
81
|
+
verifyFiles: z.boolean().optional(),
|
|
82
|
+
projectPath: z.string().optional()
|
|
83
|
+
}
|
|
84
|
+
}, async (args) => {
|
|
85
|
+
const r = await validateAsset(args);
|
|
86
|
+
return r.ok ? text(`✓ valid ${r.kind}${r.verifiedFiles !== void 0 ? `; verified ${r.verifiedFiles} package files` : ""}`) : text(r.formatted ?? "invalid", true);
|
|
87
|
+
});
|
|
88
|
+
server.registerTool("run_simulation", {
|
|
89
|
+
title: "Run simulation",
|
|
90
|
+
description: "Run a scene headlessly for N ticks; returns tick, state hash, events, assertions.",
|
|
91
|
+
inputSchema: {
|
|
92
|
+
scenePath: z.string(),
|
|
93
|
+
ticks: z.number().int().positive(),
|
|
94
|
+
setupModule: z.string().optional(),
|
|
95
|
+
commandsPath: z.string().optional(),
|
|
96
|
+
assertPath: z.string().optional(),
|
|
97
|
+
projectPath: z.string().optional()
|
|
98
|
+
}
|
|
99
|
+
}, async (args) => {
|
|
100
|
+
const r = await runSimulation(args);
|
|
101
|
+
if (r.error !== void 0) return text(r.error, true);
|
|
102
|
+
const lines = [
|
|
103
|
+
`tick: ${r.tick}`,
|
|
104
|
+
`hash: ${r.stateHash}`,
|
|
105
|
+
`events: ${r.eventCount}`
|
|
106
|
+
];
|
|
107
|
+
if (r.assertionsFormatted !== void 0) lines.push(r.assertionsFormatted);
|
|
108
|
+
return text(lines.join("\n"), !r.ok);
|
|
109
|
+
});
|
|
110
|
+
server.registerTool("screenshot_scene", {
|
|
111
|
+
title: "Screenshot scene",
|
|
112
|
+
description: "Render a deterministic headless screenshot of a scene to a PNG; returns stats.",
|
|
113
|
+
inputSchema: {
|
|
114
|
+
scenePath: z.string(),
|
|
115
|
+
outPath: z.string(),
|
|
116
|
+
ticks: z.number().int().nonnegative().default(0),
|
|
117
|
+
setupModule: z.string().optional(),
|
|
118
|
+
projectPath: z.string().optional(),
|
|
119
|
+
camera: z.object({
|
|
120
|
+
position: z.tuple([
|
|
121
|
+
z.number(),
|
|
122
|
+
z.number(),
|
|
123
|
+
z.number()
|
|
124
|
+
]),
|
|
125
|
+
lookAt: z.tuple([
|
|
126
|
+
z.number(),
|
|
127
|
+
z.number(),
|
|
128
|
+
z.number()
|
|
129
|
+
]).optional()
|
|
130
|
+
}).optional(),
|
|
131
|
+
size: z.tuple([z.number(), z.number()]).optional(),
|
|
132
|
+
terrain: z.object({
|
|
133
|
+
descriptorPath: z.string(),
|
|
134
|
+
heightmapPath: z.string()
|
|
135
|
+
}).optional(),
|
|
136
|
+
clearColor: z.string().optional(),
|
|
137
|
+
assetVariant: z.string().optional()
|
|
138
|
+
}
|
|
139
|
+
}, async (args) => {
|
|
140
|
+
const r = await screenshotScene(args);
|
|
141
|
+
if (!r.ok) return text(r.error ?? "screenshot failed", true);
|
|
142
|
+
const s = r.renderStats;
|
|
143
|
+
return text(`wrote ${r.imagePath}\ntick ${r.tick}, hash ${r.stateHash}\nrendered ${s?.entitiesRendered ?? 0} entities, ${s?.drawCalls ?? 0} draw calls, ${s?.triangles ?? 0} triangles`);
|
|
144
|
+
});
|
|
145
|
+
server.registerTool("rasterize_material", {
|
|
146
|
+
title: "Rasterize material",
|
|
147
|
+
description: "Bake a material graph or palette ref to a PNG texture.",
|
|
148
|
+
inputSchema: {
|
|
149
|
+
path: z.string().optional(),
|
|
150
|
+
inline: z.unknown().optional(),
|
|
151
|
+
ref: z.string().optional(),
|
|
152
|
+
outPath: z.string()
|
|
153
|
+
}
|
|
154
|
+
}, async (args) => {
|
|
155
|
+
const r = await rasterizeMaterial(args);
|
|
156
|
+
return r.ok ? text(`wrote ${r.imagePath} (${r.width}x${r.height}, slots: ${r.slots?.join(", ")})`) : text(r.error ?? "bake failed", true);
|
|
157
|
+
});
|
|
158
|
+
server.registerTool("run_replay", {
|
|
159
|
+
title: "Run replay",
|
|
160
|
+
description: "Replay a recorded fixture and compare the state hash; localizes divergence on mismatch.",
|
|
161
|
+
inputSchema: {
|
|
162
|
+
path: z.string(),
|
|
163
|
+
setupModule: z.string().optional(),
|
|
164
|
+
projectPath: z.string().optional(),
|
|
165
|
+
record: z.boolean().optional()
|
|
166
|
+
}
|
|
167
|
+
}, async (args) => {
|
|
168
|
+
const r = await runReplayFile(args);
|
|
169
|
+
if (r.error !== void 0) return text(r.error, true);
|
|
170
|
+
return text(r.report ?? (r.ok ? "✓ replay matches" : "✖ replay diverged"), !r.ok);
|
|
171
|
+
});
|
|
172
|
+
server.registerTool("apply_uv_paint", {
|
|
173
|
+
title: "Apply UV paint",
|
|
174
|
+
description: "Import a painted UV template: mask it to the island map and dilate the gutters.",
|
|
175
|
+
inputSchema: {
|
|
176
|
+
paintedPath: z.string(),
|
|
177
|
+
islandMapPath: z.string(),
|
|
178
|
+
outPath: z.string(),
|
|
179
|
+
maskToIslands: z.boolean().optional(),
|
|
180
|
+
dilationPx: z.number().int().nonnegative().optional()
|
|
181
|
+
}
|
|
182
|
+
}, async (args) => {
|
|
183
|
+
const r = await applyUvPaintOp(args);
|
|
184
|
+
return r.ok ? text(`wrote ${r.imagePath} (${r.width}x${r.height})`) : text(r.error ?? "failed", true);
|
|
185
|
+
});
|
|
186
|
+
server.registerTool("export_frames", {
|
|
187
|
+
title: "Export frames",
|
|
188
|
+
description: "Render a tick range of a scene to a PNG sequence, optionally following a camera track.",
|
|
189
|
+
inputSchema: {
|
|
190
|
+
scenePath: z.string(),
|
|
191
|
+
outDir: z.string(),
|
|
192
|
+
from: z.number().int().nonnegative(),
|
|
193
|
+
to: z.number().int().nonnegative(),
|
|
194
|
+
step: z.number().int().positive().optional(),
|
|
195
|
+
setupModule: z.string().optional(),
|
|
196
|
+
projectPath: z.string().optional(),
|
|
197
|
+
trackPath: z.string().optional(),
|
|
198
|
+
camera: z.object({
|
|
199
|
+
position: z.tuple([
|
|
200
|
+
z.number(),
|
|
201
|
+
z.number(),
|
|
202
|
+
z.number()
|
|
203
|
+
]),
|
|
204
|
+
lookAt: z.tuple([
|
|
205
|
+
z.number(),
|
|
206
|
+
z.number(),
|
|
207
|
+
z.number()
|
|
208
|
+
]).optional()
|
|
209
|
+
}).optional(),
|
|
210
|
+
size: z.tuple([z.number(), z.number()]).optional()
|
|
211
|
+
}
|
|
212
|
+
}, async (args) => {
|
|
213
|
+
const r = await exportFrames(args);
|
|
214
|
+
if (!r.ok) return text(r.error ?? "export failed", true);
|
|
215
|
+
return text(`wrote ${r.frameCount} frames to ${r.dir}`);
|
|
216
|
+
});
|
|
217
|
+
server.registerTool("diff_snapshots", {
|
|
218
|
+
title: "Diff snapshots",
|
|
219
|
+
description: "Component-level diff between two keyframe JSON files.",
|
|
220
|
+
inputSchema: {
|
|
221
|
+
a: z.string(),
|
|
222
|
+
b: z.string()
|
|
223
|
+
}
|
|
224
|
+
}, async (args) => {
|
|
225
|
+
const r = await diffSnapshots(args);
|
|
226
|
+
if (!r.ok) return text(r.error ?? "diff failed", true);
|
|
227
|
+
const diffs = r.diffs ?? [];
|
|
228
|
+
if (diffs.length === 0) return text("no differences");
|
|
229
|
+
return text(diffs.map((d) => `${d.kind} ${d.entity}.${d.component}` + (d.kind === "changed" ? `: ${JSON.stringify(d.before)} -> ${JSON.stringify(d.after)}` : "")).join("\n"));
|
|
230
|
+
});
|
|
231
|
+
server.registerTool("search_docs", {
|
|
232
|
+
title: "Search docs",
|
|
233
|
+
description: "Lexical search over the shipped engine docs (docs-src bundle).",
|
|
234
|
+
inputSchema: {
|
|
235
|
+
query: z.string(),
|
|
236
|
+
k: z.number().int().positive().default(5),
|
|
237
|
+
includeDesign: z.boolean().optional()
|
|
238
|
+
}
|
|
239
|
+
}, async ({ query, k, includeDesign }) => text((await searchDocs({
|
|
240
|
+
query,
|
|
241
|
+
k,
|
|
242
|
+
includeDesign
|
|
243
|
+
})).formatted));
|
|
244
|
+
const imageItem = async (path) => ({
|
|
245
|
+
type: "image",
|
|
246
|
+
data: (await readFile(path)).toString("base64"),
|
|
247
|
+
mimeType: "image/png"
|
|
248
|
+
});
|
|
249
|
+
server.registerTool("drive_scene", {
|
|
250
|
+
title: "Drive scene",
|
|
251
|
+
description: "PLAY a scene deterministically: submit commands at chosen ticks and capture screenshots at chosen ticks in one pass. Returns the frames as images plus events/hash — same actions always produce the same frames.",
|
|
252
|
+
inputSchema: {
|
|
253
|
+
scenePath: z.string(),
|
|
254
|
+
projectPath: z.string().optional(),
|
|
255
|
+
setupModule: z.string().optional(),
|
|
256
|
+
actions: z.array(z.object({
|
|
257
|
+
at: z.number().int().nonnegative(),
|
|
258
|
+
command: z.object({
|
|
259
|
+
type: z.string(),
|
|
260
|
+
payload: z.unknown().optional()
|
|
261
|
+
}).optional(),
|
|
262
|
+
screenshot: z.string().optional(),
|
|
263
|
+
camera: z.object({
|
|
264
|
+
position: z.tuple([
|
|
265
|
+
z.number(),
|
|
266
|
+
z.number(),
|
|
267
|
+
z.number()
|
|
268
|
+
]),
|
|
269
|
+
lookAt: z.tuple([
|
|
270
|
+
z.number(),
|
|
271
|
+
z.number(),
|
|
272
|
+
z.number()
|
|
273
|
+
]).optional()
|
|
274
|
+
}).optional()
|
|
275
|
+
})),
|
|
276
|
+
until: z.number().int().nonnegative().optional(),
|
|
277
|
+
assertPath: z.string().optional(),
|
|
278
|
+
size: z.tuple([z.number(), z.number()]).optional()
|
|
279
|
+
}
|
|
280
|
+
}, async (args) => {
|
|
281
|
+
const outDir = await mkdtemp(join(tmpdir(), "molen-drive-"));
|
|
282
|
+
try {
|
|
283
|
+
const r = await driveScene(Object.assign({}, args, { outDir }));
|
|
284
|
+
if (r.error !== void 0) return text(r.error, true);
|
|
285
|
+
const lines = [
|
|
286
|
+
`tick: ${r.tick} hash: ${r.stateHash}`,
|
|
287
|
+
`events (${r.events?.length ?? 0}): ${(r.events ?? []).slice(0, 40).map((e) => `t${e.tick}:${e.type}`).join(" ")}`,
|
|
288
|
+
...(r.frames ?? []).map((f) => `frame "${f.name}" @ tick ${f.tick}`),
|
|
289
|
+
...r.assertionsFormatted !== void 0 ? [r.assertionsFormatted] : []
|
|
290
|
+
];
|
|
291
|
+
const images = await Promise.all((r.frames ?? []).map((f) => imageItem(f.path)));
|
|
292
|
+
return {
|
|
293
|
+
content: [{
|
|
294
|
+
type: "text",
|
|
295
|
+
text: lines.join("\n")
|
|
296
|
+
}, ...images],
|
|
297
|
+
...r.ok ? {} : { isError: true }
|
|
298
|
+
};
|
|
299
|
+
} finally {
|
|
300
|
+
await rm(outDir, {
|
|
301
|
+
recursive: true,
|
|
302
|
+
force: true
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
server.registerTool("play_experience", {
|
|
307
|
+
title: "Play browser experience",
|
|
308
|
+
description: "Host a built browser experience, execute declarative keyboard/pointer/UI actions, and return screenshots plus diagnostics.",
|
|
309
|
+
inputSchema: {
|
|
310
|
+
appDir: z.string(),
|
|
311
|
+
scenario: z.record(z.string(), z.unknown())
|
|
312
|
+
}
|
|
313
|
+
}, async ({ appDir, scenario }) => {
|
|
314
|
+
const outDir = await mkdtemp(join(tmpdir(), "molen-play-"));
|
|
315
|
+
try {
|
|
316
|
+
const result = await playExperience({
|
|
317
|
+
appDir,
|
|
318
|
+
scenario,
|
|
319
|
+
outDir
|
|
320
|
+
});
|
|
321
|
+
if (result.error !== void 0) return text(result.error, true);
|
|
322
|
+
const lines = [
|
|
323
|
+
`scenario: ${result.scenario}`,
|
|
324
|
+
...(result.frames ?? []).map((frame) => `frame "${frame.name}" @ action ${frame.actionIndex}${Object.keys(frame.probes).length === 0 ? "" : ` — ${JSON.stringify(frame.probes)}`}`),
|
|
325
|
+
...(result.diagnostics ?? []).map((diagnostic) => `${diagnostic.kind} @ action ${diagnostic.actionIndex}: ${diagnostic.text}`)
|
|
326
|
+
];
|
|
327
|
+
const images = await Promise.all((result.frames ?? []).map((frame) => imageItem(frame.path)));
|
|
328
|
+
return {
|
|
329
|
+
content: [{
|
|
330
|
+
type: "text",
|
|
331
|
+
text: lines.join("\n")
|
|
332
|
+
}, ...images],
|
|
333
|
+
...result.ok ? {} : { isError: true }
|
|
334
|
+
};
|
|
335
|
+
} finally {
|
|
336
|
+
await rm(outDir, {
|
|
337
|
+
recursive: true,
|
|
338
|
+
force: true
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
server.registerTool("screenshot_asset", {
|
|
343
|
+
title: "Screenshot asset",
|
|
344
|
+
description: "Render an imported asset from N turntable angles (framed from its sidecar bounds). Returns the frames as images — look at what you imported.",
|
|
345
|
+
inputSchema: {
|
|
346
|
+
ref: z.string(),
|
|
347
|
+
projectPath: z.string().optional(),
|
|
348
|
+
angles: z.number().int().positive().optional(),
|
|
349
|
+
clip: z.string().optional(),
|
|
350
|
+
clipTime: z.number().nonnegative().optional(),
|
|
351
|
+
size: z.tuple([z.number(), z.number()]).optional(),
|
|
352
|
+
assetVariant: z.string().optional()
|
|
353
|
+
}
|
|
354
|
+
}, async (args) => {
|
|
355
|
+
const outDir = await mkdtemp(join(tmpdir(), "molen-asset-shot-"));
|
|
356
|
+
try {
|
|
357
|
+
const r = await screenshotAsset(Object.assign({}, args, { outDir }));
|
|
358
|
+
if (!r.ok) return text(r.error ?? "asset shot failed", true);
|
|
359
|
+
const images = await Promise.all((r.frames ?? []).map((f) => imageItem(f.path)));
|
|
360
|
+
return { content: [{
|
|
361
|
+
type: "text",
|
|
362
|
+
text: `${r.frames?.length ?? 0} angles, ${r.triangles} triangles`
|
|
363
|
+
}, ...images] };
|
|
364
|
+
} finally {
|
|
365
|
+
await rm(outDir, {
|
|
366
|
+
recursive: true,
|
|
367
|
+
force: true
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
server.registerTool("figure_preview", {
|
|
372
|
+
title: "Preview figures",
|
|
373
|
+
description: "Render figure presets, an inline molen/figure@1 descriptor, or a built-in lineup headlessly from turntable angles or the art-review view set. Returns the frames as images.",
|
|
374
|
+
inputSchema: {
|
|
375
|
+
preset: z.union([z.string(), z.array(z.string())]).optional(),
|
|
376
|
+
descriptor: z.record(z.string(), z.unknown()).optional(),
|
|
377
|
+
descriptorPath: z.string().optional(),
|
|
378
|
+
lineup: z.enum([
|
|
379
|
+
"humans",
|
|
380
|
+
"bodies",
|
|
381
|
+
"species",
|
|
382
|
+
"all"
|
|
383
|
+
]).optional(),
|
|
384
|
+
mode: z.enum([
|
|
385
|
+
"idle",
|
|
386
|
+
"walk",
|
|
387
|
+
"run",
|
|
388
|
+
"sit",
|
|
389
|
+
"jump",
|
|
390
|
+
"fall"
|
|
391
|
+
]).optional(),
|
|
392
|
+
tick: z.number().int().nonnegative().optional(),
|
|
393
|
+
tier: z.union([
|
|
394
|
+
z.literal(0),
|
|
395
|
+
z.literal(1),
|
|
396
|
+
z.literal(2)
|
|
397
|
+
]).optional(),
|
|
398
|
+
angles: z.union([z.number().int().positive(), z.literal("review")]).optional(),
|
|
399
|
+
size: z.tuple([z.number(), z.number()]).optional()
|
|
400
|
+
}
|
|
401
|
+
}, async (args) => {
|
|
402
|
+
const outDir = await mkdtemp(join(tmpdir(), "molen-figure-preview-"));
|
|
403
|
+
try {
|
|
404
|
+
const r = await previewFigure(Object.assign({}, args, { outPath: join(outDir, "figure.png") }));
|
|
405
|
+
if (!r.ok) return text(r.error ?? "figure preview failed", true);
|
|
406
|
+
const images = await Promise.all((r.frames ?? []).map((f) => imageItem(f.path)));
|
|
407
|
+
return { content: [{
|
|
408
|
+
type: "text",
|
|
409
|
+
text: `${r.stats?.figures ?? 0} figures, ${r.stats?.triangles ?? 0} triangles, ${r.stats?.joints ?? 0} joints, hash ${r.hash ?? ""}`
|
|
410
|
+
}, ...images] };
|
|
411
|
+
} finally {
|
|
412
|
+
await rm(outDir, {
|
|
413
|
+
recursive: true,
|
|
414
|
+
force: true
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
server.registerTool("list_figure_presets", {
|
|
419
|
+
title: "List figure presets",
|
|
420
|
+
description: "List the shipped figure presets with their resolved descriptors.",
|
|
421
|
+
inputSchema: { archetype: z.enum(["biped", "quadruped"]).optional() }
|
|
422
|
+
}, async (args) => text(JSON.stringify(listFigurePresets(args).presets, null, 2)));
|
|
423
|
+
server.registerTool("worldgen_preview", {
|
|
424
|
+
title: "Preview generated buildings",
|
|
425
|
+
description: "Generate buildings from a style pack (default: one of every footprint class) and render them headlessly from N turntable angles. Returns the frames as images.",
|
|
426
|
+
inputSchema: {
|
|
427
|
+
stylePath: z.string().optional(),
|
|
428
|
+
packPath: z.string().optional(),
|
|
429
|
+
styleId: z.string().optional(),
|
|
430
|
+
batchPath: z.string().optional(),
|
|
431
|
+
scatterId: z.string().optional(),
|
|
432
|
+
ground: z.enum(["flat", "slope"]).optional(),
|
|
433
|
+
angles: z.number().int().positive().optional(),
|
|
434
|
+
size: z.tuple([z.number(), z.number()]).optional()
|
|
435
|
+
}
|
|
436
|
+
}, async (args) => {
|
|
437
|
+
const outDir = await mkdtemp(join(tmpdir(), "molen-worldgen-preview-"));
|
|
438
|
+
try {
|
|
439
|
+
const r = await previewWorldgen(Object.assign({}, args, { outPath: join(outDir, "preview.png") }));
|
|
440
|
+
if (!r.ok) return text(r.error ?? "worldgen preview failed", true);
|
|
441
|
+
const images = await Promise.all((r.frames ?? []).map((f) => imageItem(f.path)));
|
|
442
|
+
return { content: [{
|
|
443
|
+
type: "text",
|
|
444
|
+
text: `${r.stats?.buildingsRendered ?? 0} buildings (${r.stats?.buildingsBoxed ?? 0} boxed), ${r.renderStats?.drawCalls ?? 0} draws, ${r.renderStats?.triangles ?? 0} triangles, hash ${r.hash ?? ""}`
|
|
445
|
+
}, ...images] };
|
|
446
|
+
} finally {
|
|
447
|
+
await rm(outDir, {
|
|
448
|
+
recursive: true,
|
|
449
|
+
force: true
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
server.registerTool("worldgen_bake", {
|
|
454
|
+
title: "Bake generated buildings",
|
|
455
|
+
description: "Generate buildings from a batch document or one outline and bake them to a glTF asset with a molen/asset@1 sidecar under outDir.",
|
|
456
|
+
inputSchema: {
|
|
457
|
+
batchPath: z.string().optional(),
|
|
458
|
+
outline: z.string().optional(),
|
|
459
|
+
styleId: z.string().optional(),
|
|
460
|
+
packPath: z.string().optional(),
|
|
461
|
+
outDir: z.string(),
|
|
462
|
+
id: z.string().optional(),
|
|
463
|
+
ground: z.enum(["flat", "slope"]).optional(),
|
|
464
|
+
force: z.boolean().optional(),
|
|
465
|
+
projectPath: z.string().optional()
|
|
466
|
+
}
|
|
467
|
+
}, async (args) => {
|
|
468
|
+
const r = await bakeWorldgen(args);
|
|
469
|
+
if (!r.ok) return text(r.error ?? "worldgen bake failed", true);
|
|
470
|
+
return text(JSON.stringify(r, null, 2));
|
|
471
|
+
});
|
|
472
|
+
server.registerTool("worldgen_stats", {
|
|
473
|
+
title: "Worldgen tile stats",
|
|
474
|
+
description: "Generate one real terrain-package tile in Node and report counts, footprint and roof histograms, sizes, timings, and determinism; optionally dump the adapted batch document.",
|
|
475
|
+
inputSchema: {
|
|
476
|
+
packagePath: z.string(),
|
|
477
|
+
tile: z.string().optional(),
|
|
478
|
+
auto: z.boolean().optional(),
|
|
479
|
+
packPath: z.string().optional(),
|
|
480
|
+
atlasPath: z.string().optional(),
|
|
481
|
+
styleId: z.string().optional(),
|
|
482
|
+
quality: z.enum([
|
|
483
|
+
"economy",
|
|
484
|
+
"balanced",
|
|
485
|
+
"high"
|
|
486
|
+
]).optional(),
|
|
487
|
+
dumpPath: z.string().optional()
|
|
488
|
+
}
|
|
489
|
+
}, async (args) => {
|
|
490
|
+
const r = await worldgenStats(args);
|
|
491
|
+
if (!r.ok) return text(r.error ?? "worldgen stats failed", true);
|
|
492
|
+
return text(JSON.stringify(r, null, 2));
|
|
493
|
+
});
|
|
494
|
+
server.registerTool("test_types", {
|
|
495
|
+
title: "Test types",
|
|
496
|
+
description: "Smoke-test every registry type standalone: resolved components validate, the entity spawns, and the world simulates N ticks.",
|
|
497
|
+
inputSchema: {
|
|
498
|
+
projectPath: z.string().optional(),
|
|
499
|
+
cwd: z.string().optional(),
|
|
500
|
+
ticks: z.number().int().positive().optional(),
|
|
501
|
+
only: z.array(z.string()).optional()
|
|
502
|
+
}
|
|
503
|
+
}, async (args) => {
|
|
504
|
+
const r = await testTypes(args);
|
|
505
|
+
if (r.error !== void 0) return text(r.error, true);
|
|
506
|
+
return text((r.results ?? []).map((t) => `${t.ok ? "✓" : "✖"} ${t.id}${t.error !== void 0 ? ` — ${t.error}` : ""}${t.issues !== void 0 ? ` — ${t.issues.map((i) => i.message).join("; ")}` : ""}`).join("\n") || "(no types registered)", !r.ok);
|
|
507
|
+
});
|
|
508
|
+
server.registerTool("import_asset", {
|
|
509
|
+
title: "Import asset",
|
|
510
|
+
description: "Import a glTF/GLB into the project asset store: normalize, extract bounds + collision (hulls/trimesh), write the molen/asset@1 sidecar, register in project.json.",
|
|
511
|
+
inputSchema: {
|
|
512
|
+
path: z.string(),
|
|
513
|
+
id: z.string().optional(),
|
|
514
|
+
outDir: z.string().optional(),
|
|
515
|
+
trimesh: z.boolean().optional(),
|
|
516
|
+
optimize: z.boolean().optional(),
|
|
517
|
+
projectPath: z.string().optional(),
|
|
518
|
+
cwd: z.string().optional(),
|
|
519
|
+
force: z.boolean().optional()
|
|
520
|
+
}
|
|
521
|
+
}, async (args) => {
|
|
522
|
+
const r = await importAsset(args);
|
|
523
|
+
if (!r.ok) return text(r.error ?? "import failed", true);
|
|
524
|
+
const s = r.sidecar;
|
|
525
|
+
return text([
|
|
526
|
+
`imported "${r.id}" -> ${r.dir}`,
|
|
527
|
+
`${s.stats.triangles} tris, ${s.stats.meshes} meshes, ${s.stats.animations} clips, ${s.collision.hulls.length} hulls${s.collision.trimesh !== void 0 ? " + trimesh" : ""}`,
|
|
528
|
+
r.registered === true ? `registered in ${r.projectPath}` : "NOT registered (no project.json found)",
|
|
529
|
+
...r.warnings ?? []
|
|
530
|
+
].join("\n"));
|
|
531
|
+
});
|
|
532
|
+
server.registerTool("inspect_asset", {
|
|
533
|
+
title: "Inspect asset",
|
|
534
|
+
description: "Read + validate an asset sidecar (by path or project asset id); optionally verify file hashes.",
|
|
535
|
+
inputSchema: {
|
|
536
|
+
ref: z.string(),
|
|
537
|
+
verify: z.boolean().optional(),
|
|
538
|
+
projectPath: z.string().optional()
|
|
539
|
+
}
|
|
540
|
+
}, async (args) => {
|
|
541
|
+
const r = await inspectAsset(args);
|
|
542
|
+
if (!r.ok) return text(r.error ?? (r.verifyErrors ?? []).join("\n"), true);
|
|
543
|
+
return text(JSON.stringify(r.sidecar, null, 2));
|
|
544
|
+
});
|
|
545
|
+
server.registerTool("pack_asset", {
|
|
546
|
+
title: "Pack asset (KTX2 runtime variant)",
|
|
547
|
+
description: "Derive a RUNTIME GLB next to the canonical one: every texture re-encoded as KTX2 (Basis Universal) with a full mip chain, resized to a power of two, so the GPU gets ASTC/BC7 instead of RGBA8 (4-8x less texture memory; decisive on iOS/Android webviews). Records files.variants.<variant> in the sidecar. Pass ref (asset id / sidecar) or all: true.",
|
|
548
|
+
inputSchema: {
|
|
549
|
+
ref: z.string().optional(),
|
|
550
|
+
all: z.boolean().optional(),
|
|
551
|
+
projectPath: z.string().optional(),
|
|
552
|
+
variant: z.string().optional(),
|
|
553
|
+
mode: z.enum([
|
|
554
|
+
"auto",
|
|
555
|
+
"etc1s",
|
|
556
|
+
"uastc"
|
|
557
|
+
]).optional(),
|
|
558
|
+
maxSize: z.number().int().positive().optional(),
|
|
559
|
+
powerOfTwo: z.boolean().optional(),
|
|
560
|
+
etc1sQuality: z.number().int().min(1).max(255).optional(),
|
|
561
|
+
uastcQuality: z.number().int().min(0).max(4).optional()
|
|
562
|
+
}
|
|
563
|
+
}, async (args) => {
|
|
564
|
+
const r = await packAsset(args);
|
|
565
|
+
if (!r.ok) return text(r.error ?? "pack failed", true);
|
|
566
|
+
return text([...formatPacked(r.assets ?? []), ...r.warnings ?? []].join("\n"));
|
|
567
|
+
});
|
|
568
|
+
server.registerTool("stage_assets", {
|
|
569
|
+
title: "Stage assets for the browser",
|
|
570
|
+
description: "Copy every registered asset's runtime files into outDir (same relative layout) and write assets.index.json (id -> URL) for the client's assets.index option. With variant (e.g. \"ktx2\"), the packed GLB replaces the design-time one and the staged sidecar is rewritten to match. Fails on stale (hash-mismatched) assets.",
|
|
571
|
+
inputSchema: {
|
|
572
|
+
outDir: z.string(),
|
|
573
|
+
projectPath: z.string().optional(),
|
|
574
|
+
variant: z.string().optional(),
|
|
575
|
+
requireVariant: z.boolean().optional(),
|
|
576
|
+
clean: z.boolean().optional()
|
|
577
|
+
}
|
|
578
|
+
}, async (args) => {
|
|
579
|
+
const r = await stageAssets(args);
|
|
580
|
+
if (!r.ok) return text(r.error ?? "stage failed", true);
|
|
581
|
+
return text([
|
|
582
|
+
...(r.assets ?? []).map((a) => `${a.id} -> ${a.file}${a.variant !== void 0 ? ` [${a.variant}]` : ""} (${a.bytes} bytes)`),
|
|
583
|
+
`index: ${r.indexPath}`,
|
|
584
|
+
...r.warnings ?? []
|
|
585
|
+
].join("\n"));
|
|
586
|
+
});
|
|
587
|
+
server.registerTool("build_pack", {
|
|
588
|
+
title: "Build a content pack",
|
|
589
|
+
description: "Build a molen/pack@1 zip from a source directory holding molen-pack.source.json. Writes <id>-<hash>.zip into outDir and records it in outDir/index.json. Small text files are grouped into compressed solid blocks unless solid is false.",
|
|
590
|
+
inputSchema: {
|
|
591
|
+
sourceDir: z.string(),
|
|
592
|
+
outDir: z.string(),
|
|
593
|
+
solid: z.boolean().optional()
|
|
594
|
+
}
|
|
595
|
+
}, async (args) => {
|
|
596
|
+
const r = await buildContentPack(args);
|
|
597
|
+
if (!r.ok) return text(r.error ?? "pack build failed", true);
|
|
598
|
+
return text(`${r.id}@${r.version}: ${r.files} files -> ${r.path} (${r.size} bytes)\ncontentHash ${r.contentHash}\nindex ${r.indexPath}`);
|
|
599
|
+
});
|
|
600
|
+
server.registerTool("inspect_pack", {
|
|
601
|
+
title: "Inspect a content pack",
|
|
602
|
+
description: "Summarize a content pack (built file, source directory, or http(s) URL): id, version, contentHash, sizes, solid blocks, asset ids, roles and the largest files, as JSON.",
|
|
603
|
+
inputSchema: { source: z.string() }
|
|
604
|
+
}, async (args) => {
|
|
605
|
+
const r = await inspectContentPack(args);
|
|
606
|
+
if (!r.ok) return text(r.error ?? "pack inspect failed", true);
|
|
607
|
+
const { ok: _ok, ...summary } = r;
|
|
608
|
+
return text(JSON.stringify(summary, null, 2));
|
|
609
|
+
});
|
|
610
|
+
server.registerTool("verify_pack", {
|
|
611
|
+
title: "Verify a content pack",
|
|
612
|
+
description: "Read every file of a content pack checking CRC and sha256, validate each JSON document against its registered schema, and check asset sidecar hashes against their models. Returns the problems found.",
|
|
613
|
+
inputSchema: { source: z.string() }
|
|
614
|
+
}, async (args) => {
|
|
615
|
+
const r = await verifyContentPack(args);
|
|
616
|
+
if (r.error !== void 0) return text(r.error, true);
|
|
617
|
+
const summary = `${r.id}: ${r.checked} files checked, ${r.validated} documents validated`;
|
|
618
|
+
if (!r.ok) return text([summary, ...(r.issues ?? []).map((issue) => `${issue.path}: ${issue.message}`)].join("\n"), true);
|
|
619
|
+
return text(`ok — ${summary}`);
|
|
620
|
+
});
|
|
621
|
+
server.registerTool("extract_pack", {
|
|
622
|
+
title: "Extract a content pack",
|
|
623
|
+
description: "Write every file of a content pack into outDir, with a molen-pack.source.json that builds it back to the same content.",
|
|
624
|
+
inputSchema: {
|
|
625
|
+
source: z.string(),
|
|
626
|
+
outDir: z.string()
|
|
627
|
+
}
|
|
628
|
+
}, async (args) => {
|
|
629
|
+
const r = await extractContentPack(args);
|
|
630
|
+
if (!r.ok) return text(r.error ?? "pack extract failed", true);
|
|
631
|
+
return text(`${r.id}: ${r.files} files -> ${r.outDir}`);
|
|
632
|
+
});
|
|
633
|
+
server.registerTool("fetch_pack", {
|
|
634
|
+
title: "Fetch content packs into a project",
|
|
635
|
+
description: "Download a pack (or the packs listed by a molen/pack-index@1 URL, optionally only ids) into outDir (default packs/ beside project.json) and pin each in project.json `packs` with its contentHash, so the project runs offline.",
|
|
636
|
+
inputSchema: {
|
|
637
|
+
url: z.string(),
|
|
638
|
+
ids: z.array(z.string()).optional(),
|
|
639
|
+
outDir: z.string().optional(),
|
|
640
|
+
projectPath: z.string().optional(),
|
|
641
|
+
cwd: z.string().optional()
|
|
642
|
+
}
|
|
643
|
+
}, async (args) => {
|
|
644
|
+
const r = await fetchContentPack(args);
|
|
645
|
+
if (!r.ok) return text(r.error ?? "pack fetch failed", true);
|
|
646
|
+
return text([...(r.packs ?? []).map((pack) => `${pack.id}@${pack.version} -> ${r.outDir}/${pack.file} (${pack.size} bytes)`), r.projectPath !== void 0 ? `pinned in ${r.projectPath}` : "no project.json to pin in"].join("\n"));
|
|
647
|
+
});
|
|
648
|
+
server.registerTool("list_assets", {
|
|
649
|
+
title: "List assets",
|
|
650
|
+
description: "List the assets registered in the surrounding project.",
|
|
651
|
+
inputSchema: {
|
|
652
|
+
projectPath: z.string().optional(),
|
|
653
|
+
cwd: z.string().optional()
|
|
654
|
+
}
|
|
655
|
+
}, async (args) => {
|
|
656
|
+
const r = await listAssets(args);
|
|
657
|
+
if (!r.ok) return text(r.error ?? "failed", true);
|
|
658
|
+
return text((r.assets ?? []).map((a) => `${a.id} (${a.kind ?? "?"}, ${a.triangles ?? "?"} tris) — ${a.sidecar}`).join("\n") || "(no assets registered)");
|
|
659
|
+
});
|
|
660
|
+
server.registerTool("get_project", {
|
|
661
|
+
title: "Get project",
|
|
662
|
+
description: "Show the surrounding project.json: scenes, types, assets, reservations.",
|
|
663
|
+
inputSchema: {
|
|
664
|
+
projectPath: z.string().optional(),
|
|
665
|
+
cwd: z.string().optional()
|
|
666
|
+
}
|
|
667
|
+
}, async (args) => {
|
|
668
|
+
const r = await projectInfo(args);
|
|
669
|
+
if (r.error !== void 0) return text(r.error, true);
|
|
670
|
+
return text(JSON.stringify(r, null, 2), !r.ok);
|
|
671
|
+
});
|
|
672
|
+
server.registerTool("list_types", {
|
|
673
|
+
title: "List types",
|
|
674
|
+
description: "List the entity types registered in the project type registry.",
|
|
675
|
+
inputSchema: {
|
|
676
|
+
projectPath: z.string().optional(),
|
|
677
|
+
cwd: z.string().optional()
|
|
678
|
+
}
|
|
679
|
+
}, async (args) => {
|
|
680
|
+
const r = await listTypes(args);
|
|
681
|
+
if (!r.ok) return text(r.error ?? "failed", true);
|
|
682
|
+
return text((r.types ?? []).map((t) => `${t.id}${t.extends !== void 0 ? ` extends ${t.extends}` : ""}${t.doc !== void 0 ? ` — ${t.doc}` : ""} [${t.source}]`).join("\n") || "(no types registered)");
|
|
683
|
+
});
|
|
684
|
+
server.registerTool("check_types", {
|
|
685
|
+
title: "Check types",
|
|
686
|
+
description: "Validate the type registry: duplicates, extends cycles, namespace ownership, asset refs, codegen staleness.",
|
|
687
|
+
inputSchema: {
|
|
688
|
+
projectPath: z.string().optional(),
|
|
689
|
+
cwd: z.string().optional()
|
|
690
|
+
}
|
|
691
|
+
}, async (args) => {
|
|
692
|
+
const r = await checkTypesOp(args);
|
|
693
|
+
if (r.error !== void 0) return text(r.error, true);
|
|
694
|
+
const lines = (r.issues ?? []).map((i) => `${i.path}: ${i.message}`);
|
|
695
|
+
if (r.codegenStale === true) lines.push("codegen is stale — run generate_types");
|
|
696
|
+
return text(r.ok ? "✓ types check passed" : lines.join("\n"), !r.ok);
|
|
697
|
+
});
|
|
698
|
+
server.registerTool("check_scripts", {
|
|
699
|
+
title: "Check scripts",
|
|
700
|
+
description: "Type-check the scene's scripts against their generated ambient declarations (component names, command payloads, frozen reads).",
|
|
701
|
+
inputSchema: {
|
|
702
|
+
projectPath: z.string().optional(),
|
|
703
|
+
cwd: z.string().optional()
|
|
704
|
+
}
|
|
705
|
+
}, async (args) => {
|
|
706
|
+
const r = await checkScripts(args);
|
|
707
|
+
if (r.error !== void 0) return text([
|
|
708
|
+
r.error,
|
|
709
|
+
...r.stale ?? [],
|
|
710
|
+
...r.ungenerated ?? []
|
|
711
|
+
].join("\n"), true);
|
|
712
|
+
const lines = (r.diagnostics ?? []).map((d) => `${d.file}:${d.line}:${d.column} ${d.code}: ${d.message}`);
|
|
713
|
+
return text(r.ok ? `✓ ${r.checked ?? 0} script(s) type-check clean` : lines.join("\n"), !r.ok);
|
|
714
|
+
});
|
|
715
|
+
server.registerTool("reserve_type", {
|
|
716
|
+
title: "Reserve namespace",
|
|
717
|
+
description: "Reserve a type/asset id namespace for an owner in project.json (idempotent per owner; conflicts name the holder).",
|
|
718
|
+
inputSchema: {
|
|
719
|
+
namespace: z.string(),
|
|
720
|
+
owner: z.string(),
|
|
721
|
+
note: z.string().optional(),
|
|
722
|
+
projectPath: z.string().optional(),
|
|
723
|
+
cwd: z.string().optional()
|
|
724
|
+
}
|
|
725
|
+
}, async (args) => {
|
|
726
|
+
const r = await reserveNamespace(args);
|
|
727
|
+
if (!r.ok) return text(r.error ?? "reserve failed", true);
|
|
728
|
+
return text(r.alreadyReserved === true ? `already reserved by ${args.owner}` : `reserved "${args.namespace}" for ${args.owner}`);
|
|
729
|
+
});
|
|
730
|
+
server.registerTool("generate_types", {
|
|
731
|
+
title: "Generate types",
|
|
732
|
+
description: "Generate (or verify with check) the typed component/type-id module from the registry.",
|
|
733
|
+
inputSchema: {
|
|
734
|
+
projectPath: z.string().optional(),
|
|
735
|
+
cwd: z.string().optional(),
|
|
736
|
+
out: z.string().optional(),
|
|
737
|
+
check: z.boolean().optional()
|
|
738
|
+
}
|
|
739
|
+
}, async (args) => {
|
|
740
|
+
const r = await generateTypes(args);
|
|
741
|
+
if (r.error !== void 0 && r.stale !== true) return text(r.error, true);
|
|
742
|
+
if (args.check === true) return text(r.stale === true ? `stale: ${r.outPath}` : "codegen up to date", !r.ok);
|
|
743
|
+
return text(`wrote ${r.outPath} (${r.componentCount} components, ${r.typeCount} types)`);
|
|
744
|
+
});
|
|
745
|
+
server.registerTool("new_experience", {
|
|
746
|
+
title: "New experience",
|
|
747
|
+
description: "Scaffold a runnable experience (scene + scripts + setup + commands + checks) on disk.",
|
|
748
|
+
inputSchema: {
|
|
749
|
+
name: z.string(),
|
|
750
|
+
dir: z.string().optional(),
|
|
751
|
+
force: z.boolean().optional()
|
|
752
|
+
}
|
|
753
|
+
}, async (args) => {
|
|
754
|
+
const r = await scaffoldExperience(args);
|
|
755
|
+
if (!r.ok) return text(r.error ?? "scaffold failed", true);
|
|
756
|
+
return text(`created ${r.dir}\n${(r.files ?? []).join("\n")}\n\nnext:\n${(r.nextSteps ?? []).join("\n")}`);
|
|
757
|
+
});
|
|
758
|
+
return server;
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
* Under stdio MCP, stdout **is** the JSON-RPC transport: one stray `console.log` from any
|
|
762
|
+
* dependency (gltf-transform's logger, an Emscripten print hook, a diagnostic left in a library)
|
|
763
|
+
* makes the client fail to parse a frame. Route every stdout-bound console method to stderr for
|
|
764
|
+
* the life of the process; returns a restore function for tests.
|
|
765
|
+
*/
|
|
766
|
+
function guardMcpStdout() {
|
|
767
|
+
const saved = {
|
|
768
|
+
log: console.log,
|
|
769
|
+
info: console.info,
|
|
770
|
+
debug: console.debug,
|
|
771
|
+
dir: console.dir,
|
|
772
|
+
trace: console.trace
|
|
773
|
+
};
|
|
774
|
+
const toStderr = (...args) => {
|
|
775
|
+
console.error(...args);
|
|
776
|
+
};
|
|
777
|
+
console.log = toStderr;
|
|
778
|
+
console.info = toStderr;
|
|
779
|
+
console.debug = toStderr;
|
|
780
|
+
console.dir = toStderr;
|
|
781
|
+
console.trace = toStderr;
|
|
782
|
+
return () => {
|
|
783
|
+
console.log = saved.log;
|
|
784
|
+
console.info = saved.info;
|
|
785
|
+
console.debug = saved.debug;
|
|
786
|
+
console.dir = saved.dir;
|
|
787
|
+
console.trace = saved.trace;
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
/** Start the MCP server over stdio (used by `molen mcp`). */
|
|
791
|
+
async function startMcpServer() {
|
|
792
|
+
guardMcpStdout();
|
|
793
|
+
await createMcpServer().connect(new StdioServerTransport());
|
|
794
|
+
}
|
|
795
|
+
//#endregion
|
|
796
|
+
export { startMcpServer };
|