uml-mcp

TikZ Diagrams

UML-MCP supports TikZ/PGF graphics via Kroki. You can render TikZ and LaTeX snippets to SVG, PDF, PNG, or JPEG without installing TeX locally.

Overview

Use diagram_type: "tikz" with the generate_uml or generate_diagram_url tools. The code parameter is your TikZ/LaTeX source (snippet or full document).

Available templates and examples

The TikZ module provides a template library and auto-wrapping:

Templates (via tools.kroki.tikz.TikZTemplateLibrary) include:

Template Description
flowchart Decision/process flowchart
graph Simple node-and-edge graph
math_plot 2D function plot (pgfplots)
tree Tree structure
automata Finite state machine
geometry_circle Circle and axes
mindmap_simple Mind map
circuit_simple Simple circuit (IEC)
coordinate_grid XY grid
block_diagram Input–Process–Output blocks

Example files are in examples/:

Output format comparison

Format Best for Notes
SVG Web, scaling Vector, small size
PDF Print, documents Vector, high quality
PNG Presentations, UI Raster, good compatibility
JPEG Photos, large areas Raster, smaller files

Use output_format in the tool call (e.g. "svg", "pdf", "png", "jpeg").

Common patterns

Flowchart (uses shapes, arrows, positioning):

\begin{tikzpicture}[node distance=2cm]
  \node[rectangle, draw] (start) {Start};
  \node[diamond, draw, below of=start] (dec) {OK?};
  \draw[->] (start) -- (dec);
\end{tikzpicture}

Math plot (uses pgfplots):

\begin{tikzpicture}
  \begin{axis}[xlabel=$x$, ylabel=$f(x)$, grid=major]
    \addplot[blue, domain=-2:2] {x^2};
  \end{axis}
\end{tikzpicture}

Automata (uses automata, positioning):

\begin{tikzpicture}[shorten >=1pt, node distance=2cm]
  \node[state, initial] (q0) {$q_0$};
  \node[state, accepting, right of=q0] (q1) {$q_1$};
  \draw[->] (q0) to node {1} (q1);
\end{tikzpicture}

Tips for complex diagrams

Local vs Kroki rendering

Aspect Kroki (default) Local (Docker)
Setup None Docker build/run
Network Required Optional
Custom TeX Kroki’s environment Your image
Use case Most diagrams Offline or custom deps

To use optional local compilation, set USE_LOCAL_LATEX=true and use the LaTeX Docker setup under tools/docker/ (see Optional Docker).

Optional Docker

For local LaTeX/TikZ compilation without Kroki:

  1. Build and start the container from the project root:
    docker compose -f tools/docker/docker-compose.latex.yml build
    docker compose -f tools/docker/docker-compose.latex.yml up -d
    
  2. Compile a .tex file inside the container (e.g. from examples/):
    docker exec -it uml-mcp-latex xelatex -interaction=nonstopmode /workspace/examples/example-tikz-flowchart.tex
    

See tools/docker/README.md for details and volume mounts.