Skip to main content
Glama

add_code

Adds a sandboxed HTML, CSS and JS page as a layer for 3D, shaders, canvas, particle or GSAP animation that keyframes cannot express, driven by seek, adapter or clock.

Instructions

Add a code layer: a page you write (HTML, CSS, JavaScript) drawn into a box, for what keyframes cannot say: three.js and WebGL 3D, shaders, canvas, particles and physics, GSAP, Lottie, CSS animations. It runs in a sandboxed frame (no network to the project, no operations) and gets window.MOGA_CODE = { fps, width, height, seed, theme, colors: { "md.sys.color.primary": "#…", … }, t }. How it is driven (drive, default auto, picked from what the page offers): seek — set window.seek = (t) => { … } and draw time t (seconds from the layer start); any frame in any order, the fastest and the one to prefer, e.g. three.js: pose the scene for t and call renderer.render. adapter — no seek and no clock of its own: GSAP timelines, Lottie and CSS / Web Animations are seeked to t for you. clock — anything else (requestAnimationFrame loops, timers, Date, performance.now, stateful simulations): its clocks are virtual and step exactly one frame at a time, so frames are the same every run, but reaching a time means stepping there from the start (scrubbing back reloads the page). Math.random is seeded by seed in every mode. Load libraries from the project (import_file, then "/media/three.module.min.js" in an import or a script src) rather than the network. The layer is type "code" with props.html; change it later with set_props (html, start, drive, seed), set_motion and set_keyframe like any layer.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "composition": "<composition>"
    },
    "name": "add_code"
  }
}

Input Schema

NameRequiredDescriptionDefault
hNoBox height in px (default: the frame height)
wNoBox width in px (default: the frame width)
xNoCentre x in px (default: the frame centre)
yNoCentre y in px (default: the frame centre)
idNoElement id (default: "code")
fileNoOr an .html file on disk (absolute, or relative to the project) whose text becomes html
htmlNoThe page: markup, <style> and <script> (module scripts work)
intoNoA composition nested inline in this one to put it in (default: this composition itself)
seedNoSeed for Math.random (default 1)
basisNoWhat you read and followed to make this change, as refs from search or lookup: rule:<lint or taste rule>, taste, feedback:<id> (earlier feedback this follows; what it answers goes in feedback), commit:<id> (an earlier change it builds on), asset:, template:, skill:… The person sees them under the change, so they know why it is this way. Name only what shaped it.
driveNoauto
startNoSeconds into the element where the page's time 0 falls (held on its first frame before)
radiusNoCorner radius of the box in px
messageNoOne line saying why, kept with the change in the history
feedbackNoIds of the feedback this change answers (notes and marks from list_notes, list_examples or the conversation). When the person keeps the change it joins the record of that feedback, and when they then mark the feedback resolved it is the fix; when they take it back, the feedback opens again.
confidenceNoHow sure you are this change is what the person wants. high: they asked for exactly this, or you measured it against a reference. medium: you inferred it from the taste, a rule or earlier feedback. low: you are guessing, or it changes something they did not ask about. The person's threshold decides which changes stand by themselves and which wait for them to keep; say it honestly on every change.
compositionYesComposition name (file in compositions/ without .json)

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed5 schema fields changedv0.1.2
    • addedInput schema / properties / confidence
      Added value: +{
      +  "description": "How sure you are this change is what the person wants. high: they asked for exactly this, or you measured it against a reference. medium: you inferred it from the taste, a rule or earlier feedback. low: you are guessing, or it changes something they did not ask about. The person's threshold decides which changes stand by themselves and which wait for them to keep; say it honestly on every change.",
      +  "enum": [
      +    "high",
      +    "medium",
      +    "low"
      +  ]
      +}
    • changedInput schema / properties / id / description
      Previous value: -"Layer id (default: \"code\")"New value: +"Element id (default: \"code\")"
    • addedInput schema / properties / into
      Added value: +{
      +  "description": "A composition nested inline in this one to put it in (default: this composition itself)",
      +  "type": "string"
      +}
    • removedInput schema / properties / scene
      Removed value: -{
      -  "description": "Scene id (default: the first scene)",
      -  "type": "string"
      -}
    • changedInput schema / properties / start / description
      Previous value: -"Scene seconds where the page's time 0 falls (held on its first frame before)"New value: +"Seconds into the element where the page's time 0 falls (held on its first frame before)"
  2. First observedv0.1.0

TDQS

A4.5/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Far exceeds the annotations (which only say non-read-only, non-destructive, non-idempotent, closed-world). It discloses sandboxing and network isolation, the injected window.MOGA_CODE contract, seeding of Math.random, and the critical determinism/scrub tradeoff ('scribbling back reloads the page' for clock mode). That is exactly the context an agent needs to avoid generating a page that behaves non-reproducibly.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Purpose is front-loaded in the opening clause, and nearly every sentence carries load-bearing information for a genuinely complex tool. The `drive` explanation is dense and nested in long parenthetical sentences, which costs some scannability, but no sentence is pure filler.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With 17 parameters, no output schema and non-read-only annotations, the description carries a lot and mostly delivers: creation semantics, sandbox constraints, timing model, library loading, and how to later modify the layer. The remaining gap is that it never says what the call returns or how failures (e.g., malformed html or an unresolvable file path) surface.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 94%, so the baseline is 3; the description earns above that by explaining the semantics of `drive` in real depth (what seek/adapter/clock each require from the page and the performance consequences) and by clarifying `seed` feeds Math.random in every mode. Spatial and metadata params (x, y, w, h, basis, feedback, confidence) are left entirely to the schema, so it is not a 5.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource ('Add a code layer: a page you write (HTML, CSS, JavaScript) drawn into a box') and immediately scopes it against adjacent capability ('for what keyframes cannot say'), enumerating concrete use cases (three.js/WebGL, shaders, canvas, particles, GSAP, Lottie). It also names the layer type and props.html, so the agent knows exactly what artifact is created.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives a clear selection criterion relative to keyframe-driven siblings ('what keyframes cannot say'), which is the main routing decision here. It also routes follow-up edits to set_props, set_motion and set_keyframe. It stops short of explicit when-not-to-use guidance or contrasting against add_sound/add_site style alternatives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Deploy Server

Other Tools