Skip to content

3D engine that AI agents drive

Let scene_render_result leave out the attached PNGs (#2056)

Nguyen Xuan An7d99027b8095
diff --git a/changes/2056.md b/changes/2056.md
new file mode 100644
index 00000000..e04285c5
--- /dev/null
+++ b/changes/2056.md
@@ -0,0 +1 @@
+- `scene_render_result` takes `images: false` to return the output paths without attaching every PNG, and its description says the PNGs are attached (#2056)
diff --git a/docs/agent-render-jobs.md b/docs/agent-render-jobs.md
index 0b75712c..b42662a4 100644
--- a/docs/agent-render-jobs.md
+++ b/docs/agent-render-jobs.md
@@ -9,7 +9,7 @@ Release `0.6.0` includes five MCP tools for asynchronous image and video renderi
3. Create a scene and inspect its current revision.
4. Submit `scene_render_submit` with the session ID, current revision and render settings.
5. Poll `scene_render_status` until the job reaches a terminal state. The job tools take `jobId` alone; a `sessionId` is refused with that hint. A path traced job on the default cpu backend whose scene is estimated above twice 400000 triangles (the estimate can run 1.5 times high on non-indexed geometry) is refused at submit with the count, instead of failing after it started; a scene between the cap and that margin is checked exactly when the trace starts.
-6. Read `scene_render_result` after completion to obtain output paths, and SHA-256 hashes with `response_format: "detailed"`.
+6. Read `scene_render_result` after completion to obtain output paths, and SHA-256 hashes with `response_format: "detailed"`. The answer attaches every PNG of the job (up to 1 MiB each) as an image, whatever `response_format` is, and adds a resource link to each file; a harness that keeps the transcript pays for those pictures on every later turn, so pass `images: false` to get the paths, sizes and metrics only. Video is never attached.
7. Release unwanted outputs with `scene_render_release`.
For MP4 jobs, FFmpeg must be on PATH or configured with `--ffmpeg` and an absolute executable path.
diff --git a/scripts/mcp-server.mjs b/scripts/mcp-server.mjs
index c92fb7d4..143355d8 100644
--- a/scripts/mcp-server.mjs
+++ b/scripts/mcp-server.mjs
@@ -859,6 +859,7 @@ const checkpointFields = { ...sessionFields, checkpointId: z.uuid().describe('Ch
const expectedRevision = z.number().int().min(0).max(Number.MAX_SAFE_INTEGER).describe('Current revision returned by create, inspect, apply or restore. Stale edits fail atomically.');
const jobFields = { jobId: z.uuid().describe('Render job UUID returned by scene_render_submit or capabilities jobs.records.') };
const jobWithFormatFields = { ...jobFields, response_format: responseFormatField };
+const jobResultFields = { ...jobWithFormatFields, images: z.boolean().optional() };
// Job tools take jobId alone; an agent that carries sessionId over from the scene tools gets told to drop it.
function jobKeysHint(toolName, acceptedKeys) {
const accepted = acceptedKeys.length > 1 ? `${acceptedKeys[0]} (and ${acceptedKeys.slice(1).join(', ')})` : acceptedKeys[0];
@@ -920,10 +921,10 @@ const OUTPUT_SCHEMAS = {
const INLINE_IMAGE_TYPES = new Set(['image/png', 'image/jpeg', 'image/webp']);
const INLINE_IMAGE_MAXIMUM_BYTES = 1024 * 1024;
-async function renderResultContent(result, shown = result) {
+async function renderResultContent(result, shown = result, { attachImages = true } = {}) {
const content = [{ type: 'text', text: JSON.stringify(shown) }];
for (const artifact of result.artifacts) {
- if (INLINE_IMAGE_TYPES.has(artifact.mimeType) && artifact.bytes <= INLINE_IMAGE_MAXIMUM_BYTES) {
+ if (attachImages && INLINE_IMAGE_TYPES.has(artifact.mimeType) && artifact.bytes <= INLINE_IMAGE_MAXIMUM_BYTES) {
content.push({ type: 'image', data: (await readFile(artifact.path)).toString('base64'), mimeType: artifact.mimeType });
}
content.push({ type: 'resource_link', uri: pathToFileURL(artifact.path).href, name: artifact.filename, mimeType: artifact.mimeType, size: artifact.bytes });
@@ -1102,9 +1103,9 @@ export function createAgentMcpServer(runtime, { version = packageMetadata.versio
return jsonResult(chosenFormat('scene_render_status', response_format) === 'concise' ? conciseJobStatus(record) : record);
});
register('scene_render_cancel', 'Request cancellation of one job. Poll status until terminal before using the preview again.', z.strictObject(jobFields, { error: jobKeysHint('scene_render_cancel', Object.keys(jobFields)) }), { ...edit, idempotentHint: true }, async argumentsValue => jsonResult(await runtime.cancelJob(argumentsValue)));
- register('scene_render_result', 'Read completed local output paths, MIME types, byte counts, SHA-256 digests and measured render metrics. Returns a PNG inline and a resource link to each file; video stays on disk.', z.strictObject(jobWithFormatFields, { error: jobKeysHint('scene_render_result', Object.keys(jobWithFormatFields)) }), readOnly, async ({ response_format, ...jobInput }) => {
+ register('scene_render_result', 'Read completed local output paths, MIME types, byte counts, SHA-256 digests and measured render metrics. Attaches each PNG (images: false for paths only) and a resource link per file; video stays on disk.', z.strictObject(jobResultFields, { error: jobKeysHint('scene_render_result', Object.keys(jobResultFields)) }), readOnly, async ({ response_format, images, ...jobInput }) => {
const result = await runtime.jobResult(jobInput);
- return renderResultContent(result, chosenFormat('scene_render_result', response_format) === 'concise' ? conciseJobResult(result) : result);
+ return renderResultContent(result, chosenFormat('scene_render_result', response_format) === 'concise' ? conciseJobResult(result) : result, { attachImages: images !== false });
});
register('scene_render_release', 'Delete the owned files and record for a terminal job, freeing store quota. Active jobs must be cancelled first.', z.strictObject(jobFields, { error: jobKeysHint('scene_render_release', Object.keys(jobFields)) }), destroy, async argumentsValue => jsonResult(await runtime.releaseJob(argumentsValue)));
return server;
diff --git a/skills/render-crucible-media/SKILL.md b/skills/render-crucible-media/SKILL.md
index c6a8ebb4..4f267b40 100644
--- a/skills/render-crucible-media/SKILL.md
+++ b/skills/render-crucible-media/SKILL.md
@@ -22,7 +22,7 @@ submit call fails: tell the user which launch option is missing.
durable frame progress. Never loop tightly. Status and result answer in a short `concise` form by default; pass
`response_format: "detailed"` for the full record.
5. `scene_render_result`: output paths, sizes and metrics. Report the actual `width` and `height`, the backend
- and the seconds; memory limits can lower the size. `detailed` adds SHA-256 hashes and resource counters.
+ and the seconds; memory limits can lower the size. `detailed` adds SHA-256 hashes and resource counters. The answer attaches every PNG as an image; pass `images: false` when the paths are enough (a `stills` job is 8 pictures).
`metrics.report.fallbacks` lists everything that ran differently from the request: read it.
6. Keep what you need, then `scene_render_release` to remove the job's files.
7. `scene_render_cancel` stops a job; poll `scene_render_status` until it is `cancelled` before editing again.
diff --git a/tests/mcp-agent-errors.test.js b/tests/mcp-agent-errors.test.js
index 7c2d2f1f..a20a3ab7 100644
--- a/tests/mcp-agent-errors.test.js
+++ b/tests/mcp-agent-errors.test.js
@@ -80,7 +80,7 @@ test('scene_render_status given a sessionId says jobs are addressed by jobId alo
test('the other job tools give the same hint for sessionId', async context => {
const client = await connect(context);
- const accepted = { scene_render_cancel: 'jobId', scene_render_result: 'jobId (and response_format)', scene_render_release: 'jobId' };
+ const accepted = { scene_render_cancel: 'jobId', scene_render_result: 'jobId (and response_format, images)', scene_render_release: 'jobId' };
for (const [name, keys] of Object.entries(accepted)) {
const result = await client.callTool({ name, arguments: { jobId: randomUUID(), sessionId: randomUUID() } });
assert.equal(result.isError, true, name);
diff --git a/tests/mcp-render-result-images.test.js b/tests/mcp-render-result-images.test.js
new file mode 100644
index 00000000..59484b4c
--- /dev/null
+++ b/tests/mcp-render-result-images.test.js
@@ -0,0 +1,60 @@
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import { mkdtemp, writeFile, rm } from 'node:fs/promises';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { randomUUID } from 'node:crypto';
+import { Client } from '@modelcontextprotocol/client';
+import { InMemoryTransport } from '@modelcontextprotocol/server';
+import { createAgentMcpServer } from '../scripts/mcp-server.mjs';
+
+const ONE_PIXEL_PNG = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jRZkAAAAASUVORK5CYII=', 'base64');
+const jobId = randomUUID();
+
+async function connectWithStills(context) {
+ const directory = await mkdtemp(join(tmpdir(), 'crucible-render-result-images-'));
+ context.after(() => rm(directory, { recursive: true, force: true }));
+ const artifacts = [];
+ for (const index of [1, 2, 3]) {
+ const path = join(directory, `still-${index}.png`);
+ await writeFile(path, ONE_PIXEL_PNG);
+ artifacts.push({ filename: `still-${index}.png`, mimeType: 'image/png', bytes: ONE_PIXEL_PNG.length, path, sha256: 'a'.repeat(64) });
+ }
+ const runtime = {
+ activeSessionId: () => null,
+ async close() {},
+ async jobResult() { return { jobId, sourceRevision: 1, metrics: { backend: 'cpu' }, artifacts: structuredClone(artifacts) }; },
+ };
+ const server = createAgentMcpServer(runtime);
+ const client = new Client({ name: 'render-result-images-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;
+}
+
+const countOf = (result, type) => result.content.filter(block => block.type === type).length;
+
+test('scene_render_result attaches every PNG by default and none with images: false (#2056)', async context => {
+ const client = await connectWithStills(context);
+ for (const response_format of [undefined, 'concise', 'detailed']) {
+ const withImages = await client.callTool({ name: 'scene_render_result', arguments: { jobId, ...(response_format && { response_format }) } });
+ assert.equal(countOf(withImages, 'image'), 3, `${response_format}: images attached by default`);
+ }
+ const pathsOnly = await client.callTool({ name: 'scene_render_result', arguments: { jobId, images: false } });
+ assert.equal(countOf(pathsOnly, 'image'), 0);
+ assert.equal(countOf(pathsOnly, 'resource_link'), 3, 'every file keeps its resource link');
+ assert.equal(pathsOnly.structuredContent.artifacts.length, 3, 'the paths stay in the answer');
+});
+
+test('scene_render_result says in its description that PNGs are attached and how to turn that off', async context => {
+ const client = await connectWithStills(context);
+ const { tools } = await client.listTools();
+ const tool = tools.find(candidate => candidate.name === 'scene_render_result');
+ assert.ok(tool.description.includes("Attaches each PNG (images: false for paths only)"));
+ assert.ok(tool.inputSchema.properties.images);
+});