Skip to main content
Glama

mermaid_save

Save rendered Mermaid diagrams to files after previewing and tuning. Export diagrams in SVG, PNG, or PDF formats to specified file paths for documentation and sharing.

Instructions

Save the current live Mermaid diagram to a file path. This copies the already-rendered diagram from the live preview to the specified location. Use this after tuning your diagram with mermaid_preview.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formatNoOutput format (default: svg). Must match the format used in mermaid_preview.svg
preview_idYesID of the preview to save. Must match the preview_id used in mermaid_preview.
save_pathYesPath to save the diagram file (e.g., './docs/diagram.svg')

Implementation Reference

  • Core handler function for the mermaid_save tool. Validates input, renders diagram if needed, and saves the file to the specified path.
    export async function handleMermaidSave(args: any) { const savePath = args.save_path as string; const previewId = args.preview_id as string; const format = (args.format as string) || "svg"; if (!savePath) { throw new Error("save_path parameter is required"); } if (!previewId) { throw new Error("preview_id parameter is required"); } // Validate save path to prevent path traversal attacks try { validateSavePath(savePath); } catch (error) { mcpLogger.error("Save path validation failed", { savePath, error: error instanceof Error ? error.message : String(error), }); return { content: [ { type: "text", text: `Invalid save path: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } try { const liveFilePath = getDiagramFilePath(previewId, format); try { await access(liveFilePath); } catch { const diagram = await loadDiagramSource(previewId); const options = await loadDiagramOptions(previewId); await renderDiagram( { diagram, previewId, format, ...options, }, liveFilePath ); } const saveDir = dirname(savePath); await mkdir(saveDir, { recursive: true }); await copyFile(liveFilePath, savePath); return { content: [ { type: "text", text: `Diagram saved to: ${savePath} (${format.toUpperCase()})`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error saving diagram: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } }
  • Input schema defining parameters for mermaid_save: save_path (required), preview_id (required), format (optional, defaults to svg).
    inputSchema: { type: "object", properties: { save_path: { type: "string", description: "Path to save the diagram file (e.g., './docs/diagram.svg')", }, preview_id: { type: "string", description: "ID of the preview to save. Must match the preview_id used in mermaid_preview.", }, format: { type: "string", enum: ["png", "svg", "pdf"], description: "Output format (default: svg). Must match the format used in mermaid_preview.", default: "svg", }, }, required: ["save_path", "preview_id"], },
  • src/index.ts:86-114 (registration)
    Tool definition registration in TOOL_DEFINITIONS array, including name, description, and input schema.
    { name: "mermaid_save", description: "Save the current live Mermaid diagram to a file path. " + "This copies the already-rendered diagram from the live preview to the specified location. " + "Use this after tuning your diagram with mermaid_preview.", inputSchema: { type: "object", properties: { save_path: { type: "string", description: "Path to save the diagram file (e.g., './docs/diagram.svg')", }, preview_id: { type: "string", description: "ID of the preview to save. Must match the preview_id used in mermaid_preview.", }, format: { type: "string", enum: ["png", "svg", "pdf"], description: "Output format (default: svg). Must match the format used in mermaid_preview.", default: "svg", }, }, required: ["save_path", "preview_id"], }, },
  • src/index.ts:147-150 (registration)
    Dispatch case in CallToolRequestSchema handler that calls the handleMermaidSave function.
    case "mermaid_save": result = await handleMermaidSave(args); mcpLogger.info(`CallTool completed: ${toolName}`); return result;
  • src/index.ts:14-14 (registration)
    Import of the handleMermaidSave handler function.
    import { handleMermaidPreview, handleMermaidSave } from "./handlers.js";

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/veelenga/claude-mermaid'

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