Skip to content

🎥 Make videos programmatically with React

Refine WebMCP tool contracts

JonnyBurger9ee9348cb820
diff --git a/packages/docs/docs/ai/webmcp.mdx b/packages/docs/docs/ai/webmcp.mdx
index 922f6a2ce5..af6ba9ed78 100644
--- a/packages/docs/docs/ai/webmcp.mdx
+++ b/packages/docs/docs/ai/webmcp.mdx
@@ -7,7 +7,7 @@ sidebar_label: WebMCP
# WebMCP<AvailableFrom v="4.0.518" />
-Remotion Studio exposes WebMCP tools that allow an AI agent to inspect and control the open composition.
+Remotion Studio exposes WebMCP tools that allow an AI agent to inspect and steer it.
## Capabilities
@@ -15,10 +15,10 @@ Agents can:
- See which items you currently have selected
- See selectable items and select them
-- See available compositions and navigate
+- See available compositions and navigate to them
- Get the current HTML of your composition
- See current outlines of elements and their geometry
-- See your current playhead position and playback state
+- Get your current playhead position and playback state
- Play, pause and seek
- Set timeline zoom, playback rate, and mute state
- See, add and remove guides
@@ -33,6 +33,12 @@ Out of the major harnesses, only ChatGPT Codex supports WebMCP. We hope more age
## Available tools
+:::note
+
+The shape of inputs and outputs is not currently stable.
+
+:::
+
Tools that modify the timeline, playback or guides require a composition to be open.
### `get_compositions`
@@ -182,8 +188,8 @@ Returns the measurable selectable component outlines active at the current frame
currentFrame: number | null;
outlines: Array<{
sequenceId: string;
+ parentSequenceId: string | null;
name: string | null;
- depth: number;
location: {
filename: string;
line: number;
@@ -208,7 +214,7 @@ Returns the measurable selectable component outlines active at the current frame
### `get_playback_state`
-Returns the current playhead, playback, audio, looping and timeline zoom state. Playback fields are `null` when the canvas is not showing a composition.
+Returns the current playhead, playback, audio, looping and timeline zoom state. Timeline zoom is normalized between `0` (fully zoomed out) and `1` (maximum zoom). Playback fields are `null` when the canvas is not showing a composition.
```ts title="Input"
{}
@@ -406,7 +412,7 @@ Unmutes audio playback.
### `set_timeline_zoom`
-Sets the timeline zoom factor. The requested value is clamped to the range supported by the composition duration. Still compositions do not have timeline zoom.
+Sets the timeline zoom using a normalized value between `0` (fully zoomed out) and `1` (maximum zoom). The output contains the effective normalized zoom after Studio applies its supported zoom step. Still compositions do not have timeline zoom.
```ts title="Input"
{
@@ -474,19 +480,19 @@ Seeks to a zero-based frame. Values beyond the duration are clamped to the final
You can ask a browser agent:
-- “What is currently selected in the Studio?”
-- “List all mounted compositions and their folders.”
-- “Open the `Shapes` composition.”
-- “List the sequences and select the `Title` sequence.”
-- “Inspect the HTML rendered on the canvas.”
-- “List the visible components and their canvas geometry.”
-- “What is the current playback state?”
-- “Set the timeline zoom to 2.5x.”
-- “Seek to frame 90, set the playback rate to 0.5x and play.”
-- “List the guides in the current composition.”
-- “Hide the guides.”
-- “Add a vertical guide at 640 pixels.”
-- “Mute the preview.”
+- "What is currently selected in the Studio?"
+- "List all mounted compositions and their folders."
+- "Open the `Shapes` composition."
+- "List the sequences and select the `Title` sequence."
+- "Inspect the HTML rendered on the canvas."
+- "List the visible components and their canvas geometry."
+- "What is the current playback state?"
+- "Set the timeline zoom to 2.5x."
+- "Seek to frame 90, set the playback rate to 0.5x and play."
+- "List the guides in the current composition."
+- "Hide the guides."
+- "Add a vertical guide at 640 pixels."
+- "Mute the preview."
The agent chooses and invokes the matching tools. Tool calls affect the open Studio tab immediately.
diff --git a/packages/example/e2e/studio.test.mts b/packages/example/e2e/studio.test.mts
index 37fb6491e5..dfaf2ef855 100644
--- a/packages/example/e2e/studio.test.mts
+++ b/packages/example/e2e/studio.test.mts
@@ -2141,6 +2141,7 @@ test.describe('visual mode', () => {
webMcpSelection as {
readonly selectedSequence: {
readonly sequenceId: string;
+ readonly parentSequenceId: string | null;
};
}
).selectedSequence;
@@ -2320,6 +2321,7 @@ test.describe('visual mode', () => {
readonly outlines: readonly {
readonly name: string | null;
readonly sequenceId: string;
+ readonly parentSequenceId: string | null;
readonly location: {
readonly filename: string;
readonly line: number;
@@ -2346,8 +2348,8 @@ test.describe('visual mode', () => {
});
expect(gridlineOutline).toEqual({
sequenceId: selectedSequence.sequenceId,
+ parentSequenceId: selectedSequence.parentSequenceId,
name: '0% gridline',
- depth: expect.any(Number),
location: {
filename: 'src/BarChart.tsx',
line: expect.any(Number),
@@ -2719,15 +2721,15 @@ test.describe('visual mode', () => {
throw new Error('set_timeline_zoom was not registered');
}
- return tool.execute({zoom: 2.5});
+ return tool.execute({zoom: 0.5});
});
expect(webMcpTimelineZoomResult).toEqual({
currentComposition: 'AnimatedBarChart',
- timelineZoom: 2.5,
+ timelineZoom: 0.489,
});
await expect(
- page.getByTitle('Timeline zoom (2.5x)', {exact: true}),
- ).toBeVisible();
+ page.locator('input[type="range"][alt^="Timeline zoom"]'),
+ ).toHaveValue('489');
const webMcpMuteResult = await page.evaluate(async () => {
const tools = (
window as typeof window & {
@@ -2887,7 +2889,7 @@ test.describe('visual mode', () => {
volume: 1,
playbackRate: 1.5,
looping: true,
- timelineZoom: 2.5,
+ timelineZoom: 0.489,
});
fs.writeFileSync(
diff --git a/packages/studio/src/components/WebMcp.tsx b/packages/studio/src/components/WebMcp.tsx
index 0d1b38f477..5cc5312303 100644
--- a/packages/studio/src/components/WebMcp.tsx
+++ b/packages/studio/src/components/WebMcp.tsx
@@ -15,7 +15,10 @@ import {
} from '../helpers/format-file-location';
import {
clampTimelineZoom,
+ getTimelineMaxZoom,
+ normalizedToTimelineZoom,
TIMELINE_MIN_ZOOM,
+ timelineZoomToNormalized,
} from '../helpers/get-timeline-max-zoom';
import type {TimelineTrackData} from '../helpers/get-timeline-sequence-sort-key';
import {
@@ -624,8 +627,8 @@ export const WebMcp: FC = () => {
return {
sequenceId: outline.sequence.id,
+ parentSequenceId: outline.sequence.parent,
name,
- depth: outline.depth,
location: getRelativeFileLocation({
location,
root: window.remotion_cwd,
@@ -660,7 +663,7 @@ export const WebMcp: FC = () => {
name: 'get_playback_state',
title: 'Get Studio playback state',
description:
- 'Read the current frame, playing state, audio state, playback rate, looping state, and timeline zoom for the composition open in Remotion Studio. All playback fields are null when the canvas is not showing a composition.',
+ 'Read the current frame, playing state, audio state, playback rate, looping state, and normalized timeline zoom for the composition open in Remotion Studio. All playback fields are null when the canvas is not showing a composition.',
inputSchema: {
type: 'object',
properties: {},
@@ -690,8 +693,11 @@ export const WebMcp: FC = () => {
volume: mediaVolumeRef.current,
playbackRate: playbackRateRef.current,
looping: loadLoopOption(),
- timelineZoom:
- timelineZoomRef.current[compositionId] ?? TIMELINE_MIN_ZOOM,
+ timelineZoom: timelineZoomToNormalized({
+ zoom:
+ timelineZoomRef.current[compositionId] ?? TIMELINE_MIN_ZOOM,
+ maxZoom: getTimelineMaxZoom(getCurrentDuration()),
+ }),
});
},
},
@@ -1056,14 +1062,16 @@ export const WebMcp: FC = () => {
name: 'set_timeline_zoom',
title: 'Set Studio timeline zoom',
description:
- 'Set the timeline zoom factor for the current Remotion Studio composition. The zoom is clamped to the range supported by the composition duration.',
+ 'Set the timeline zoom for the current Remotion Studio composition. Use 0 for fully zoomed out and 1 for the maximum zoom supported by the composition duration.',
inputSchema: {
type: 'object',
properties: {
zoom: {
type: 'number',
- exclusiveMinimum: 0,
- description: 'The requested timeline zoom factor.',
+ minimum: 0,
+ maximum: 1,
+ description:
+ 'The normalized timeline zoom, from 0 (fully zoomed out) to 1 (maximum zoom).',
},
},
required: ['zoom'],
@@ -1074,9 +1082,10 @@ export const WebMcp: FC = () => {
if (
typeof zoom !== 'number' ||
!Number.isFinite(zoom) ||
- zoom <= 0
+ zoom < 0 ||
+ zoom > 1
) {
- throw new Error('zoom must be a positive finite number.');
+ throw new Error('zoom must be a finite number between 0 and 1.');
}
const compositionId = currentCompositionRef.current;
@@ -1091,8 +1100,12 @@ export const WebMcp: FC = () => {
);
}
+ const maxZoom = getTimelineMaxZoom(durationInFrames);
const timelineZoom = clampTimelineZoom({
- zoom,
+ zoom: normalizedToTimelineZoom({
+ normalized: zoom,
+ maxZoom,
+ }),
durationInFrames,
});
setTimelineZoom(compositionId, () => timelineZoom, {
@@ -1102,7 +1115,10 @@ export const WebMcp: FC = () => {
return Promise.resolve({
currentComposition: compositionId,
- timelineZoom,
+ timelineZoom: timelineZoomToNormalized({
+ zoom: timelineZoom,
+ maxZoom,
+ }),
});
},
},
diff --git a/packages/studio/src/helpers/get-timeline-max-zoom.ts b/packages/studio/src/helpers/get-timeline-max-zoom.ts
index 87bff3ed97..e5432ebd90 100644
--- a/packages/studio/src/helpers/get-timeline-max-zoom.ts
+++ b/packages/studio/src/helpers/get-timeline-max-zoom.ts
@@ -29,7 +29,7 @@ export const clampTimelineZoom = ({
return Math.round(clamped * 10) / 10;
};
-export const timelineZoomToSliderValue = ({
+export const timelineZoomToNormalized = ({
zoom,
maxZoom,
}: {
@@ -41,27 +41,54 @@ export const timelineZoomToSliderValue = ({
}
const clampedZoom = Math.min(maxZoom, Math.max(TIMELINE_MIN_ZOOM, zoom));
- const t =
+ const normalized =
Math.log(clampedZoom / TIMELINE_MIN_ZOOM) /
Math.log(maxZoom / TIMELINE_MIN_ZOOM);
- return Math.round(t * TIMELINE_ZOOM_SLIDER_MAX);
+ return (
+ Math.round(normalized * TIMELINE_ZOOM_SLIDER_MAX) / TIMELINE_ZOOM_SLIDER_MAX
+ );
};
-export const sliderValueToTimelineZoom = ({
- sliderValue,
+export const timelineZoomToSliderValue = ({
+ zoom,
maxZoom,
}: {
- sliderValue: number;
+ zoom: number;
+ maxZoom: number;
+}): number => {
+ return Math.round(
+ timelineZoomToNormalized({zoom, maxZoom}) * TIMELINE_ZOOM_SLIDER_MAX,
+ );
+};
+
+export const normalizedToTimelineZoom = ({
+ normalized,
+ maxZoom,
+}: {
+ normalized: number;
maxZoom: number;
}): number => {
if (maxZoom <= TIMELINE_MIN_ZOOM) {
return TIMELINE_MIN_ZOOM;
}
- const t = sliderValue / TIMELINE_ZOOM_SLIDER_MAX;
+ const t = Math.min(1, Math.max(0, normalized));
return TIMELINE_MIN_ZOOM * (maxZoom / TIMELINE_MIN_ZOOM) ** t;
};
+export const sliderValueToTimelineZoom = ({
+ sliderValue,
+ maxZoom,
+}: {
+ sliderValue: number;
+ maxZoom: number;
+}): number => {
+ return normalizedToTimelineZoom({
+ normalized: sliderValue / TIMELINE_ZOOM_SLIDER_MAX,
+ maxZoom,
+ });
+};
+
export const TIMELINE_ZOOM_SLIDER_PROPS = {
min: 0,
max: TIMELINE_ZOOM_SLIDER_MAX,
diff --git a/packages/studio/src/test/get-timeline-max-zoom.test.ts b/packages/studio/src/test/get-timeline-max-zoom.test.ts
index 81c300e2bb..1cc0c32817 100644
--- a/packages/studio/src/test/get-timeline-max-zoom.test.ts
+++ b/packages/studio/src/test/get-timeline-max-zoom.test.ts
@@ -2,11 +2,13 @@ import {expect, test} from 'bun:test';
import {
clampTimelineZoom,
getTimelineMaxZoom,
+ normalizedToTimelineZoom,
sliderValueToTimelineZoom,
TIMELINE_FRAMES_VISIBLE_AT_MAX_ZOOM,
TIMELINE_MAX_ZOOM_FLOOR,
TIMELINE_MIN_ZOOM,
TIMELINE_ZOOM_SLIDER_PROPS,
+ timelineZoomToNormalized,
timelineZoomToSliderValue,
} from '../helpers/get-timeline-max-zoom';
@@ -61,6 +63,21 @@ test('timeline zoom slider maps min and max', () => {
).toBe(maxZoom);
});
+test('normalized timeline zoom maps min, midpoint and max', () => {
+ const maxZoom = 6;
+
+ expect(normalizedToTimelineZoom({normalized: 0, maxZoom})).toBe(
+ TIMELINE_MIN_ZOOM,
+ );
+ expect(normalizedToTimelineZoom({normalized: 0.5, maxZoom})).toBeCloseTo(
+ Math.sqrt(maxZoom),
+ );
+ expect(normalizedToTimelineZoom({normalized: 1, maxZoom})).toBe(maxZoom);
+ expect(
+ timelineZoomToNormalized({zoom: Math.sqrt(maxZoom), maxZoom}),
+ ).toBeCloseTo(0.5);
+});
+
test('timeline zoom slider increases with zoom', () => {
const maxZoom = getTimelineMaxZoom(60 * 60 * 30);