3D engine that AI agents drive
Packaged MCP server loads shipped HDRIs and looks (issue #664)
Nguyen Xuan An9643d3f889a1
diff --git a/changes/664.md b/changes/664.mdnew file mode 100644index 00000000..add3a742--- /dev/null+++ b/changes/664.md@@ -0,0 +1 @@+- MCP: shipped HDRI and .cube look names (sky-clouds, teal-orange and the rest) load in the packaged server built by npm run build:lib; they failed with "The URL must be of scheme file" (#664)diff --git a/scripts/agent-runtime.mjs b/scripts/agent-runtime.mjsindex 189caede..9164be13 100644--- a/scripts/agent-runtime.mjs+++ b/scripts/agent-runtime.mjs@@ -157,12 +157,15 @@ export function createAgentRuntime({ kernelWorkers = true, backend = 'gpu', brow/** The HDRI and .cube files a recipe names: shipped ones by name from assets/looks, the others by catalog ID. The page decodes them. */async function lookFileData(value) {const { environments, looks } = catalogLookReferences(value);+ // Derived from previewUrl (build/mcp/preview.js in the repo and the package), not from import.meta.url: the bundler+ // inlines a literal `new URL(..., import.meta.url)` as a data URL, and the bundled server sits two folders below the package root.+ const shippedLooksUrl = new URL('../../assets/looks/', previewUrl);const lookData = {};for (const [kind, references] of [['environment', environments], ['look', looks]]) {for (const reference of references) {const shipped = BUNDLED_ENVIRONMENT_NAMES.includes(reference) || BUNDLED_CUBE_LOOK_NAMES.includes(reference);const bytes = shipped- ? await readFile(new URL(`../assets/looks/${reference}.${kind === 'environment' ? 'hdr' : 'cube'}`, import.meta.url))+ ? await readFile(new URL(`${reference}.${kind === 'environment' ? 'hdr' : 'cube'}`, shippedLooksUrl)): await (await catalog()).read(reference);lookData[reference] = kind === 'environment' ? { kind, base64: bytes.toString('base64') } : { kind, text: bytes.toString('utf8') };}diff --git a/tests/packaged-looks.test.js b/tests/packaged-looks.test.jsnew file mode 100644index 00000000..858e9405--- /dev/null+++ b/tests/packaged-looks.test.js@@ -0,0 +1,48 @@+import test from 'node:test';+import assert from 'node:assert/strict';+import { existsSync } from 'node:fs';+import { execFileSync } from 'node:child_process';+import { Client } from '@modelcontextprotocol/client';+import { StdioClientTransport } from '@modelcontextprotocol/client/stdio';+import { BUNDLED_CUBE_LOOK_NAMES, BUNDLED_ENVIRONMENT_NAMES } from '../src/look-catalog.js';++const serverEntry = new URL('../bin/67js-mcp.mjs', import.meta.url).pathname.replace(/^\/(\w:)/, '$1');+const hasBuild = existsSync(new URL('../build/mcp/server.mjs', import.meta.url));+const recipe = {+ format: '67js.scene', schemaVersion: 1,+ geometries: [{ id: 'cube', type: 'box', bevel: 0 }],+ materials: [{ id: 'blue', color: [0.1, 0.3, 0.8] }],+ nodes: [{ id: 'mesh', geometry: 'cube', material: 'blue' }],+};++function textOf(result) {+ return (result.content ?? []).map(part => part.text ?? '').join('\n');+}++test('the built MCP server reads shipped HDRIs and .cube looks from assets/looks', { skip: !hasBuild && 'run npm run build:lib first', timeout: 120000 }, async context => {+ const transport = new StdioClientTransport({ command: process.execPath, args: [serverEntry, '--backend', 'cpu'], stderr: 'ignore' });+ const client = new Client({ name: 'packaged-looks-test', version: '1.0.0' });+ await client.connect(transport);+ context.after(() => client.close());+ const created = await client.callTool({ name: 'scene_create', arguments: { recipe } });+ if (created.isError) {+ context.skip(`no browser for the scene: ${textOf(created).slice(0, 120)}`);+ return;+ }+ const { sessionId } = created.structuredContent;+ let revision = created.structuredContent.revision;+ for (const environment of [{ hdri: BUNDLED_ENVIRONMENT_NAMES[0] }, { look: BUNDLED_CUBE_LOOK_NAMES[0] }]) {+ const applied = await client.callTool({ name: 'scene_apply', arguments: { sessionId, expectedRevision: revision, operations: [{ type: 'set-environment', environment }] } });+ assert.notEqual(applied.isError, true, textOf(applied));+ assert.doesNotMatch(textOf(applied), /scheme file/);+ revision = applied.structuredContent?.revision ?? revision + 1;+ }+});++test('the npm archive ships every bundled HDRI and .cube look', { timeout: 120000 }, () => {+ const output = execFileSync('npm', ['pack', '--dry-run', '--json', '--ignore-scripts'], { encoding: 'utf8', shell: true });+ const report = JSON.parse(output);+ const paths = (Array.isArray(report) ? report[0] : Object.values(report)[0]).files.map(file => file.path);+ for (const name of BUNDLED_ENVIRONMENT_NAMES) assert.ok(paths.includes(`assets/looks/${name}.hdr`), name);+ for (const name of BUNDLED_CUBE_LOOK_NAMES) assert.ok(paths.includes(`assets/looks/${name}.cube`), name);+});