Skip to main content
Glama

create-diagram-using-graphviz

Generate visual diagrams from DOT graph descriptions, providing image URLs or saving files in SVG or PNG format with customizable layouts.

Instructions

Create graph diagrams using GraphViz - get diagram image URL or save diagram image to file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesWhether to get graph URL or save as file
outputPathNoPath where to save the file (only used with action=save_file)
graphYesDOT graph description
layoutNoGraph layout algorithm (default: dot)
formatNoOutput format (default: svg)
widthNoImage width in pixels
heightNoImage height in pixels

Implementation Reference

  • The main handler function 'handleGraphvizTool' that executes the tool logic: validates inputs, generates GraphViz diagrams via QuickChart API, returns URLs, base64 images, or saves files.
    export async function handleGraphvizTool(args: any): Promise<any> { const graph = args.graph as string; const action = args.action as string; validateGraph(graph); validateAction(action); validateOutputPath(args.outputPath, action); validateLayout(args.layout); validateFormat(args.format); validateDimensions(args.width, args.height); const config = buildGraphvizConfig(graph, { layout: args.layout as string, format: args.format as string, width: args.width as number, height: args.height as number, }); const graphvizUrl = buildGraphvizUrl( graph, args.layout as string || "dot", args.format as string || "svg" ); const result: any = { content: [ { type: "text", text: "Below is the GraphViz diagram URL:", }, { type: "text", text: graphvizUrl, }, ], metadata: { graphvizType: args.layout || "dot", generatedAt: new Date().toISOString(), graphvizUrl: graphvizUrl, }, }; try { const pngData = await fetchGraphvizContent(config, "png"); const pngBase64 = Buffer.from(pngData).toString("base64"); result.content.push( { type: "text", text: "Below is the PNG image:", }, { type: "image", data: pngBase64, mimeType: "image/png", } ); result.metadata.pngBase64 = pngBase64; } catch (error) { result.content.unshift({ type: "text", text: "⚠️ Failed to fetch diagram image", }); result.content.push({ type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}`, }); result.metadata.error = error instanceof Error ? error.message : String(error); } if (action === "get_url") { return result; } const format = (args.format as string) || "svg"; const outputPath = getDownloadPath( args.outputPath as string | undefined, format ); try { const dir = path.dirname(outputPath); if (!fs.existsSync(dir)) { fs.mkdirSync(dir, { recursive: true }); } const data = await fetchGraphvizContent(config, format); if (format === "svg") { fs.writeFileSync(outputPath, data, "utf8"); } else { fs.writeFileSync(outputPath, data); } result.metadata.savedPath = outputPath; result.content.push({ type: "text", text: "Below is the saved file path:", }); result.content.push({ type: "text", text: outputPath, }); return result; } catch (error) { throw new McpError( ErrorCode.InternalError, `Failed to save GraphViz diagram: ${ error instanceof Error ? error.message : String(error) }` ); } }
  • The tool definition including name, description, and inputSchema for validation.
    export const CREATE_DIAGRAM_USING_GRAPHVIZ_TOOL: Tool = { name: "create-diagram-using-graphviz", description: "Create graph diagrams using GraphViz - get diagram image URL or save diagram image to file", inputSchema: { type: "object", properties: { action: { type: "string", enum: ["get_url", "save_file"], description: "Whether to get graph URL or save as file", }, outputPath: { type: "string", description: "Path where to save the file (only used with action=save_file)", }, graph: { type: "string", description: "DOT graph description", }, layout: { type: "string", enum: ["dot", "fdp", "neato", "circo", "twopi", "osage", "patchwork"], description: "Graph layout algorithm (default: dot)", }, format: { type: "string", enum: ["svg", "png"], description: "Output format (default: svg)", }, width: { type: "integer", description: "Image width in pixels", }, height: { type: "integer", description: "Image height in pixels", }, }, required: ["action", "graph"], }, };
  • Registration of the tool handler in the TOOL_HANDLERS mapping.
    "create-diagram-using-graphviz": { handler: handleGraphvizTool, toolName: ToolNames.GRAPHVIZ, },
  • Import of the tool definition and handler from graphviz.ts
    CREATE_DIAGRAM_USING_GRAPHVIZ_TOOL, handleGraphvizTool, } from "./graphviz.js";
  • Inclusion of the tool in the ALL_TOOLS array for conditional enabling.
    { tool: CREATE_DIAGRAM_USING_GRAPHVIZ_TOOL, name: ToolNames.GRAPHVIZ },

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/TakanariShimbo/quickchart-mcp-server'

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