Skip to main content
Glama

Save Content

save

Save rendered content to disk as text or raster images. Automatically detects format from file extension, prevents overwriting with numeric counters, and supports SVG and PNG outputs.

Instructions

Save rendered content to disk. Format-aware: can save as text or render to raster image.

IMPORTANT: Use this only AFTER iterating on the design with render and preview. Do not save on the first render. Preview and refine your work first.

Format detection:

  • 'auto' (default): infers format from file extension. .svg saves as text, .png renders to image.

  • 'svg': saves content as a UTF-8 text file

  • 'png': renders the content (assumed SVG) to a PNG image, then saves it

If the file already exists, a numeric counter is appended before the extension to prevent overwriting: design.svg becomes design-1.svg, then design-2.svg. The actual saved path is returned in the response.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYesContent to save. This is typically the output of a render tool such as render_svg.
outputPathYesFile path to save to. The directory must already exist. If the file already exists, a numeric counter is appended before the extension: design.svg becomes design-1.svg, then design-2.svg, and so on. The actual saved path is returned in the response.
formatNoOutput format. 'auto' infers from file extension (.svg saves as text, .png renders to image). 'svg' saves content as a UTF-8 text file. 'png' renders SVG content to a PNG image before saving.auto
widthNoFor raster formats (png): render width in pixels. Defaults to the source content's own declared dimensions.

Implementation Reference

  • Registration of the 'save' tool in src/index.ts.
    // Tool: save
    // ---------------------------------------------------------------------------
    
    server.registerTool(
      "save",
      {
        title: "Save Content",
        description: `
    Save rendered content to disk. Format-aware: can save as text or render to raster image.
    
    IMPORTANT: Use this only AFTER iterating on the design with render and preview.
    Do not save on the first render. Preview and refine your work first.
    
    **Format detection:**
    - 'auto' (default): infers format from file extension. .svg saves as text, .png renders to image.
    - 'svg': saves content as a UTF-8 text file
    - 'png': renders the content (assumed SVG) to a PNG image, then saves it
    
    If the file already exists, a numeric counter is appended before the extension
    to prevent overwriting: design.svg becomes design-1.svg, then design-2.svg.
    The actual saved path is returned in the response.
        `.trim(),
        inputSchema: z.object({
          content: z
            .string()
            .describe(
              "Content to save. This is typically the output of a render tool such as render_svg."
            ),
          outputPath: z
            .string()
            .describe(
              "File path to save to. The directory must already exist. " +
                "If the file already exists, a numeric counter is appended before the extension: " +
                "design.svg becomes design-1.svg, then design-2.svg, and so on. " +
                "The actual saved path is returned in the response."
            ),
          format: z
            .enum(["auto", "svg", "png"])
            .default("auto")
            .describe(
              "Output format. " +
                "'auto' infers from file extension (.svg saves as text, .png renders to image). " +
                "'svg' saves content as a UTF-8 text file. " +
                "'png' renders SVG content to a PNG image before saving."
            ),
          width: z
            .number()
            .positive()
            .optional()
            .describe(
              "For raster formats (png): render width in pixels. " +
                "Defaults to the source content's own declared dimensions."
            ),
        }),
      },
      async ({ content, outputPath, format, width }) => {
        const start = Date.now();
        try {
          const savedPath = await saveContent(content, outputPath, format, width);
          const elapsed = Date.now() - start;
          console.error(`[nakkas] save OK — ${savedPath}, ${elapsed}ms`);
          return {
            content: [{ type: "text", text: `Saved to: ${savedPath}` }],
          };
        } catch (err) {
          const message = err instanceof Error ? err.message : String(err);
          console.error(`[nakkas] save ERROR — ${message}`);
          return {
            content: [{ type: "text", text: `Error saving file: ${message}` }],
            isError: true,
          };
        }
      }
    );
  • The implementation logic of the 'save' tool, which delegates to saveContent in src/save.ts.
    export async function saveContent(
      content: string,
      outputPath: string,
      format: "auto" | "svg" | "png",
      width?: number
    ): Promise<string> {
      const resolved = await resolveOutputPath(outputPath);
      const effectiveFormat = format === "auto" ? inferFormat(resolved) : format;
    
      if (effectiveFormat === "png") {
        const pngBuffer = svgToPng(content, width);
        await writeFile(resolved, pngBuffer);
      } else {
        await writeFile(resolved, content, "utf-8");
      }
    
      return resolved;
    }
  • Helper for resolving output paths with automatic filename incrementing for collision prevention.
    export async function resolveOutputPath(requested: string): Promise<string> {
      const exists = (p: string) =>
        access(p)
          .then(() => true)
          .catch(() => false);
    
      if (!(await exists(requested))) return requested;
    
      const dir = dirname(requested);
      const ext = extname(requested);
      const stem = basename(requested, ext);
    
      for (let i = 1; ; i++) {
        const candidate = join(dir, `${stem}-${i}${ext}`);
        if (!(await exists(candidate))) return candidate;
      }
    }
Behavior4/5

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

With no annotations provided, the description carries full behavioral disclosure burden. It explains file collision handling (numeric counter appending), format conversion assumptions ('assumed SVG'), and return value ('actual saved path is returned'). Minor gap: could mention permission requirements or error conditions.

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?

Excellent structure with clear visual hierarchy: single-sentence purpose, format capability summary, emphasized workflow constraint ('IMPORTANT'), bulleted format detection rules, and collision behavior note. No redundant or wasted text.

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

Completeness5/5

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

Comprehensive for a 4-parameter file I/O tool with no annotations. Covers: purpose, workflow context, detailed format conversion logic, file system mutation behavior (collision handling), and response structure. Compensates adequately for missing output schema.

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 100% (baseline 3), but description adds significant value: explains 'content' typically comes from render tools, details the logic behind format enum values (auto-detection rules), and clarifies the relationship between outputPath extensions and format behavior.

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 opens with a specific verb-resource combination ('Save rendered content to disk') and clearly distinguishes this tool's role from siblings by establishing it as the final persistence step in a workflow involving 'render' and 'preview'.

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

Usage Guidelines5/5

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

Contains explicit temporal guidance ('Use this only AFTER iterating') and names sibling tools ('render and preview') to establish clear workflow precedence. Explicitly states anti-pattern ('Do not save on the first render').

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/arikusi/nakkas'

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