3D engine that AI agents drive
Accept the curve fields from #701 in the MCP recipe schema
Nguyen Xuan Ane2487e7d2e2a
diff --git a/changes/801.md b/changes/801.mdnew file mode 100644index 00000000..be8513c0--- /dev/null+++ b/changes/801.md@@ -0,0 +1 @@+- Fix the MCP recipe schema refusing the curve fields from #701: `scene_create` and `scene_apply` `add-geometry` now take `kind`, `weights`, `splines` (up to 64), `shape`, `trim` and `grow` on a `curve`, and `points` is optional when `shape` or `splines` is given (#801)diff --git a/scripts/mcp-server.mjs b/scripts/mcp-server.mjsindex d08a34dd..0203848e 100644--- a/scripts/mcp-server.mjs+++ b/scripts/mcp-server.mjs@@ -329,7 +329,9 @@ const shadow = z.strictObject({// engine and listed in scene_capabilities curveText, because every tool that takes a recipe repeats this schema.function curveAndTextGeometries(id) {return [- z.strictObject({ ...id, type: z.literal('curve'), points: z.array(z.unknown()).max(1024), closed: looseField, radius: looseField, taper: looseField, profile: looseField, resolution: looseField, radialSegments: looseField }).describe('Bezier sweep; see scene_capabilities curveText.'),+ z.strictObject({ ...id, type: z.literal('curve'), points: z.array(z.unknown()).max(1024).optional(), shape: looseField, splines: z.array(z.unknown()).max(64).optional(), kind: looseField, weights: z.array(z.unknown()).max(1024).optional(), trim: looseField, grow: looseField, closed: looseField, radius: looseField, taper: looseField, profile: looseField, resolution: looseField, radialSegments: looseField })+ .refine(curve => curve.points !== undefined || curve.shape !== undefined || curve.splines !== undefined, { message: 'A curve needs one of points (an array of [x, y, z]), shape ({ type: "arc" | "spiral" | "star" }) or splines (an array of up to 64 splines). See scene_capabilities curveText.' })+ .describe('Sweep along points, a shape or splines; see scene_capabilities curveText.'),z.strictObject({ ...id, type: z.literal('sdf'), root: z.record(z.string(), z.unknown()), resolution: looseField }).describe('Signed-distance shapes with smooth union; see scene_capabilities curveText.'),z.strictObject({ ...id, type: z.literal('text'), text: z.string().max(256), size: looseField, depth: looseField, font: looseField, align: looseField, curveSegments: looseField }).describe('3D text; see scene_capabilities curveText.'),z.strictObject({ ...id, type: z.literal('terrain'), size: looseField, resolution: looseField, seed: looseField, amplitude: looseField, holes: z.array(z.unknown()).max(16).optional() }).describe('Hills with round holes; see scene_capabilities terrain.'),diff --git a/tests/mcp-curve-schema.test.js b/tests/mcp-curve-schema.test.jsnew file mode 100644index 00000000..f1cf57da--- /dev/null+++ b/tests/mcp-curve-schema.test.js@@ -0,0 +1,90 @@+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';++const vine = { id: 'vine', type: 'curve', shape: { type: 'spiral', rotations: 4, height: 3 }, trim: { end: 0.5 }, radius: 0.04 };+const nurbs = { id: 'ribbon', type: 'curve', kind: 'nurbs', points: [[0, 0, 0], [1, 1, 0], [2, 0, 0], [3, 1, 0]], weights: [1, 2, 2, 1] };+const bundle = {+ id: 'bundle',+ type: 'curve',+ splines: [+ { shape: { type: 'arc', radius: 1 } },+ { kind: 'poly', points: [[0, 0, 0], [1, 0, 0]], trim: { start: 0.25, end: 0.75 } },+ ],+};+const growing = { id: 'growing', type: 'curve', shape: { type: 'spiral' }, grow: { name: 'grow', steps: 4 } };++function recipeWith(geometry) {+ return { format: '67js.scene', schemaVersion: 1, geometries: [geometry], materials: [], nodes: [] };+}++async function connectRecordingServer() {+ const received = { create: [], apply: [] };+ const runtime = {+ async close() {},+ async create(requestArguments) {+ received.create.push(requestArguments);+ return { sessionId: 's', revision: 0 };+ },+ async apply(requestArguments) {+ received.apply.push(requestArguments);+ return { sessionId: 's', revision: 1 };+ },+ };+ const server = createAgentMcpServer(runtime);+ const client = new Client({ name: '67js-curve-schema-test', version: '1' });+ const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();+ await server.connect(serverTransport);+ await client.connect(clientTransport);+ return { client, server, received };+}++async function withServer(body) {+ const connection = await connectRecordingServer();+ try {+ await body(connection);+ } finally {+ await connection.client.close();+ await connection.server.close();+ }+}++for (const [name, geometry] of [['spiral with trim', vine], ['nurbs with weights', nurbs], ['splines', bundle], ['grow', growing]]) {+ test(`scene_create accepts a curve with ${name}`, async () => {+ await withServer(async ({ client, received }) => {+ const result = await client.callTool({ name: 'scene_create', arguments: { recipe: recipeWith(geometry) } });+ assert.notEqual(result.isError, true, JSON.stringify(result.content));+ assert.equal(received.create.length, 1);+ });+ });++ test(`scene_apply add-geometry accepts a curve with ${name}`, async () => {+ await withServer(async ({ client, received }) => {+ const result = await client.callTool({+ name: 'scene_apply',+ arguments: { sessionId: '00000000-0000-4000-8000-000000000000', expectedRevision: 0, operations: [{ type: 'add-geometry', geometry }] },+ });+ assert.notEqual(result.isError, true, JSON.stringify(result.content));+ assert.equal(received.apply.length, 1);+ });+ });+}++test('scene_create refuses a curve with no points, shape or splines and names the fields to pass', async () => {+ await withServer(async ({ client }) => {+ const result = await client.callTool({ name: 'scene_create', arguments: { recipe: recipeWith({ id: 'empty', type: 'curve' }) } });+ assert.equal(result.isError, true);+ assert.match(JSON.stringify(result.content), /points.*shape.*splines/s);+ });+});++test('scene_create bounds the spline count', async () => {+ await withServer(async ({ client }) => {+ const splines = Array.from({ length: 65 }, () => ({ shape: { type: 'arc' } }));+ const result = await client.callTool({ name: 'scene_create', arguments: { recipe: recipeWith({ id: 'many', type: 'curve', splines }) } });+ assert.equal(result.isError, true);+ });+});