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 },
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions the two action outcomes but lacks critical details: whether this is a read/write operation, if it requires external GraphViz installation, rate limits, error handling, or what happens when saving files (overwrites? permissions?). The description is insufficient for a tool with 7 parameters and file operations.

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

Conciseness4/5

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

The description is a single, efficient sentence that front-loads the core purpose ('Create graph diagrams using GraphViz') followed by the two main actions. There's no wasted text, though it could be slightly more structured (e.g., separating purpose from options).

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 (7 parameters, file operations, no output schema, and no annotations), the description is incomplete. It doesn't explain what a 'DOT graph description' is, how the output looks (URL format? file location?), error conditions, or dependencies. For a tool that can save files and generate images, more context is needed for safe and effective use.

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 description coverage is 100%, so the schema already documents all 7 parameters thoroughly. The description adds minimal value beyond the schema—it mentions 'get diagram image URL or save diagram image to file' which aligns with the 'action' parameter but doesn't provide additional context about parameter interactions or usage examples. Baseline 3 is appropriate when schema does heavy lifting.

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 tool's purpose: 'Create graph diagrams using GraphViz' with specific verbs ('create', 'get', 'save') and resources ('diagrams', 'image URL', 'file'). It distinguishes from sibling tools by specifying GraphViz rather than other visualization libraries like ApexCharts or ChartJS, though it doesn't explicitly contrast with all siblings.

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

Usage Guidelines3/5

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

The description implies usage context by mentioning two actions ('get diagram image URL or save diagram image to file'), but provides no explicit guidance on when to choose this tool over alternatives like 'create-chart-using-*' tools or 'create-diagram' (if existed). It doesn't mention prerequisites, limitations, or specific scenarios favoring GraphViz.

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

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