sceneview-mcp 4.3.4 → 4.5.0

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.
@@ -595,6 +595,7 @@ export const SYMBOLS = {
595
595
  "TextNode",
596
596
  "TorusNode",
597
597
  "TubeNode",
598
+ "TubeNodeWithCaps",
598
599
  "VideoNode",
599
600
  "ViewNode",
600
601
  "engine",
@@ -6539,43 +6540,75 @@ export const SYMBOLS = {
6539
6540
  "DEFAULT_CLOSED",
6540
6541
  "DEFAULT_RADIAL_SEGMENTS",
6541
6542
  "DEFAULT_RADIUS",
6543
+ "capStyle",
6544
+ "capacity",
6542
6545
  "caps",
6543
6546
  "closed",
6547
+ "dEFAULT_CAP_STYLE",
6544
6548
  "dEFAULT_POINTS",
6545
6549
  "frames",
6550
+ "getCapStyle",
6551
+ "getCapacity",
6546
6552
  "getCaps",
6547
6553
  "getClosed",
6554
+ "getDEFAULT_CAP_STYLE",
6548
6555
  "getDEFAULT_POINTS",
6549
6556
  "getIndices",
6557
+ "getIndicesWithCaps",
6550
6558
  "getPoints",
6551
6559
  "getRadialSegments",
6560
+ "getRadii",
6552
6561
  "getRadius",
6553
6562
  "getVertices",
6563
+ "getVerticesWithCaps",
6554
6564
  "indices",
6565
+ "indicesWithCaps",
6555
6566
  "points",
6556
6567
  "radialSegments",
6568
+ "radii",
6557
6569
  "radius",
6558
6570
  "ringCount",
6571
+ "roundCapRings",
6559
6572
  "update",
6560
- "vertices"
6573
+ "updateWithCaps",
6574
+ "vertices",
6575
+ "verticesWithCaps"
6561
6576
  ]
6562
6577
  },
6563
6578
  "io.github.sceneview.geometries.Tube.Builder": {
6564
6579
  "module": "sceneview",
6565
6580
  "members": [
6566
6581
  "build",
6582
+ "capStyle",
6583
+ "capacity",
6567
6584
  "caps",
6568
6585
  "closed",
6586
+ "getCapStyle",
6587
+ "getCapacity",
6569
6588
  "getCaps",
6570
6589
  "getClosed",
6571
6590
  "getPoints",
6572
6591
  "getRadialSegments",
6592
+ "getRadii",
6573
6593
  "getRadius",
6574
6594
  "points",
6575
6595
  "radialSegments",
6596
+ "radii",
6576
6597
  "radius"
6577
6598
  ]
6578
6599
  },
