Skip to main content
Glama

mermaid_to_excalidraw

Convert Mermaid flowchart syntax into an Excalidraw diagram. Supports graph directions, node shapes, edge types, and subgraphs with auto-detected component styling.

Instructions

Convert Mermaid flowchart syntax into an Excalidraw diagram.

Supports the mermaid flowchart subset that AI agents commonly generate:

  • Directions: graph TD, LR, BT, RL

  • Node shapes: [text], {text}, ((text)), ([text])

  • Edge types: -->, ---, -.-> ==> with |label|

  • Subgraphs: subgraph Title ... end

Component types are auto-detected from node labels (e.g., a node labeled "PostgreSQL DB" automatically gets database styling).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
mermaid_syntaxYesMermaid flowchart source code.
output_pathYesFile path to save the .excalidraw file.
themeNoColor theme - "default", "dark", "colorful". Default: "default"default

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The tool handler function for 'mermaid_to_excalidraw'. It calls parse_mermaid() to parse the mermaid syntax, compute_layout() for layout, build_excalidraw_file() to render, save_excalidraw() to persist, then returns a summary string.
    @mcp.tool
    def mermaid_to_excalidraw(
        mermaid_syntax: str,
        output_path: str,
        theme: str = "default",
    ) -> str:
        """Convert Mermaid flowchart syntax into an Excalidraw diagram.
    
        Supports the mermaid flowchart subset that AI agents commonly generate:
        - Directions: graph TD, LR, BT, RL
        - Node shapes: [text], {text}, ((text)), ([text])
        - Edge types: -->, ---, -.->  ==>  with |label|
        - Subgraphs: subgraph Title ... end
    
        Component types are auto-detected from node labels (e.g., a node labeled
        "PostgreSQL DB" automatically gets database styling).
    
        Args:
            mermaid_syntax: Mermaid flowchart source code.
            output_path: File path to save the .excalidraw file.
            theme: Color theme - "default", "dark", "colorful". Default: "default"
    
        Returns:
            Summary of the converted diagram.
        """
        graph = parse_mermaid(mermaid_syntax)
        layout = compute_layout(graph)
        doc = build_excalidraw_file(layout, theme_name=theme, direction=graph.direction)
        path = save_excalidraw(doc, output_path)
    
        return (
            f"Converted mermaid to excalidraw at: {path}\n"
            f"Nodes: {len(graph.nodes)}\n"
            f"Connections: {len(graph.edges)}\n"
            f"Subgraphs: {len(graph.subgraphs)}\n"
            f"Direction: {graph.direction.value}\n"
            f"Theme: {theme}\n\n"
            f"Open with the VS Code Excalidraw extension or drag into excalidraw.com"
        )
  • The main parse_mermaid() function that converts mermaid flowchart source into a DiagramGraph intermediate representation. Uses two-pass parsing: pass 1 extracts node definitions and shapes, pass 2 extracts edges.
    def parse_mermaid(source: str) -> DiagramGraph:
        """Parse mermaid flowchart source into a DiagramGraph."""
        nodes: dict[str, Node] = {}
        edges: list[Edge] = []
        subgraphs: list[Subgraph] = []
        direction = Direction.TOP_DOWN
        subgraph_stack: list[Subgraph] = []
    
        for raw_line in source.strip().splitlines():
            line = raw_line.strip()
    
            if not line or line.startswith("%%"):
                continue
            line = re.sub(r"%%.*$", "", line).strip()
            if not line:
                continue
    
            m = _GRAPH_DECL.match(line)
            if m:
                direction = _DIRECTION_MAP.get(m.group(1).upper(), Direction.TOP_DOWN)
                continue
    
            m = _SUBGRAPH_START.match(line)
            if m:
                sg_id = m.group(1) or m.group(3) or _sanitize_id(m.group(4) or "subgraph")
                sg_label = m.group(2) or m.group(4) or m.group(3) or sg_id
                sg = Subgraph(id=sg_id, label=sg_label.strip())
                subgraph_stack.append(sg)
                continue
    
            if _SUBGRAPH_END.match(line):
                if subgraph_stack:
                    subgraphs.append(subgraph_stack.pop())
                continue
    
            # Pass 1: extract node definitions, get cleaned line
            cleaned = _extract_nodes_from_line(line, nodes, subgraph_stack)
    
            # Pass 2: extract edges from cleaned line
            _extract_edges_from_line(cleaned, nodes, edges, subgraph_stack)
    
            # If no edges found and no nodes extracted, try as standalone node
            if not edges or edges[-1].from_id not in {n.id for n in nodes.values()}:
                pass  # Nodes already handled in pass 1
    
        while subgraph_stack:
            subgraphs.append(subgraph_stack.pop())
    
        return DiagramGraph(
            nodes=list(nodes.values()),
            edges=edges,
            subgraphs=subgraphs,
            direction=direction,
        )
  • DiagramGraph model - the intermediate representation produced by the mermaid parser and consumed by the layout engine. Contains nodes, edges, subgraphs, and direction.
    class DiagramGraph(BaseModel):
        """
        The intermediate representation shared across all tools.
    
        Produced by: create_diagram args, mermaid parser, or diagram state manager.
        Consumed by: layout engine -> excalidraw builder.
        """
    
        nodes: list[Node] = Field(default_factory=list)
        edges: list[Edge] = Field(default_factory=list)
        subgraphs: list[Subgraph] = Field(default_factory=list)
        direction: Direction = Direction.LEFT_RIGHT
  • EdgeStyle enum used to map mermaid arrow types (-->, ==>, -.->) to edge styles (solid, thick, dashed, dotted).
    class EdgeStyle(str, Enum):
        """Visual style for edges/arrows."""
    
        SOLID = "solid"
        DASHED = "dashed"
        DOTTED = "dotted"
        THICK = "thick"
  • The @mcp.tool decorator registers 'mermaid_to_excalidraw' as a FastMCP tool. No explicit name arg means the function name is used as the tool name.
    @mcp.tool
Behavior4/5

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

No annotations are provided, so the description carries full burden. It discloses that component types are auto-detected from node labels (e.g., 'PostgreSQL DB' gets database styling), which is a key behavioral trait. It also lists supported directions, node shapes, edge types, and subgraphs, providing good transparency for a conversion tool.

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 reasonably concise with three paragraphs. The main purpose is stated in the first sentence. Each section adds value, though the list of supported syntax could be slightly trimmed. Overall, it is well-structured and front-loaded.

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

Completeness4/5

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

Given the tool's complexity (converting Mermaid flowcharts to Excalidraw), the description covers the supported syntax, auto-detection behavior, and output path. An output schema exists, so return values need not be detailed. Minor omissions like error handling or file overwrite behavior do not significantly detract from completeness.

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?

The input schema already has 100% coverage and clear descriptions for all three parameters. The description adds value by explaining the supported Mermaid syntax subset and auto-detection, but this is not directly tied to individual parameter semantics. Thus a baseline score of 3 is appropriate.

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 the tool converts Mermaid flowchart syntax to an Excalidraw diagram, specifying the verb 'Convert' and the resources 'Mermaid flowchart syntax' and 'Excalidraw diagram'. This distinguishes it from sibling tools that create, export, get info, or modify diagrams.

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 details the supported Mermaid subset but does not explicitly state when to use this tool versus alternatives like create_diagram or modify_diagram. It implies usage for conversion tasks but lacks explicit guidance on when not to use it.

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/BV-Venky/excalidraw-architect-mcp'

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