genart.dev
MCP ToolsExport

export_sketch

Export a sketch as a standalone HTML file, raw algorithm code, PNG image, or SVG — producing a self-contained artifact viewable outside the genart editor.

Input Schema

ParameterTypeRequiredDescription
sketchIdstringyesID of the sketch to export
format'html' | 'png' | 'svg' | 'algorithm' | 'zip'yesExport format
outputPathstringyesFile path to write the export
widthnumbernoOverride width for PNG/SVG export (default: sketch canvas width)
heightnumbernoOverride height for PNG/SVG export (default: sketch canvas height)
seednumbernoOverride seed for this export (default: sketch's current seed)
paramsobjectnoOverride params for this export (default: sketch's current params)

Format details

  • html: Self-contained HTML file with the renderer runtime loaded from CDN (p5.js, three.js, etc.), all metadata inlined, and the algorithm embedded. Opens in any browser.
  • png: Rendered PNG at specified or canvas dimensions.
  • svg: For SVG-renderer sketches, the raw SVG output. For other renderers, a rasterized PNG embedded in an SVG container.
  • algorithm: Raw algorithm source code as a plain text file (.js or .glsl depending on renderer).
  • zip: All of the above bundled together plus the .genart source file.

Output Shape

{
  "success": true,
  "sketchId": "noise-grid",
  "format": "html",
  "outputPath": "/absolute/path/to/noise-grid.html",
  "fileSize": 24576,
  "renderer": "p5"
}

Side Effects

  • Writes one or more files to outputPath
  • For html format: fetches no external resources at export time (CDN URLs are embedded as <script src> tags)
  • For png format: renders the sketch headlessly to produce the image
  • Does not modify the source .genart file

Error Cases

ConditionError
Sketch not found"Sketch not found: 'bad-id'"
No workspace open"No workspace is currently open"
outputPath parent directory doesn't exist"Parent directory does not exist: /bad/path"
File already exists at outputPath"File already exists at /path/to/file. Delete it first or use a different path."
Renderer fails during PNG capture"Renderer error for 'noise-grid': [error message]"
SVG format for non-SVG renderer (returns PNG-in-SVG)Not an error — falls back to rasterized export with a notice

Golden Path Example

Request:

{
  "sketchId": "noise-grid",
  "format": "html",
  "outputPath": "~/projects/genart/outputs/noise-grid-export.html"
}

Response:

{
  "success": true,
  "sketchId": "noise-grid",
  "format": "html",
  "outputPath": "/Users/et/projects/genart/outputs/noise-grid-export.html",
  "fileSize": 24576,
  "renderer": "p5"
}

Exported HTML structure (abbreviated):

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Noise Grid — genart.dev</title>
  <style>body { margin: 0; background: #1a1a1a; display: flex; justify-content: center; align-items: center; height: 100vh; }</style>
  <script src="https://cdn.jsdelivr.net/npm/p5@1/lib/p5.min.js"></script>
</head>
<body>
  <main id="sketch-container"></main>
  <script>
    const state = { /* serialized sketch state */ };
    const sketchFn = function sketch(p, state) { /* algorithm */ };
    new p5((p) => sketchFn(p, state), document.getElementById('sketch-container'));
  </script>
</body>
</html>