Skip to content

3D engine that AI agents drive

Accept alphaMode add in the MCP material schema (#2091)

Nguyen Xuan An41193ccc759b
diff --git a/changes/2091.md b/changes/2091.md
new file mode 100644
index 00000000..88d4f529
--- /dev/null
+++ b/changes/2091.md
@@ -0,0 +1 @@
+- `scene_create` and `scene_apply` accept material `alphaMode: "add"` (additive light), as `scene_capabilities` topic `alphaModes` already listed; both read one list (#2091)
diff --git a/docs/agent-scene.md b/docs/agent-scene.md
index 1c8765ec..fa343d5e 100644
--- a/docs/agent-scene.md
+++ b/docs/agent-scene.md
@@ -107,7 +107,7 @@ The defaults are `surface`, `[0.5, 0.5, 0.5]`, `0`, `0.5`, `0`, opacity `1`, `op
The tag can be `surface`, `unlit`, `liquid`, `foam`, `water`, `foliage` or `grass` (the last two sway in `environment.wind`) and remains fixed during editing.
`liquid` refracts and tints what lies behind it: its color is the light one metre lets through, so `[0.56, 0.84, 0.88]` is clear water. `foam` draws soft blended droplets.
`water` is a flat mirror sheet (a plane or thin box). The largest one sets the water level: everything below it fades by `exp(-absorption * depth)` per colour channel (`absorption` is RGB per metre), and its shadows are lifted and softened with depth times `turbidity` (0 clear to 1 murky). `waterPreset` fills both: `lake` (default), `sea` or `river`. A shadow on the surface is faint and never darkens the reflection; give the sheet an `opacity` below one when the bed should show. The sun's leg to a bed is bent at n = 1.33 and absorbed over `depth / cos(theta_t)`, so a clear lake keeps little shadow contrast on a bed 4 m down, and a murky river keeps about a quarter.
-Any `opacity` below one draws the material blended after opaque geometry, which suits glass, windows and visors. `alphaMode` accepts `opaque`, `blend` or `add` (additive light for sparks, trails and glow); cutout masking needs a texture and is not available in procedural recipes.
+Any `opacity` below one draws the material blended after opaque geometry, which suits glass, windows and visors. `alphaMode` accepts `opaque`, `blend` or `add` (additive light for sparks, trails and glow); the MCP tools accept the same three, and `scene_capabilities` topic `alphaModes` lists them. Cutout masking (`mask`) needs a texture and is not available in procedural recipes.
`doubleSided` draws and lights both faces of thin sheets.
Changing the tag, opacity, blending, sidedness or pattern replaces the affected parts in the renderer; color, metallic, roughness and emission edits keep them.
Set liquid optics with `environment.liquid`: `thickness`, `ior`, `refraction`, `scattering`, `foamOpacity` and `foamSoftness`.
diff --git a/scripts/mcp-server.mjs b/scripts/mcp-server.mjs
index c92fb7d4..c37f42b5 100644
--- a/scripts/mcp-server.mjs
+++ b/scripts/mcp-server.mjs
@@ -16,7 +16,7 @@ import packageMetadata from '../package.json' with { type: 'json' };
import { MODIFIER_OPERATIONS } from '../src/mesh-operations.js';
import { VIEW_TRANSFORM_NAMES, LOOK_NAMES } from '../src/view-transform-names.js';
import { BUNDLED_ENVIRONMENT_NAMES, BUNDLED_CUBE_LOOK_NAMES, CATALOG_FILE_ID } from '../src/look-catalog.js';
-import { MATERIAL_PATTERN_TYPES, MATERIAL_MAPPINGS, LIGHTING_SETUP_NAMES, RENDER_PASS_NAMES, RENDER_OUTPUT_FORMATS, MAXIMUM_JOB_FPS, VIDEO_ENCODERS, MAXIMUM_JOB_SIDE, maximumMemoryMiB, memoryRangeError, MAXIMUM_STILLS_FRAMES } from '../src/agent-scene-capabilities.js';
+import { MATERIAL_PATTERN_TYPES, MATERIAL_MAPPINGS, LIGHTING_SETUP_NAMES, RENDER_PASS_NAMES, RENDER_OUTPUT_FORMATS, MAXIMUM_JOB_FPS, VIDEO_ENCODERS, MAXIMUM_JOB_SIDE, maximumMemoryMiB, memoryRangeError, MAXIMUM_STILLS_FRAMES, RECIPE_ALPHA_MODES } from '../src/agent-scene-capabilities.js';
import { MATERIAL_LAYER_SCALAR_RANGES, MATERIAL_LAYER_COLOR_RANGES } from '../src/material-layers.js';
import { SUBSURFACE_RANGES } from '../src/subsurface-limits.js';
import { responseFormatField, chosenFormat, conciseReview, conciseJobStatus, conciseJobResult, conciseCapabilities } from './mcp-response-format.mjs';
@@ -187,7 +187,7 @@ const materialFields = {
emission: nonnegative.optional().describe('Emission multiplier. Backend checks Float32 radiance products.'),
emissiveColor: z.tuple([nonnegative, nonnegative, nonnegative]).optional().describe('Independent linear RGB emission color.'),
opacity: unit.optional().describe('Surface opacity. Any value below one draws the material blended (glass, windows, visors).'),
- alphaMode: z.enum(['opaque', 'blend']).optional().describe('blend draws after opaque geometry, sorted back to front.'),
+ alphaMode: z.enum(RECIPE_ALPHA_MODES).optional().describe('blend draws after opaque geometry, sorted back to front; add adds its light to what is behind it.'),
doubleSided: z.boolean().optional().describe('Draw and light both faces (thin sheets, leaves, cloth).'),
aov: z.union([unit, color]).optional(),
};
diff --git a/tests/mcp-alpha-modes.test.js b/tests/mcp-alpha-modes.test.js
new file mode 100644
index 00000000..4d488c97
--- /dev/null
+++ b/tests/mcp-alpha-modes.test.js
@@ -0,0 +1,52 @@
+import './support/load-agent-scene-modules.mjs';
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import { Client } from '@modelcontextprotocol/client';
+import { InMemoryTransport } from '@modelcontextprotocol/server';
+import { createAgentMcpServer } from '../scripts/mcp-server.mjs';
+import { AGENT_SCENE_CAPABILITIES, RECIPE_ALPHA_MODES } from '../src/agent-scene-capabilities.js';
+
+function recipeWithAlphaMode(alphaMode) {
+ return {
+ format: 'crucible.scene',
+ schemaVersion: 1,
+ geometries: [{ id: 'cube', type: 'box', bevel: 0 }],
+ materials: [{ id: 'm', color: [0.5, 0.5, 0.5], alphaMode }],
+ nodes: [{ id: 'mesh', geometry: 'cube', material: 'm' }],
+ };
+}
+
+async function connectedClient(context) {
+ const acceptedRecipes = [];
+ const runtime = {
+ async close() {},
+ async capabilities() { return { scene: {}, phase: 'idle' }; },
+ async create({ recipe }) { acceptedRecipes.push(recipe); return { sessionId: 'session', revision: 1 }; },
+ };
+ const server = createAgentMcpServer(runtime);
+ const client = new Client({ name: 'crucible-alpha-modes-test', version: '1' });
+ const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
+ await server.connect(serverTransport);
+ await client.connect(clientTransport);
+ context.after(async () => {
+ await client.close();
+ await server.close();
+ });
+ return { client, acceptedRecipes };
+}
+
+test('scene_capabilities alphaModes lists exactly the modes the recipe schema accepts', async context => {
+ assert.deepEqual(AGENT_SCENE_CAPABILITIES.alphaModes, [...RECIPE_ALPHA_MODES]);
+ const { client, acceptedRecipes } = await connectedClient(context);
+ for (const alphaMode of AGENT_SCENE_CAPABILITIES.alphaModes) {
+ const result = await client.callTool({ name: 'scene_create', arguments: { recipe: recipeWithAlphaMode(alphaMode) } });
+ assert.notEqual(result.isError, true, `scene_capabilities lists alphaMode "${alphaMode}" but scene_create rejects it: ${JSON.stringify(result.content)}`);
+ }
+ assert.equal(acceptedRecipes.length, AGENT_SCENE_CAPABILITIES.alphaModes.length);
+});
+
+test('scene_create rejects an alphaMode that scene_capabilities does not list', async context => {
+ const { client } = await connectedClient(context);
+ const result = await client.callTool({ name: 'scene_create', arguments: { recipe: recipeWithAlphaMode('mask') } }).catch(error => ({ isError: true, content: error.message }));
+ assert.equal(result.isError, true);
+});