6600
+ "io.github.sceneview.geometries.Tube.CapStyle": {
6601
+ "module": "sceneview",
6602
+ "members": [
6603
+ "Flat",
6604
+ "None",
6605
+ "Round",
6606
+ "entries",
6607
+ "getEntries",
6608
+ "valueOf",
6609
+ "values"
6610
+ ]
6611
+ },
6579
6612
  "io.github.sceneview.geometries.Tube.Frame": {
6580
6613
  "module": "sceneview",
6581
6614
  "members": [
@@ -8478,7 +8511,8 @@ export const SYMBOLS = {
8478
8511
  "members": [
8479
8512
  "geometry",
8480
8513
  "getGeometry",
8481
- "updateGeometry"
8514
+ "updateGeometry",
8515
+ "updateGeometryWithCaps"
8482
8516
  ]
8483
8517
  },
8484
8518
  "io.github.sceneview.node.VideoNode": {
@@ -4,8 +4,8 @@
4
4
  // build time so the MCP server, telemetry, and the install-snippet
5
5
  // generators all report the actually-published versions instead of
6
6
  // stale hardcoded constants. See #941.
7
- export const PACKAGE_VERSION = "4.3.4";
8
- export const LATEST_SCENEVIEW_RELEASE = "4.72.0";
7
+ export const PACKAGE_VERSION = "4.5.0";
8
+ export const LATEST_SCENEVIEW_RELEASE = "4.76.0";
9
9
  // The pub.dev coordinate for `flutter_sceneview`, read from the plugin's
10
10
  // README. Deliberately NOT LATEST_SCENEVIEW_RELEASE: pub.dev lags the SDK,
11
11
  // and a caret range against an unpublished version cannot be resolved.
package/dist/glb.js ADDED
@@ -0,0 +1,227 @@
1
+ /**
2
+ * Minimal, dependency-free GLB (binary glTF 2.0) helpers used by
3
+ * `generate_3d_model`: write a GLB from a JSON document + binary buffer,
4
+ * parse one back, measure its world-space bounding box, and rescale it
5
+ * uniformly without touching the vertex data.
6
+ *
7
+ * Measurement reads only the `POSITION` accessor `min`/`max` that the glTF
8
+ * spec makes mandatory, transformed by each node's TRS/matrix. It never
9
+ * decodes vertex buffers, so it also works on quantized or Draco-compressed
10
+ * meshes. Skins and morph targets are not evaluated (bind pose only).
11
+ *
12
+ * glTF's unit is the metre (spec §3.4), so every size reported here is in
13
+ * metres.
14
+ */
15
+ const GLB_MAGIC = 0x46546c67; // "glTF"
16
+ const CHUNK_JSON = 0x4e4f534a; // "JSON"
17
+ const CHUNK_BIN = 0x004e4942; // "BIN\0"
18
+ export class GlbError extends Error {
19
+ }
20
+ function pad4(length) {
21
+ return (4 - (length % 4)) % 4;
22
+ }
23
+ /** Serialize a glTF JSON document and an optional binary buffer as a GLB. */
24
+ export function writeGlb(json, bin) {
25
+ const jsonBytes = new TextEncoder().encode(JSON.stringify(json));
26
+ const jsonPad = pad4(jsonBytes.length);
27
+ const binPad = bin ? pad4(bin.length) : 0;
28
+ const jsonChunk = 8 + jsonBytes.length + jsonPad;
29
+ const binChunk = bin ? 8 + bin.length + binPad : 0;
30
+ const total = 12 + jsonChunk + binChunk;
31
+ const out = new Uint8Array(total);
32
+ const view = new DataView(out.buffer);
33
+ view.setUint32(0, GLB_MAGIC, true);
34
+ view.setUint32(4, 2, true);
35
+ view.setUint32(8, total, true);
36
+ view.setUint32(12, jsonBytes.length + jsonPad, true);
37
+ view.setUint32(16, CHUNK_JSON, true);
38
+ out.set(jsonBytes, 20);
39
+ out.fill(0x20, 20 + jsonBytes.length, 20 + jsonBytes.length + jsonPad); // spaces
40
+ if (bin) {
41
+ const at = 12 + jsonChunk;
42
+ view.setUint32(at, bin.length + binPad, true);
43
+ view.setUint32(at + 4, CHUNK_BIN, true);
44
+ out.set(bin, at + 8); // padding bytes are already zero
45
+ }
46
+ return out;
47
+ }
48
+ /** Parse a GLB container. Throws `GlbError` on anything that is not GLB 2.0. */
49
+ export function parseGlb(bytes) {
50
+ if (bytes.length < 20)
51
+ throw new GlbError("File is too small to be a GLB.");
52
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
53
+ if (view.getUint32(0, true) !== GLB_MAGIC)
54
+ throw new GlbError("Not a GLB file (bad magic).");
55
+ if (view.getUint32(4, true) !== 2)
56
+ throw new GlbError("Only glTF 2.0 GLB files are supported.");
57
+ const declared = view.getUint32(8, true);
58
+ if (declared > bytes.length)
59
+ throw new GlbError("GLB header length exceeds the file size.");
60
+ let json = null;
61
+ let bin = null;
62
+ let offset = 12;
63
+ while (offset + 8 <= declared) {
64
+ const length = view.getUint32(offset, true);
65
+ const type = view.getUint32(offset + 4, true);
66
+ const start = offset + 8;
67
+ if (start + length > declared)
68
+ throw new GlbError("GLB chunk overruns the file.");
69
+ const chunk = bytes.subarray(start, start + length);
70
+ if (type === CHUNK_JSON && json === null) {
71
+ try {
72
+ json = JSON.parse(new TextDecoder("utf-8").decode(chunk));
73
+ }
74
+ catch {
75
+ throw new GlbError("GLB JSON chunk is not valid JSON.");
76
+ }
77
+ }
78
+ else if (type === CHUNK_BIN && bin === null) {
79
+ bin = chunk;
80
+ }
81
+ offset = start + length;
82
+ }
83
+ if (!json || typeof json !== "object" || !json.asset) {
84
+ throw new GlbError("GLB has no glTF JSON chunk.");
85
+ }
86
+ return { json, bin };
87
+ }
88
+ const IDENTITY = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
89
+ function multiply(a, b) {
90
+ const out = new Array(16).fill(0);
91
+ for (let col = 0; col < 4; col++) {
92
+ for (let row = 0; row < 4; row++) {
93
+ let sum = 0;
94
+ for (let k = 0; k < 4; k++)
95
+ sum += a[k * 4 + row] * b[col * 4 + k];
96
+ out[col * 4 + row] = sum;
97
+ }
98
+ }
99
+ return out;
100
+ }
101
+ function localMatrix(node) {
102
+ if (Array.isArray(node.matrix) && node.matrix.length === 16)
103
+ return node.matrix;
104
+ const [tx, ty, tz] = node.translation ?? [0, 0, 0];
105
+ const [qx, qy, qz, qw] = node.rotation ?? [0, 0, 0, 1];
106
+ const [sx, sy, sz] = node.scale ?? [1, 1, 1];
107
+ const xx = qx * qx;
108
+ const yy = qy * qy;
109
+ const zz = qz * qz;
110
+ const xy = qx * qy;
111
+ const xz = qx * qz;
112
+ const yz = qy * qz;
113
+ const wx = qw * qx;
114
+ const wy = qw * qy;
115
+ const wz = qw * qz;
116
+ return [
117
+ (1 - 2 * (yy + zz)) * sx,
118
+ 2 * (xy + wz) * sx,
119
+ 2 * (xz - wy) * sx,
120
+ 0,
121
+ 2 * (xy - wz) * sy,
122
+ (1 - 2 * (xx + zz)) * sy,
123
+ 2 * (yz + wx) * sy,
124
+ 0,
125
+ 2 * (xz + wy) * sz,
126
+ 2 * (yz - wx) * sz,
127
+ (1 - 2 * (xx + yy)) * sz,
128
+ 0,
129
+ tx,
130
+ ty,
131
+ tz,
132
+ 1,
133
+ ];
134
+ }
135
+ function transformPoint(m, p) {
136
+ return [
137
+ m[0] * p[0] + m[4] * p[1] + m[8] * p[2] + m[12],
138
+ m[1] * p[0] + m[5] * p[1] + m[9] * p[2] + m[13],
139
+ m[2] * p[0] + m[6] * p[1] + m[10] * p[2] + m[14],
140
+ ];
141
+ }
142
+ /** Root node indices of the default scene (or every node that is no one's child). */
143
+ function sceneRoots(json) {
144
+ const scenes = json.scenes ?? [];
145
+ const sceneIndex = typeof json.scene === "number" ? json.scene : 0;
146
+ const scene = scenes[sceneIndex];
147
+ if (scene?.nodes)
148
+ return scene.nodes;
149
+ const nodes = json.nodes ?? [];
150
+ const children = new Set(nodes.flatMap((n) => n.children ?? []));
151
+ return nodes.map((_, i) => i).filter((i) => !children.has(i));
152
+ }
153
+ /**
154
+ * World-space axis-aligned bounding box of the default scene, in metres.
155
+ * Returns `null` when no mesh primitive carries `POSITION` min/max.
156
+ */
157
+ export function measureGlb(json) {
158
+ const nodes = json.nodes ?? [];
159
+ const meshes = json.meshes ?? [];
160
+ const accessors = json.accessors ?? [];
161
+ const min = [Infinity, Infinity, Infinity];
162
+ const max = [-Infinity, -Infinity, -Infinity];
163
+ let found = false;
164
+ const visiting = new Set();
165
+ const visit = (index, parent) => {
166
+ const node = nodes[index];
167
+ if (!node || visiting.has(index))
168
+ return; // malformed cycle guard
169
+ visiting.add(index);
170
+ const world = multiply(parent, localMatrix(node));
171
+ const mesh = typeof node.mesh === "number" ? meshes[node.mesh] : undefined;
172
+ for (const primitive of mesh?.primitives ?? []) {
173
+ const accessor = accessors[primitive.attributes?.POSITION];
174
+ const lo = accessor?.min;
175
+ const hi = accessor?.max;
176
+ if (!Array.isArray(lo) || !Array.isArray(hi) || lo.length < 3 || hi.length < 3)
177
+ continue;
178
+ for (let corner = 0; corner < 8; corner++) {
179
+ const p = transformPoint(world, [
180
+ corner & 1 ? hi[0] : lo[0],
181
+ corner & 2 ? hi[1] : lo[1],
182
+ corner & 4 ? hi[2] : lo[2],
183
+ ]);
184
+ for (let axis = 0; axis < 3; axis++) {
185
+ if (p[axis] < min[axis])
186
+ min[axis] = p[axis];
187
+ if (p[axis] > max[axis])
188
+ max[axis] = p[axis];
189
+ }
190
+ found = true;
191
+ }
192
+ }
193
+ for (const child of node.children ?? [])
194
+ visit(child, world);
195
+ visiting.delete(index);
196
+ };
197
+ for (const root of sceneRoots(json))
198
+ visit(root, IDENTITY);
199
+ return found ? { min, max } : null;
200
+ }
201
+ export function dimensionsOf(bounds) {
202
+ return {
203
+ width: bounds.max[0] - bounds.min[0],
204
+ height: bounds.max[1] - bounds.min[1],
205
+ depth: bounds.max[2] - bounds.min[2],
206
+ };
207
+ }
208
+ /**
209
+ * Uniformly rescale the default scene by `factor`, by parenting its root
210
+ * nodes under one new node carrying `scale: [f, f, f]`. Vertex data is left
211
+ * untouched, so this is safe for compressed or quantized meshes.
212
+ * Returns a new document; the input is not mutated.
213
+ */
214
+ export function scaleGlbDocument(json, factor) {
215
+ const copy = structuredClone(json);
216
+ const nodes = copy.nodes ?? [];
217
+ const roots = sceneRoots(copy);
218
+ const wrapperIndex = nodes.length;
219
+ nodes.push({ name: "sceneview_scale_root", scale: [factor, factor, factor], children: roots });
220
+ copy.nodes = nodes;
221
+ const scenes = copy.scenes && copy.scenes.length > 0 ? copy.scenes : [{}];
222
+ const sceneIndex = typeof copy.scene === "number" ? copy.scene : 0;
223
+ scenes[sceneIndex] = { ...scenes[sceneIndex], nodes: [wrapperIndex] };
224
+ copy.scenes = scenes;
225
+ copy.scene = sceneIndex;
226
+ return copy;
227
+ }
package/dist/server.js CHANGED
@@ -190,7 +190,11 @@ export function createSceneViewServer(options = {}) {
190
190
  // The dispatcher returns the narrower SceneView `ToolResult` shape, which
191
191
  // structurally matches the MCP SDK's `CallToolResult` but TS can't prove
192
192
  // it (the SDK's zod-derived type has additional optional members).
193
- const result = await dispatchTool(toolName, args);
193
+ // `surface` lets a tool refuse what only makes sense on the user's own
194
+ // machine (`generate_3d_model`'s `save_to_path` writes to local disk).
195
+ const result = await dispatchTool(toolName, args, {
196
+ extras: { surface: remote ? "remote" : "stdio" },
197
+ });
194
198
  return negotiateResult(result);
195
199
  });
196
200
  return server;
@@ -10,7 +10,7 @@
10
10
  import { DEBUG_CATEGORIES } from "../debug-issue.js";
11
11
  import { PLATFORM_IDS } from "../platform-setup.js";
12
12
  import { SAMPLE_IDS, SAMPLES } from "../samples.js";
13
- import { WIDGET_3D_VIEWER_URI } from "../widgets.js";
13
+ import { WIDGET_3D_VIEWER_URI, WIDGET_SHOW_IN_SPACE_URI } from "../widgets.js";
14
14
  export const TOOL_DEFINITIONS = [
15
15
  {
16
16
  name: "get_sample",
@@ -680,27 +680,97 @@ export const TOOL_DEFINITIONS = [
680
680
  },
681
681
  {
682
682
  name: "generate_3d_model",
683
- description: 'Generates a brand-new 3D model (GLB) from a text prompt OR a source image, with TRELLIS.2 on Runware or with Tripo AI — use this when `search_models` finds no suitable existing asset and the user needs a custom one ("a low-poly cactus in a striped pot"). Returns a direct GLB download URL (expires ~5 minutes — download it immediately and self-host it) plus license/attribution metadata, ready for `rememberModelInstance(modelLoader, ...)` and AR placement. Providers (BYOK — billed to the USER\'S own account, nothing is charged by SceneView): "trellis" = Microsoft TRELLIS.2 on Runware, needs `RUNWARE_API_KEY` (my.runware.ai/keys), roughly $0.01-0.03 per model as of November 2026, ~40-90 s, text→3D renders a FLUX concept image first; "tripo" = Tripo AI, needs `TRIPO_API_KEY` (platform.tripo3d.ai/api-keys), roughly $0.10-0.25 per fast and ~$0.41 per hd generation as of July 2026. Without `provider`, Tripo is used when `TRIPO_API_KEY` is set, otherwise TRELLIS.2 when `RUNWARE_API_KEY` is set. Quality tiers: "fast" (default — Tripo P1 low-poly, or TRELLIS.2 at 1024³) or "hd" (Tripo H3.1 quad topology, or TRELLIS.2 at 1536³ — slower, pricier). If no key is set, the tool returns setup instructions for both providers.',
683
+ description: 'Generates a brand-new 3D model (GLB) at real-world scale — use this when `search_models` finds no suitable existing asset. Three modes, all free on SceneView\'s side (there is no paid tier and no SceneView-hosted generation API): (1) provider "parametric" — deterministic primitives (box, cylinder, cone, sphere, torus) from a structured `parts` list, built locally with NO API key and no network; pick it for furniture blockouts, props and placeholders whose dimensions are known ("a 1.2 × 0.75 × 0.6 m desk"). Passing `parts` without `provider` selects it. (2) "trellis" — Microsoft TRELLIS.2 on Runware, BYOK `RUNWARE_API_KEY` (my.runware.ai/keys), roughly $0.01-0.03 per model as of November 2026, ~40-90 s, text→3D renders a FLUX concept image first. (3) "tripo" — Tripo AI, BYOK `TRIPO_API_KEY` (platform.tripo3d.ai/api-keys), roughly $0.10-0.25 per fast and ~$0.41 per hd generation as of July 2026. Provider generations are billed to the USER\'S own account. Without `provider` or `parts`, Tripo is used when `TRIPO_API_KEY` is set, otherwise TRELLIS.2 when `RUNWARE_API_KEY` is set; with no key the tool returns setup instructions. Output is in metres (glTF\'s unit): the result reports the model\'s size, and `targetSize` (e.g. { heightMeters: 0.75 }) rescales it uniformly so that dimension matches. `save_to_path` writes the GLB to an absolute local `.glb` path (local package only; the parent directory must exist; an existing file is never replaced unless `overwrite: true`). Without `save_to_path`, provider mode returns a temporary GLB download URL (expires ~5 minutes) and parametric mode returns the GLB base64 in `structuredContent.glbBase64`. Load the result with `rememberModelInstance(modelLoader, ...)`.',
684
684
  inputSchema: {
685
685
  type: "object",
686
686
  properties: {
687
+ provider: {
688
+ type: "string",
689
+ enum: ["parametric", "trellis", "tripo"],
690
+ description: '"parametric": deterministic primitives from `parts`, no key, no network. "trellis": Microsoft TRELLIS.2 on Runware (`RUNWARE_API_KEY`, a few US cents per model, image-faithful PBR mesh). "tripo": Tripo AI (`TRIPO_API_KEY`). Omit to use "parametric" when `parts` is given, otherwise whichever key is configured (Tripo first).',
691
+ },
687
692
  prompt: {
688
693
  type: "string",
689
- description: 'Text description of the model to generate (text→3D), e.g. "a low-poly cactus in a striped pot". Max 1024 characters. Provide exactly one of `prompt` or `imageUrl`.',
694
+ description: 'Provider modes: text description of the model to generate (text→3D), e.g. "a low-poly cactus in a striped pot". Max 1024 characters. Provide exactly one of `prompt` or `imageUrl`.',
690
695
  },
691
696
  imageUrl: {
692
697
  type: "string",
693
- description: "Public HTTPS URL of a source image to convert to 3D (image→3D). JPEG or PNG, max 20 MB. Provide exactly one of `prompt` or `imageUrl`.",
698
+ description: "Provider modes: public HTTPS URL of a source image to convert to 3D (image→3D). JPEG or PNG, max 20 MB. Provide exactly one of `prompt` or `imageUrl`.",
694
699
  },
695
700
  quality: {
696
701
  type: "string",
697
702
  enum: ["fast", "hd"],
698
- description: '"fast" (default): Tripo P1 low-poly (~25-30 s) or TRELLIS.2 1024³ — cheap, AR-ready. "hd": Tripo H3.1 quad topology (up to ~100 s) or TRELLIS.2 1536³ — more detail, higher cost.',
703
+ description: 'Provider modes. "fast" (default): Tripo P1 low-poly (~25-30 s) or TRELLIS.2 1024³ — cheap, AR-ready. "hd": Tripo H3.1 quad topology (up to ~100 s) or TRELLIS.2 1536³ — more detail, higher cost.',
699
704
  },
700
- provider: {
705
+ parts: {
706
+ type: "array",
707
+ maxItems: 64,
708
+ description: "Parametric mode: the primitives the model is assembled from (union by composition, one node per part; no boolean subtraction). Sizes and positions are in `units`; y is up; `position` is the centre of the part.",
709
+ items: {
710
+ type: "object",
711
+ properties: {
712
+ shape: { type: "string", enum: ["box", "cylinder", "cone", "sphere", "torus"] },
713
+ name: { type: "string" },
714
+ size: {
715
+ type: "array",
716
+ items: { type: "number" },
717
+ minItems: 3,
718
+ maxItems: 3,
719
+ description: "box: [width (x), height (y), depth (z)].",
720
+ },
721
+ radius: {
722
+ type: "number",
723
+ description: "cylinder / cone / sphere: radius. torus: ring radius (centre of the tube).",
724
+ },
725
+ radiusTop: {
726
+ type: "number",
727
+ description: "cylinder: top radius (defaults to `radius`; 0 = cone).",
728
+ },
729
+ height: { type: "number", description: "cylinder / cone: height along y." },
730
+ tube: { type: "number", description: "torus: tube radius." },
731
+ position: {
732
+ type: "array",
733
+ items: { type: "number" },
734
+ minItems: 3,
735
+ maxItems: 3,
736
+ description: "[x, y, z] centre of the part.",
737
+ },
738
+ rotation: {
739
+ type: "array",
740
+ items: { type: "number" },
741
+ minItems: 3,
742
+ maxItems: 3,
743
+ description: "Euler degrees [x, y, z], applied X then Y then Z.",
744
+ },
745
+ color: { type: "string", description: '"#rrggbb" base colour.' },
746
+ metallic: { type: "number", minimum: 0, maximum: 1 },
747
+ roughness: { type: "number", minimum: 0, maximum: 1 },
748
+ },
749
+ required: ["shape"],
750
+ },
751
+ },
752
+ units: {
753
+ type: "string",
754
+ enum: ["m", "cm", "mm", "in", "ft"],
755
+ description: 'Parametric mode: unit of every size and position in `parts` (default "m"). The GLB is always written in metres.',
756
+ },
757
+ targetSize: {
758
+ type: "object",
759
+ description: "Optional real-world size: set exactly one key and the model is scaled uniformly so that dimension matches, in metres. Example: { heightMeters: 0.75 }.",
760
+ properties: {
761
+ heightMeters: { type: "number" },
762
+ widthMeters: { type: "number" },
763
+ depthMeters: { type: "number" },
764
+ maxDimensionMeters: { type: "number" },
765
+ },
766
+ },
767
+ save_to_path: {
701
768
  type: "string",
702
- enum: ["trellis", "tripo"],
703
- description: '"trellis": Microsoft TRELLIS.2 on Runware (`RUNWARE_API_KEY`, a few US cents per model, image-faithful PBR mesh). "tripo": Tripo AI (`TRIPO_API_KEY`). Omit to pick whichever key is configured (Tripo first).',
769
+ description: "Optional absolute path of a `.glb` file to write the model to (local package only). The parent directory must already exist. Validated before any generation runs.",
770
+ },
771
+ overwrite: {
772
+ type: "boolean",
773
+ description: "Allow `save_to_path` to replace an existing regular file. Default false: an existing file is never touched.",
704
774
  },
705
775
  },
706
776
  required: [],
@@ -708,7 +778,8 @@ export const TOOL_DEFINITIONS = [
708
778
  annotations: {
709
779
  readOnlyHint: false,
710
780
  openWorldHint: true,
711
- destructiveHint: false,
781
+ // `save_to_path` + `overwrite: true` can replace a local file.
782
+ destructiveHint: true,
712
783
  title: "Generate a 3D model",
713
784
  },
714
785
  },
@@ -824,10 +895,17 @@ export const TOOL_DEFINITIONS = [
824
895
  label: { type: "string" },
825
896
  sizeCm: { type: "array", items: { type: "number" }, minItems: 3, maxItems: 3 },
826
897
  placement: { type: "string", enum: ["floor", "table"] },
898
+ dimensionSource: { type: "string", enum: ["user", "estimated"] },
827
899
  },
828
- required: ["url", "label", "sizeCm", "placement"],
900
+ required: ["url", "label", "sizeCm", "placement", "dimensionSource"],
829
901
  additionalProperties: false,
830
902
  },
903
+ _meta: {
904
+ ui: { resourceUri: WIDGET_SHOW_IN_SPACE_URI },
905
+ "openai/outputTemplate": WIDGET_SHOW_IN_SPACE_URI,
906
+ "openai/toolInvocation/invoking": "Drawing size preview",
907
+ "openai/toolInvocation/invoked": "Size preview ready",
908
+ },
831
909
  annotations: {
832
910
  readOnlyHint: true,
833
911
  openWorldHint: false,
@@ -23,7 +23,7 @@ import { fetchAndroidDoc, formatAndroidDocsFetch, formatAndroidDocsSearch, searc
23
23
  import { formatArtifactResponse, generateArtifact, validateArtifactInput, } from "../artifact.js";
24
24
  import { autoDetectIssue, DEBUG_CATEGORIES, getDebugGuide, } from "../debug-issue.js";
25
25
  import { COLLISION_GUIDE, MATERIAL_GUIDE, MODEL_OPTIMIZATION_GUIDE, WEB_RENDERING_GUIDE, } from "../extra-guides.js";
26
- import { formatGenerateResult, generateModel, } from "../generate-model.js";
26
+ import { runGenerate3dModel } from "../generate-model-tool.js";
27
27
  import { formatGeneratedScene, generateScene } from "../generate-scene.js";
28
28
  import { LLMS_TXT } from "../generated/llms-txt.js";
29
29
  import { IOS_NODE_TYPE_COUNT, LATEST_SCENEVIEW_RELEASE } from "../generated/version.js";
@@ -37,7 +37,7 @@ import { getSample, SAMPLES } from "../samples.js";
37
37
  import { formatSearchResults, searchModels } from "../search-models.js";
38
38
  import { buildSpatialAnswerSpec, spatialAnswerUrl } from "../spatial-answer-link.js";
39
39
  import { formatValidationReport, validateCode } from "../validator.js";
40
- import { WIDGET_3D_VIEWER_URI } from "../widgets.js";
40
+ import { WIDGET_3D_VIEWER_URI, WIDGET_SHOW_IN_SPACE_URI } from "../widgets.js";
41
41
  // ─── Legal disclaimer (identical to index.ts 4.0.0) ─────────────────────
42
42
  const DISCLAIMER = "\n\n---\n*Generated code suggestion. Review before use in production. See [TERMS.md](https://github.com/sceneview/sceneview/blob/main/mcp/TERMS.md).*";
43
43
  function withDisclaimer(content) {
@@ -63,10 +63,11 @@ const NODE_SECTIONS = parseNodeSections(API_DOCS);
63
63
  * @param toolName MCP tool name, e.g. `"get_sample"`.
64
64
  * @param args Arguments bag from the MCP client. `undefined` and
65
65
  * `null` are both tolerated.
66
- * @param _ctx Optional context (user, request id). Currently
67
- * unused by any handler, reserved for future tool wiring.
66
+ * @param ctx Optional context (user, request id, `extras.surface`).
67
+ * `generate_3d_model` reads it to refuse `save_to_path`
68
+ * on the shared remote surface.
68
69
  */
69
- export async function dispatchTool(toolName, args, _ctx = {}) {
70
+ export async function dispatchTool(toolName, args, ctx = {}) {
70
71
  switch (toolName) {
71
72
  // ── get_sample ────────────────────────────────────────────────────────────
72
73
  case "get_sample": {
@@ -854,17 +855,8 @@ export async function dispatchTool(toolName, args, _ctx = {}) {
854
855
  }
855
856
  // ── generate_3d_model ────────────────────────────────────────────────────
856
857
  case "generate_3d_model": {
857
- const genResult = await generateModel({
858
- prompt: args?.prompt,
859
- imageUrl: args?.imageUrl,
860
- quality: args?.quality,
861
- provider: args?.provider,
862
- });
863
- const genText = formatGenerateResult(genResult);
864
- return {
865
- content: withDisclaimer([{ type: "text", text: genText }]),
866
- isError: genResult.ok ? undefined : true,
867
- };
858
+ const genResult = await runGenerate3dModel(args, ctx);
859
+ return { ...genResult, content: withDisclaimer(genResult.content) };
868
860
  }
869
861
  // ── analyze_project ───────────────────────────────────────────────────────
870
862
  case "analyze_project": {
@@ -948,7 +940,14 @@ export async function dispatchTool(toolName, args, _ctx = {}) {
948
940
  text: `${spec.label}: ${sizeCm.join(" × ")} cm — ${url}\nOpens at real scale in the SceneView app on Android; without the app, the page shows the size.`,
949
941
  },
950
942
  ],
951
- structuredContent: { url, label: spec.label, sizeCm, placement: spec.placement },
943
+ structuredContent: {
944
+ url,
945
+ label: spec.label,
946
+ sizeCm,
947
+ placement: spec.placement,
948
+ dimensionSource: spec.dimensionSource,
949
+ },
950
+ _meta: { ui: { resourceUri: WIDGET_SHOW_IN_SPACE_URI } },
952
951
  };
953
952
  }
954
953
  catch (error) {