# Coco MCP server

Source: the Coco template guide that the MCP server serves as a resource.

The MCP server is named `coco`. It answers at https://api.compositor.video/mcp over streamable HTTP and takes the same API key as the REST API: `Authorization: Bearer sk_live_...`. Agents use the same templates as the editor and the REST API.

Tools: `list_templates`, `get_template`, `save_template`, `list_assets`, `upload_asset`, `complete_upload`, `delete_asset`, `get_transcript`, `render_template`, `wait_for_render`, `get_render`, `get_usage`.

## Make a video

1. Call `list_assets` to find asset ids.
2. If an asset is missing, call `upload_asset`, run the returned curl command, then call `complete_upload`.
3. Call `list_templates` and `get_template`, or write a template and call `save_template`.
4. Call `render_template` with the ref, the `vars` and a new `request_id`.
5. Call `wait_for_render` until `done` is true.
6. Download `outputs[0].url` before `outputs[0].expires`.

If a call fails, the result has `isError` and `{"error": {"code", "message", "field", "status"}}`. Code `invalid_value` names the part to fix in `field`, for example `tracks.T1.t1` or `vars.headline`. A status of 429 is a plan limit. `get_usage` shows the limits.

## Template JSON

| Key | Value |
|---|---|
| `name` | Display name. |
| `canvas` | `{"w", "h", "fps", "duration"}`. Width and height in px, even, at most 3840. fps from 1 to 60. duration in seconds, above 0, at most 300. |
| `variables` | Object keyed by variable name (`a-z`, `0-9`, `_`, starting with a letter). |
| `tracks` | List of `{"id", "kind", "clips"}`. |

The server sets `template` (the id) and `version`. All times are seconds, and decimals are allowed.

## Rendering rules

- The video is exactly `canvas.duration` seconds long. A clip that runs past the end is cut.
- Clips on video tracks fill the canvas with a cover crop. Where clips overlap in time, the clip listed first is on top. Time with no clip is black.
- A video source shorter than its clip holds its last frame.
- A dark gradient covers the top of the frame only while a text clip is on screen. It keeps top text readable on bright images. A template with no text clip has no gradient.
- Text is white with a shadow and wraps to the canvas width. `size` is px at a 1080 px wide canvas and scales with the canvas width.
- An overlay clip shows its image in a small box at the bottom left, about a quarter of the canvas width.
- Caption clips draw above text clips and below overlay clips.
- Audio clips play from their `start` and mix together. `fade_out` fades the last second. A short audio file leaves silence after it.
- Text needs a font. The service uses the account's oldest font asset, else its default font.

## Sound

- A video clip plays the sound of its source for its span, from the same source point as its picture. It mixes with the audio clips.
- A video source with no audio stream gives silence for that clip. The render does not fail.
- Image and colour clips have no sound. A video clip that shows an image variable has no sound.
- `gain` sets the sound level of a video or audio clip, from 0 to 4. At 1 the clip plays at the level of its source. `gain: 0` mutes the clip. A video clip with no `gain` plays at 1. An audio clip needs `gain`.
- When a list section repeats a video clip, each item's clip plays its own sound.
- Where video clips overlap in time, the sound of each clip plays. The picture shows the clip on top.
- `normalize: true` levels the sound of the clip to -16 LUFS integrated, with a true peak of at most -1.5 dBTP. The level applies before `gain`. `normalize` is `false` when you leave it out.
- `normalize` measures only the part of the source that the clip plays, not the whole file. A video clip with a `trim` is levelled on its trimmed part.
- A limiter keeps the true peak of the final mix at -1 dBTP or lower. A `gain` above 1 never clips the sound.

## Lists

A list variable lets one render show any number of items, for example 4 photos with a caption each. The template stores one copy of a span of time, the section. The render plays the section once per item, in item order.

## The list variable

| Key | Value |
|---|---|
| `type` | `"list"` |
| `min` | Fewest items a render takes. An integer, 1 or more. Default 1. |
| `max` | Most items a render takes. At least `min`, at most the item ceiling. Left out, the save writes the ceiling. |
| `section` | `{"start", "dur"}` in seconds, and an optional `"fit"`. `start` is 0 or more. `dur` is at least 0.1 and one frame. `start + dur` is at most `canvas.duration`. |
| `section.fit` | Optional. The key of a video field of the list. Each item then lasts as long as its clip, and `dur` is the design length the editor shows. See Clip length below. |
| `fields` | Object of 1 to 16 fields. Each field takes the keys of a variable of its type. A field cannot be a list. |

A template holds at most one list. The list key and the field keys use `a-z`, `0-9` and `_`, start with a letter and hold at most 16 characters. They cannot hold `__`. In a template with a list, no other variable key holds `__` and no clip id holds `#`. The render uses these names for the copies.

## Section rules

- A clip shows a field as `"{{slides.photo}}"`: the list key, a dot, the field key.
- A clip that shows a field sits inside the section.
- The section holds at least one clip that shows a field.
- A clip sits before the section, inside it, or after it. It can also cover the whole section. No clip crosses an edge of the section.
- The render copies each clip inside the section once per item. Copy k starts `k * dur` seconds after the stored clip.
- Clips after the section move later by `(items - 1) * dur` seconds.
- A clip that covers the whole section and shows no field stretches over all the copies. Music and a logo work this way.
- The video lasts `canvas.duration + (items - 1) * section.dur` seconds.

