Skip to main content
Glama

generate_diagram

Generate architecture, sequence, flow, and class diagrams from Python code using the diagrams package. Creates PNG files without display.

Instructions

Generate a diagram from Python code using the diagrams package.

This tool accepts Python code as a string that uses the diagrams package DSL and generates a PNG diagram without displaying it. The code is executed with show=False to prevent automatic display.

USAGE INSTRUCTIONS: Never import. Start writing code immediately with with Diagram( and use the icons you found with list_icons.

  1. First use get_diagram_examples to understand the syntax and capabilities

  2. Then use list_icons to discover all available icons. These are the only icons you can work with.

  3. You MUST use icon names exactly as they are in the list_icons response, case-sensitive.

  4. Write your diagram code following python diagrams examples. Do not import any additional icons or packages, the runtime already imports everything needed.

  5. Submit your code to this tool to generate the diagram

  6. The tool returns the path to the generated PNG file

  7. For complex diagrams, consider using Clusters to organize components

  8. Diagrams should start with a user or end device on the left, with data flowing to the right.

CODE REQUIREMENTS:

  • Must include a Diagram() definition with appropriate parameters

  • Can use any of the supported diagram components (GCP, K8s, etc.)

  • Can include custom styling with Edge attributes (color, style)

  • Can use Cluster to group related components

  • Can use custom icons with the Custom class

COMMON PATTERNS:

  • Basic: provider.service("label")

  • Connections: service1 >> service2 >> service3

  • Grouping: with Cluster("name"): [components]

  • Styling: service1 >> Edge(color="red", style="dashed") >> service2

IMPORTANT FOR CLINE: Always send the current workspace directory when calling this tool! The workspace_dir parameter should be set to the directory where the user is currently working so that diagrams are saved to a location accessible to the user.

Supported diagram types:

  • GCP architecture diagrams

  • Sequence diagrams

  • Flow diagrams

  • Class diagrams

  • Kubernetes diagrams

  • On-premises diagrams

  • Custom diagrams with custom nodes

Returns: Dictionary with the path to the generated diagram and status information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesPython code using the diagrams package DSL. The runtime already imports everything needed so you can start immediately using `with Diagram(`
timeoutNoThe timeout for diagram generation in seconds. Default is 90 seconds.
filenameNoThe filename to save the diagram to. If not provided, a random name will be generated.
workspace_dirNoThe user's current workspace directory. CRITICAL: Client must always send the current workspace directory when calling this tool! If provided, diagrams will be saved to a 'generated-diagrams' subdirectory.
Behavior4/5

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

With no annotations, the description fully explains execution details (show=False, runtime imports), return value (path to PNG), and code requirements. Minor gap: no mention of error handling or potential side effects.

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?

Well-structured with sections and bullet points; all content is relevant and front-loaded. Slightly long but justified by the complexity of the tool.

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 coverage: explains prerequisites, code patterns, supported diagram types, return value, and all parameters. No output schema needed given the clear description of returned path and status.

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

Parameters5/5

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

Schema coverage is 100%, and the description adds significant context: code format, timeout default, filename generation, workspace_dir behavior (saves to 'generated-diagrams' subdirectory).

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 clearly states it generates a PNG diagram from Python code using the diagrams package. It distinguishes from sibling tools by referencing get_diagram_examples and list_icons as prerequisites.

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?

Provides explicit step-by-step usage instructions, including when to use this tool (after getting examples and listing icons), what not to do (never import), and important notes about the workspace_dir parameter.

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/lesonky/gcp-diagrams-mcp-server'

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