Skip to main content
Glama

export_scene

Export Excalidraw diagrams as PNG or SVG files with customizable options for elements, background, and padding.

Instructions

Export the canvas as PNG or SVG

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formatYes
elementIdsNo
backgroundNo
paddingNo

Implementation Reference

  • Main handler function exportSceneTool that parses args using ExportSchema and calls client.exportScene with format, elementIds, background, and padding options
    export async function exportSceneTool(
      args: unknown,
      client: CanvasClient
    ) {
      const { format, elementIds, background, padding } = ExportSchema.parse(args);
      const result = await client.exportScene(format, {
        elementIds,
        background: background ?? undefined,
        padding,
      });
      return result;
    }
  • MCP tool registration with name 'export_scene', description, zod schema for validation (format, elementIds, background, padding), and handler that calls client.exportScene and formats response based on format type
    // --- Tool: export_scene ---
    server.tool(
      'export_scene',
      'Export the canvas as PNG or SVG',
      {
        format: z.enum(['png', 'svg']),
        elementIds: z.array(IdZ).max(LIMITS.MAX_ELEMENT_IDS).optional(),
        background: z.string().max(LIMITS.MAX_COLOR_LENGTH).optional(),
        padding: z.number().min(0).max(500).finite().optional(),
      },
      async ({ format, elementIds, background, padding }) => {
        try {
          const result = await client.exportScene(format, { elementIds, background, padding });
          if (format === 'svg') {
            return { content: [{ type: 'text', text: result.data as string }] };
          }
          return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] };
        } catch (err) {
          return { content: [{ type: 'text', text: `Error: ${(err as Error).message}` }], isError: true };
        }
      }
    );
  • ExportSchema zod validation schema defining format (enum png/svg), optional elementIds array, optional background color (ColorSchema), and optional padding number
    export const ExportSchema = z
      .object({
        format: z.enum(['png', 'svg']),
        elementIds: z
          .array(z.string().max(LIMITS.MAX_ID_LENGTH))
          .max(LIMITS.MAX_ELEMENT_IDS)
          .optional(),
        background: ColorSchema,
        padding: z.number().min(0).max(500).finite().optional(),
      })
      .strict();
  • CanvasClient.exportScene method that makes POST request to /api/export endpoint with format and options, handles response for SVG (returns text) and PNG (returns JSON)
    async exportScene(
      format: 'png' | 'svg',
      options?: { elementIds?: string[]; background?: string; padding?: number }
    ): Promise<{ data: string | Record<string, unknown>; contentType: string }> {
      const res = await fetch(`${this.baseUrl}/api/export`, {
        method: 'POST',
        headers: this.headers(),
        body: JSON.stringify({ format, ...options }),
      });
    
      if (!res.ok) {
        const body = await res.json().catch(() => ({})) as ApiResponse;
        throw new Error(body.error ?? `Canvas error: ${res.status}`);
      }
    
      if (format === 'svg') {
        return { data: await res.text(), contentType: 'image/svg+xml' };
      }
    
      return { data: await res.json() as Record<string, unknown>, contentType: 'application/json' };
    }
  • Standalone mode adapter exportScene implementation that builds basic SVG from stored elements or returns message for PNG export when canvas server is unavailable
    async exportScene(
      format: 'png' | 'svg',
      _options?: { elementIds?: string[]; background?: string; padding?: number }
    ): Promise<{ data: string | Record<string, unknown>; contentType: string }> {
      // Full export requires the canvas server's rendering pipeline.
      // In standalone mode, return a basic SVG representation or a note.
      const elements = await this.store.getAll();
      if (format === 'svg') {
        const svg = buildBasicSvg(elements);
        return { data: svg, contentType: 'image/svg+xml' };
      }
      return {
        data: { message: 'PNG export requires the canvas server. Use SVG or connect to canvas server.' },
        contentType: 'application/json',
      };
    }
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It states the export function but doesn't disclose critical traits: whether this is a read-only operation, if it requires specific permissions, potential rate limits, file size constraints, or what happens if elementIds are invalid. For a tool with 4 parameters and no annotation coverage, this is a significant gap.

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?

The description is extremely concise with a single, front-loaded sentence: 'Export the canvas as PNG or SVG'. Every word earns its place, clearly stating the core function without redundancy. It's appropriately sized for a straightforward export tool.

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

Completeness2/5

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

Given the tool's complexity (4 parameters, no annotations, no output schema), the description is incomplete. It lacks details on behavioral aspects (e.g., side effects, error handling), parameter meanings, and usage context. Without annotations or output schema, the description should provide more comprehensive guidance but falls short, leaving gaps for effective tool invocation.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate but adds no parameter details. It mentions 'PNG or SVG' which aligns with the 'format' enum, but doesn't explain 'elementIds', 'background', or 'padding' parameters. For a tool with 4 parameters (1 required, 3 optional) and low schema coverage, the description provides insufficient semantic context beyond the basic format hint.

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

Purpose4/5

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

The description clearly states the action ('Export') and resource ('the canvas'), specifying output formats (PNG or SVG). It distinguishes from siblings like 'create_element' or 'update_element' by focusing on export rather than creation or modification. However, it doesn't explicitly differentiate from potential similar tools like 'export_document' if they existed.

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

Usage Guidelines2/5

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

No guidance on when to use this tool versus alternatives is provided. The description doesn't mention prerequisites (e.g., needing an existing canvas), exclusions (e.g., not for real-time previews), or comparisons with siblings like 'get_resource' which might retrieve resources differently. Usage is implied by the action but not explicitly contextualized.

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/debu-sinha/excalidraw-mcp-server'

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