These timing rules apply to a section with no `fit`. Clip length below gives the rules with `fit`.

## Item ceiling

A render holds at most 64 clips and lasts at most 300 s. The save takes the lower of two counts as the item ceiling:

- By clips: `floor((64 - F) / C)`. `F` is the number of clips outside the section, `C` the number of clips inside it.
- By duration: `floor((300 * fps - round(canvas.duration * fps)) / S) + 1`. `S` is the section length in frames.

With `fit`, the item lengths are known only at render, so the ceiling is the count by clips. The 300 s limit applies at render, when the lengths are known.

A `max` above the ceiling fails the save with `invalid_value` at `variables.<list>.max`. A list with one clip per item and no other clip fits 64 items. Two clips per item fit about 30.

## Render vars

`vars` gives a list an array of items. Each item is an object keyed by field. Each field value has the shape a variable of that type takes. Field order inside an item does not matter. Item order is the film order. An error inside an item names its path, for example `vars.slides[1].caption`.

## Worked example

A vertical photo slideshow: a 2 s intro in the brand colour, a 3 s section per photo, and a 2 s outro. A title shows on the intro and a call to action on the outro. The logo and the music cover the whole film. The item ceiling is 29: 6 clips sit outside the section and 2 inside it.

```json template
{
  "name": "Photo slideshow",
  "canvas": {"w": 1080, "h": 1920, "fps": 30, "duration": 7},
  "variables": {
    "title": {"type": "text", "max": 40},
    "slides": {
      "type": "list",
      "min": 1,
      "max": 29,
      "section": {"start": 2, "dur": 3},
      "fields": {
        "photo": {"type": "image", "required": true},
        "caption": {"type": "text", "max": 40}
      }
    },
    "cta": {"type": "text", "max": 24},
    "brand_color": {"type": "color"},
    "logo": {"type": "image", "default": "asset:a_logo"},
    "music": {"type": "audio", "default": "asset:a_music"}
  },
  "tracks": [
    {"id": "V1", "kind": "video", "clips": [
      {"id": "intro", "kind": "color", "src": "{{brand_color}}", "start": 0, "dur": 2},
      {"id": "shot", "kind": "image", "src": "{{slides.photo}}", "start": 2, "dur": 3, "move": "zoom_in"},
      {"id": "outro", "kind": "color", "src": "{{brand_color}}", "start": 5, "dur": 2}
    ]},
    {"id": "T1", "kind": "text", "clips": [
      {"id": "title", "kind": "text", "src": "{{title}}", "start": 0.2, "dur": 1.6, "size": 110, "edge": "top", "anim": "fade_in"},
      {"id": "cap", "kind": "text", "src": "{{slides.caption}}", "start": 2.3, "dur": 2.5, "size": 84, "edge": "bottom", "anim": "slide_up"},
      {"id": "cta", "kind": "text", "src": "{{cta}}", "start": 5.2, "dur": 1.6, "size": 84, "edge": "bottom", "anim": "slide_up"}
    ]},
    {"id": "O1", "kind": "overlay", "clips": [
      {"id": "logo", "kind": "overlay", "src": "{{logo}}", "start": 0, "dur": 7, "anim": "fade_in"}
    ]},
    {"id": "A1", "kind": "audio", "clips": [
      {"id": "music", "kind": "audio", "src": "{{music}}", "start": 0, "dur": 7, "gain": 0.6, "anim": "fade_out"}
    ]}
  ]
}
```

With 4 items the video lasts 7 + 3 * 3 = 16 s. The photos start at 2, 5, 8 and 11 s. The outro starts at 14 s. Replace `a_1` to `a_4` with image ids from `list_assets`. The template defaults `a_logo` and `a_music` also name library assets.

```json vars
{
  "title": "Autumn drop",
  "slides": [
    {"photo": {"asset": "a_1"}, "caption": "Field jacket"},
    {"photo": {"asset": "a_2"}, "caption": "Brick lane"},
    {"caption": "Crosswalk", "photo": {"asset": "a_3"}},
    {"photo": {"asset": "a_4"}, "caption": "Trio on steps"}
  ],
  "cta": "Shop the drop",
  "brand_color": "#FFB224"
}
```

## Media by URL

A video, image or audio variable also takes `{"url": "https://..."}` in place of `{"asset": "a_..."}`. A video adds `trim` as before. The file needs no upload.
Coco fetches each address before the render. During the fetch, the render stays `queued` with `step` `fetching_media`.

- The address starts with `https://`, is on the public internet and has at most 2048 characters.
- A render takes at most 32 addresses.
- Google Drive and Dropbox share links work. Share a Drive file with "Anyone with the link".
- Coco reads the file type from the bytes, not from the name.
- A file has at most 2 GiB. An account fetches at most 10 GiB a month. `get_usage` shows `url_media_bytes_used`.
- Coco keeps a fetched file for 24 hours. A second render of the same address in that time fetches nothing.
- A caption clip takes an audio variable given by URL. See Captions.
- A failed fetch fails the render with `media_fetch_failed`, `media_too_large`, `media_timeout`, `media_wrong_type` or `url_media_limit`. The message names the field and the host.
