3D engine that AI agents drive
JavaScript 3d3d-engineagentic-aiai-agentsblenderclaude-codegame-enginegaussian-splattinggltfjavascriptmcpmcp-servermodel-context-protocolpath-tracerpath-tracingpbrrenderingthreejs-alternativewebgl2webgpu
Accept material dispersion in the MCP schema and check every listed layer (#2090)
Nguyen Xuan An8875da933b0c
diff --git a/changes/2090.md b/changes/2090.mdnew file mode 100644index 00000000..064de835--- /dev/null+++ b/changes/2090.md@@ -0,0 +1 @@+- `scene_create`, `scene_apply` and `scene_capabilities materialFields` now accept the material `dispersion` layer that `materialLayers` already listed, and a test checks every listed material layer against the MCP schema (#2090).diff --git a/docs/material-maps.md b/docs/material-maps.mdindex 0947feae..8786ee13 100644--- a/docs/material-maps.md+++ b/docs/material-maps.md@@ -176,6 +176,7 @@ A material on a standard tag (`surface` in recipes, `gltf` and `armor` in code)| `transmission` | 0 to 1 | The share of light that passes through. The material draws after the opaque scene and refracts it. || `thickness` | 0 to 1000 metres | How far light travels inside. 0 is a thin sheet that does not bend the view. || `ior` | 1 to 2.5 | Index of refraction. It bends transmitted light and sets the reflectance at normal incidence, 4 percent at 1.5. |+| `dispersion` | 0 to 10 | Colour fringes through glass, 20 over the Abbe number (diamond 0.36), as in `KHR_materials_dispersion`. The path tracer renders it; the rasterizer ignores it. || `attenuationColor`, `attenuationDistance` | colour 0 to 1, distance above 0 | The colour light keeps after that many metres inside. Leave the distance out for no absorption. || `sheenColor`, `sheenRoughness` | colour 0 to 1, 0 to 1 | A soft glow at grazing angles for cloth. Black is off. || `specular`, `specularColor` | 0 to 4, colour 0 to 1000 | Strength and tint of the non-metal reflection. |diff --git a/scripts/mcp-server.mjs b/scripts/mcp-server.mjsindex c92fb7d4..5bc3ca22 100644--- a/scripts/mcp-server.mjs+++ b/scripts/mcp-server.mjs@@ -140,6 +140,7 @@ const materialLayerFields = {transmission: layerNumber('transmission'),thickness: layerNumber('thickness'),ior: layerNumber('ior'),+ dispersion: layerNumber('dispersion'),attenuationColor: layerColor('attenuationColor'),attenuationDistance: z.number().positive('attenuationDistance must be above 0. Leave it out for no absorption.').max(3.4e38).describe('Metres to reach attenuationColor.').optional(),sheenColor: layerColor('sheenColor'),@@ -193,7 +194,7 @@ const materialFields = {};const materialTag = z.enum(['surface', 'unlit', 'liquid', 'foam', 'foliage', 'grass', 'water']).optional().describe('Surface kind; liquid, foam, foliage, grass and water change how it renders: see scene_capabilities materialTags and water.');const materialCore = coreOf(materialFields, ['color', 'metallic', 'roughness', 'emission', 'opacity']);-const materialMore = 'More fields: tag, alphaMode, doubleSided, emissiveColor, map, pattern, subsurface, snippet, wear, retro, waterPreset, absorption, turbidity and the layers clearcoat, clearcoatRoughness, transmission, thickness, ior, attenuationColor, attenuationDistance, sheenColor, sheenRoughness, specular, specularColor, anisotropy, anisotropyRotation, iridescence, iridescenceIor, iridescenceThickness, toon; see scene_capabilities materialFields.';+const materialMore = 'More fields: tag, alphaMode, doubleSided, emissiveColor, map, pattern, subsurface, snippet, wear, retro, waterPreset, absorption, turbidity and the layers clearcoat, clearcoatRoughness, transmission, thickness, ior, dispersion, attenuationColor, attenuationDistance, sheenColor, sheenRoughness, specular, specularColor, anisotropy, anisotropyRotation, iridescence, iridescenceIor, iridescenceThickness, toon; see scene_capabilities materialFields.';const materialListed = (strictSchema, description, extraCore) => listed('materialFields', strictSchema, `${description} ${materialMore}`, { ...extraCore, ...materialCore });const liquidOptics = z.strictObject({thickness: z.number().min(0).max(100).optional().describe('Metres of liquid where it faces the camera.'),diff --git a/tests/mcp-material-layer-schema.test.js b/tests/mcp-material-layer-schema.test.jsnew file mode 100644index 00000000..2b2dfb05--- /dev/null+++ b/tests/mcp-material-layer-schema.test.js@@ -0,0 +1,57 @@+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 } from '../src/agent-scene-capabilities.js';++// scene_capabilities lists the material layers; the MCP schema must take every one of them (#2090: dispersion was listed+// but scene_create answered Unrecognized key). alphaMode is not a layer field, so #2091 is not covered here.++async function connectClient() {+ const server = createAgentMcpServer({ async close() {}, async capabilities() { return { scene: AGENT_SCENE_CAPABILITIES, phase: 'idle' }; } });+ const client = new Client({ name: 'crucible-material-layer-schema-test', version: '1' });+ const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();+ await server.connect(serverTransport);+ await client.connect(clientTransport);+ return { client, server };+}++function exampleValue(range) {+ if (Array.isArray(range) && range.length === 2 && typeof range[0] === 'number') {+ return range[0] + (range[1] - range[0]) / 4;+ }+ if (Array.isArray(range)) return [0.5, 0.5, 0.5];+ return 1;+}++function schemaErrorText(result) {+ return result.isError ? JSON.stringify(result.content) : '';+}++test('every material layer scene_capabilities lists is in materialFields and accepted by scene_create and set-material', async () => {+ const { client, server } = await connectClient();+ const layers = (await client.callTool({ name: 'scene_capabilities', arguments: { topic: 'materialLayers' } })).structuredContent.value;+ const listedFields = (await client.callTool({ name: 'scene_capabilities', arguments: { topic: 'materialFields' } })).structuredContent.fields;+ const layerNames = Object.keys(layers);+ assert.ok(layerNames.includes('dispersion'), 'materialLayers lists dispersion');+ const problems = [];+ for (const field of layerNames) {+ const { range } = layers[field];+ const value = exampleValue(range);+ if (!listedFields[`${field}?`]) problems.push(`materialFields has no ${field}`);+ const created = await client.callTool({+ name: 'scene_create',+ arguments: { recipe: { format: 'crucible.scene', schemaVersion: 1, materials: [{ id: 'm', color: [1, 1, 1], [field]: value }] } },+ });+ if (/Unrecognized key/.test(schemaErrorText(created))) problems.push(`scene_create rejects ${field}`);+ const edited = await client.callTool({+ name: 'scene_apply',+ arguments: { operations: [{ type: 'set-material', id: 'm', [field]: value }] },+ });+ if (/Unrecognized key/.test(schemaErrorText(edited))) problems.push(`set-material rejects ${field}`);+ }+ assert.deepEqual(problems, []);+ await client.close();+ await server.close();+});