Skip to main content
Glama

export_preview

Render an .icon bundle preview as PNG with Liquid Glass effects, customizable background and zoom. Falls back to flat composite when Icon Composer is not available.

Instructions

Render a preview of an .icon bundle. Uses Apple's ictool for Liquid Glass rendering by default (falls back to flat composite if Icon Composer is not installed). Supports canvas backgrounds and zoom.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
bundle_pathYesPath to .icon bundle
output_pathYesOutput path for the PNG file
sizeNoOutput size in pixels
appearanceNoAppearance mode to preview (omit for default/light)
flatNoForce flat composite rendering (skip ictool/Liquid Glass)
canvas_bgNoSimple preset canvas background
apple_presetNoApple Icon Composer preset background (overrides canvas_bg)
canvas_bg_colorNoCustom hex color for canvas background
canvas_bg_imageNoPath to custom background image
zoomNoZoom level — icon size relative to canvas (1.0 = full canvas, 0.5 = half size)
return_imageNoReturn the rendered image inline as base64 (default true)

Implementation Reference

  • The main handler function that executes the export_preview tool logic. It decides whether to use ictool (Liquid Glass) or flat rendering, handles canvas backgrounds, zoom, and returns the result with inline base64 image support.
    export async function exportPreview(params: ExportPreviewParams): Promise<McpResult> {
      try {
        const useIctool = !params.flat && await ictoolAvailable();
    
        const renditionMap: Record<string, string> = { dark: 'Dark', tinted: 'TintedLight' };
        const rendition = params.appearance ? renditionMap[params.appearance] ?? 'Default' : 'Default';
    
        let buffer: Buffer;
        let renderer: string;
    
        if (useIctool) {
          const canvasBg = resolveCanvasBackgroundParam(params);
          const hasCanvas = canvasBg.type !== 'none' || params.zoom !== 1.0;
    
          const tmpPath = params.output_path + '.ictool.png';
          try {
            await renderWithIctool({
              bundlePath: params.bundle_path,
              outputPath: tmpPath,
              rendition,
              width: params.size,
              height: params.size,
            });
            const raw = await fs.readFile(tmpPath);
    
            if (hasCanvas) {
              // Canvas will be composited later — keep full squircle
              buffer = raw;
            } else {
              // No canvas — glass glyph without squircle outline.
              // 1. Scale down glyph in manifest (smaller relative to app outline)
              // 2. Render ictool at bigger size (outline pushed outside crop zone)
              // 3. Crop center at target size — outline gone, glyph at correct px
              // The two factors cancel: glyph pixels = same as normal render.
              const INSCRIBED_RATIO = 0.55;
              const renderSize = Math.ceil(params.size / INSCRIBED_RATIO);
    
              // Temporarily shrink layer scales in the manifest
              const { manifest } = await readIconBundle(params.bundle_path);
              const origScales: number[] = [];
              for (const group of manifest.groups) {
                for (const layer of group.layers) {
                  const pos = layer.position ?? { scale: 1.0, 'translation-in-points': [0, 0] as [number, number] };
                  if (!layer.position) layer.position = pos;
                  origScales.push(pos.scale);
                  pos.scale *= INSCRIBED_RATIO;
                }
              }
              await saveManifest(params.bundle_path, manifest);
    
              const tmpLarge = params.output_path + '.ictool-large.png';
              try {
                await renderWithIctool({
                  bundlePath: params.bundle_path,
                  outputPath: tmpLarge,
                  rendition,
                  width: renderSize,
                  height: renderSize,
                });
                const largeRaw = await fs.readFile(tmpLarge);
    
                // Crop center at target size — squircle outline is outside
                const cropOffset = Math.round((renderSize - params.size) / 2);
                const cropped = await sharp(largeRaw)
                  .extract({ left: cropOffset, top: cropOffset, width: params.size, height: params.size })
                  .png()
                  .toBuffer();
    
                // Composite onto fill-color canvas
                const fill = resolveFill(manifest, params.appearance);
                let bgColor = { r: 255, g: 255, b: 255 };
                if (fill && typeof fill === 'object' && 'solid' in fill) {
                  const parts = fill.solid.split(':')[1]?.split(',').map(Number);
                  if (parts && parts.length >= 3) {
                    bgColor = {
                      r: Math.round(parts[0] * 255),
                      g: Math.round(parts[1] * 255),
                      b: Math.round(parts[2] * 255),
                    };
                  }
                }
                buffer = await sharp({
                  create: { width: params.size, height: params.size, channels: 4, background: { ...bgColor, alpha: 255 } },
                })
                  .composite([{ input: cropped, left: 0, top: 0 }])
                  .png()
                  .toBuffer();
              } finally {
                // Restore original scales
                let i = 0;
                for (const group of manifest.groups) {
                  for (const layer of group.layers) {
                    if (layer.position && i < origScales.length) {
                      layer.position.scale = origScales[i++];
                    }
                  }
                }
                await saveManifest(params.bundle_path, manifest);
                await fs.unlink(tmpLarge).catch(() => {});
              }
            }
          } finally {
            await fs.unlink(tmpPath).catch(() => {});
          }
          renderer = 'liquid-glass';
        } else {
          const { manifest, assets } = await readIconBundle(params.bundle_path);
          buffer = await renderPreview(manifest, assets, params.size, params.appearance);
          renderer = 'flat';
        }
    
        const canvasBg = resolveCanvasBackgroundParam(params);
    
        if (canvasBg.type !== 'none' || params.zoom !== 1.0) {
          const iconSize = Math.round(params.size * params.zoom);
          buffer = await compositeOnBackground(buffer, canvasBg, params.size, iconSize);
        }
    
        await fs.writeFile(params.output_path, buffer);
    
        const content: McpContentBlock[] = [
          { type: 'text', text: `Exported preview to ${params.output_path} (${params.size}x${params.size}, ${renderer}, zoom: ${params.zoom}x, bg: ${params.canvas_bg_image ? 'image' : params.canvas_bg_color ?? params.canvas_bg ?? 'none'})` },
        ];
        if (params.return_image !== false && buffer.length <= MAX_INLINE_IMAGE_BYTES) {
          content.push({ type: 'image', data: buffer.toString('base64'), mimeType: 'image/png' });
        }
        return { content };
      } catch (error: unknown) {
        const msg = error instanceof Error ? error.message : 'Unknown error';
        return { content: [{ type: 'text', text: `Error: ${msg}` }], isError: true };
      }
    }
  • TypeScript interface defining all input parameters for the exportPreview handler.
    export interface ExportPreviewParams {
      bundle_path: string;
      output_path: string;
      size: number;
      appearance?: 'dark' | 'tinted';
      flat: boolean;
      canvas_bg?: string;
      apple_preset?: string;
      canvas_bg_color?: string;
      canvas_bg_image?: string;
      zoom: number;
      return_image?: boolean;
    }
  • src/server.ts:163-181 (registration)
    Tool registration on the MCP server using server.tool(), including the name 'export_preview', description, Zod schema for params, and the handler binding.
    // ── Tool: export_preview ──
    server.tool(
      'export_preview',
      'Render a preview of an .icon bundle. Uses Apple\'s ictool for Liquid Glass rendering by default (falls back to flat composite if Icon Composer is not installed). Supports canvas backgrounds and zoom.',
      {
        bundle_path: z.string().describe('Path to .icon bundle'),
        output_path: z.string().describe('Output path for the PNG file'),
        size: z.number().min(16).max(2048).default(1024).describe('Output size in pixels'),
        appearance: z.optional(z.enum(['dark', 'tinted'])).describe('Appearance mode to preview (omit for default/light)'),
        flat: z.boolean().default(false).describe('Force flat composite rendering (skip ictool/Liquid Glass)'),
        canvas_bg: z.optional(z.enum(['none', 'light', 'dark', 'checkerboard', 'homescreen-light', 'homescreen-dark'])).describe('Simple preset canvas background'),
        apple_preset: z.optional(z.enum(['sine-purple-orange', 'sine-gasflame', 'sine-magenta', 'sine-green-yellow', 'sine-purple-orange-black', 'sine-gray'])).describe('Apple Icon Composer preset background (overrides canvas_bg)'),
        canvas_bg_color: z.optional(z.string()).describe('Custom hex color for canvas background'),
        canvas_bg_image: z.optional(z.string()).describe('Path to custom background image'),
        zoom: z.number().min(0.1).max(3.0).default(1.0).describe('Zoom level — icon size relative to canvas (1.0 = full canvas, 0.5 = half size)'),
        return_image: z.boolean().default(true).describe('Return the rendered image inline as base64 (default true)'),
      },
      async (params) => exportPreview(params),
    );
  • src/server.ts:8-8 (registration)
    Import statement that brings exportPreview from ops-render into server.ts for registration.
    import { exportPreview, renderLiquidGlass, exportMarketing } from './lib/ops-render';
  • Helper function that resolves canvas background parameters (image, color, apple preset, or preset name) into a CanvasBackground object used by exportPreview.
    export function resolveCanvasBackgroundParam(params: {
      canvas_bg_image?: string;
      canvas_bg_color?: string;
      apple_preset?: string;
      canvas_bg?: string;
    }): CanvasBackground {
      if (params.canvas_bg_image) {
        return { type: 'image', path: params.canvas_bg_image };
      } else if (params.canvas_bg_color) {
        return { type: 'solid', color: params.canvas_bg_color };
      } else if (params.apple_preset) {
        return { type: 'apple-preset', name: params.apple_preset as ApplePresetName };
      } else if (params.canvas_bg && params.canvas_bg !== 'none') {
        return { type: 'preset', name: params.canvas_bg as any };
      }
      return { type: 'none' };
    }
Behavior4/5

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

With no annotations, the description fully discloses key behaviors: default ictool usage, fallback to flat composite, and support for canvas backgrounds and zoom. It does not cover auth or destructive aspects, but as a preview tool, these are less critical.

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

Conciseness5/5

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

Two sentences, no wasted words. Front-loaded with the core purpose and followed by key technical details. Ideal conciseness for an AI agent.

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?

Despite 11 parameters and no output schema, the description covers essential behavior, fallback, and output options. It could include more on typical use cases or parameter interactions, but overall adequate.

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

Parameters3/5

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

Schema coverage is 100%, so baseline is 3. The description adds context on default rendering and fallback but does not elaborate on individual parameters beyond what the schema already provides.

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?

The description clearly states the tool renders a preview of .icon bundles, specifying the default rendering tool (ictool) and fallback. It distinguishes from sibling tools like export_marketing and render_liquid_glass by focusing on preview output.

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?

The description explains default behavior and fallback, and mentions support for backgrounds and zoom. However, it does not explicitly compare with alternatives like render_liquid_glass or export_marketing, leaving some ambiguity about when to choose each.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ethbak/icon-composer-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server