Skip to main content
Glama
jeel00dev

Excalidraw MCP Server

by jeel00dev

generate_diagram

Generate Excalidraw diagrams from natural language descriptions. Choose from flowchart, mindmap, sequence, architecture, ERD, or freeform diagrams.

Instructions

Generate an Excalidraw diagram from a natural-language description.

Args: description: What the diagram should show, e.g. "user login flow with OAuth and MFA" diagram_type: One of: flowchart, mindmap, sequence, architecture, erd, freeform filename: Output filename without extension (saved to ~/excalidraw_diagrams/)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
descriptionYes
diagram_typeNoflowchart
filenameNodiagram

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler for the 'generate_diagram' tool. It is registered via @mcp.tool(), takes a description, diagram_type, and filename, calls the LLM to generate Excalidraw JSON, validates it, and saves it to disk.
    @mcp.tool()
    async def generate_diagram(
        description: str,
        diagram_type: str = "flowchart",
        filename: str = "diagram",
    ) -> str:
        """Generate an Excalidraw diagram from a natural-language description.
    
        Args:
            description: What the diagram should show, e.g. "user login flow with OAuth and MFA"
            diagram_type: One of: flowchart, mindmap, sequence, architecture, erd, freeform
            filename: Output filename without extension (saved to ~/excalidraw_diagrams/)
        """
        if not await check_llm_health():
            return (
                "ERROR: llama.cpp server is not running at localhost:8080.\n"
                "Start it with:\n"
                "  ./build/bin/llama-server -m models/your-model.gguf --port 8080 -c 8192"
            )
    
        try:
            raw = await generate_with_llm(
                system_prompt=SYSTEM_PROMPT,
                user_message=build_user_prompt(description, diagram_type),
                temperature=0.2,
            )
        except Exception as e:
            return f"ERROR contacting llama.cpp: {type(e).__name__}: {e}"
    
        try:
            json_str = extract_json(raw)
            data = json.loads(json_str)
            data = validate_and_patch(data)
        except (ValueError, json.JSONDecodeError) as e:
            preview = raw[:600].replace("\n", " ")
            return (
                f"ERROR: Could not parse LLM output as valid Excalidraw JSON.\n"
                f"Reason: {e}\n"
                f"LLM response preview: {preview}"
            )
    
        try:
            filepath = save_excalidraw(data, filename)
        except Exception as e:
            return f"ERROR saving file: {e}"
    
        elem_count = len(data["elements"])
        return (
            f"Diagram saved to: {filepath}\n"
            f"Elements: {elem_count}\n"
            f"Open it in Excalidraw: File → Open → select the .excalidraw file"
        )
  • The FastMCP server instance used to register the tool via the @mcp.tool() decorator.
    mcp = FastMCP("excalidraw-mcp")
  • build_user_prompt constructs the user message sent to the LLM. It is called by the generate_diagram handler.
    """
    
    
    def build_user_prompt(description: str, diagram_type: str) -> str:
  • validate_and_patch validates and fills defaults for the Excalidraw JSON returned by the LLM. Called by generate_diagram.
    def validate_and_patch(data: dict) -> dict:
        """Validate top-level structure and fill in any missing element defaults."""
        if data.get("type") != "excalidraw":
            raise ValueError(f"Invalid type field: {data.get('type')!r}")
        if not isinstance(data.get("elements"), list):
            raise ValueError("Missing or invalid 'elements' array")
    
        data.setdefault("version", 2)
        data.setdefault("source", "https://excalidraw.com")
        data.setdefault("appState", {"viewBackgroundColor": "#ffffff"})
        data.setdefault("files", {})
    
        for i, elem in enumerate(data["elements"]):
            for f in _REQUIRED_ELEMENT_FIELDS:
                if f not in elem:
                    raise ValueError(f"Element #{i} (id={elem.get('id')!r}) missing field '{f}'")
            for k, v in _ELEMENT_DEFAULTS.items():
                elem.setdefault(k, v)
    
        return data
  • save_excalidraw saves the diagram JSON to ~/excalidraw_diagrams/. Called by generate_diagram.
    def save_excalidraw(data: dict, filename: str) -> str:
        """Save an Excalidraw document to ~/excalidraw_diagrams/ and return the path."""
        output_dir = Path.home() / "excalidraw_diagrams"
        output_dir.mkdir(parents=True, exist_ok=True)
    
        if not filename.endswith(".excalidraw"):
            filename += ".excalidraw"
    
        filepath = output_dir / filename
        with open(filepath, "w", encoding="utf-8") as fh:
            json.dump(data, fh, indent=2)
    
        return str(filepath)
Behavior3/5

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

No annotations provided, so description carries burden. Discloses save location (~/excalidraw_diagrams/) and allowed diagram types, but lacks details on overwrite behavior, permissions, or 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?

Concise docstring format with front-loaded purpose. No redundant information, but the Args section somewhat duplicates the schema.

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

Completeness3/5

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

Covers key aspects: purpose, parameters, output location, example. But missing behavioral details like file overwrite, error handling, and output format (though output schema exists but unknown).

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

Parameters4/5

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

Schema has 0% coverage, so description compensates well: explains description parameter with example, lists diagram_type options, and clarifies filename extension and save location. Could be more precise about allowed diagram_type values.

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?

Clearly states it generates an Excalidraw diagram from natural language, with an example. Distinguishes from siblings (check_llm_status, list_diagrams) by being the only diagram generation tool.

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?

Implied usage from description, but no explicit when-to-use or when-not-to-use guidance. No comparisons with alternatives, though siblings are unrelated.

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/jeel00dev/exclalidraw_mcp'

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