Ask your coding agent:
Read Instructions_for_agents.md in this repository, or https://agentic-mermaid.dev/llms.txt if you don't have a checkout. Draw Browser → API → Database using the hand-drawn style and nord-light palette. Verify it, then return the Mermaid source and an SVG.
Agent setup and skills · Try the same diagram in JavaScript
Docs: docs index · getting started · agent guide · agent API cookbook · design system · skills · fork differences · vs Mermaid & Beautiful Mermaid · changelog
Why Agentic Mermaid
Choose a built-in style, or keep your diagram's colors and fonts in a JSON style file. Inspect the rendered result before publishing.
The agent workflow is the guardrail behind the polish: agents should not guess from pixels, concatenate strings, or regenerate whole diagrams when a structured edit is available.
Highlights
- Discover supported diagrams and edits —
am capabilities --summary indexes what the installed version supports, including registered extensions; am capabilities --family <id> gives one family's full edit schema.
- SVG, PNG, ASCII, Unicode, JSON — export images, review diagrams in the terminal, or inspect positions as JSON layout.
- Render SVG without a browser — the synchronous JavaScript API runs without a DOM or Puppeteer.
- Composable styles —
{ style: ['hand-drawn', 'dracula'] } combines a look with a palette. Set colors, fonts, strokes, fills and backdrops in a JSON style. seed re-rolls the ink, never the layout.
- Match your editor's colors — choose a built-in palette, theme from two colors, or adapt a VS Code theme with Shiki.
- Agent-native editing — use typed operations for modeled syntax. Class and Timeline retain unmodeled statements alongside typed edits; source-preserving mode keeps every authored line an edit does not touch (comments, indentation, quoting) and covers selected opaque Class and Flowchart operations.
- CLI + MCP + library — use
am, connect agentic-mermaid-mcp, or import agentic-mermaid/agent for rendering and editing. See the API reference for the other library and browser entry points.
Installation
Requires Node.js 22 or later, or Bun 1.4.0 or later. The package is ESM-only; use import, or dynamic import() from CommonJS.
The am … examples below name the published bin. After a project-local npm
install, invoke it from a shell as npx --no-install agentic-mermaid … (or
from an npm script as am …). From a source checkout, use
bun run bin/am.ts … instead.
Output quick starts
Use agentic-mermaid/agent when you want one import path for styled renders, output formats, and the structured edit API.
SVG
Save this as diagram.mjs:
Open diagram.svg to see Browser → API → Database in the hand-drawn style with the nord-light palette.
PNG
CLI equivalent:
ASCII / Unicode
Agent quick start
If your coding agent can read repo files, point it at:
If it only has shell access:
For an existing diagram, follow parse → narrow → mutate → verify → serialize. For a new diagram, author Mermaid source, then parse and verify it. To wire Agentic Mermaid into another repo, run npx agentic-mermaid init-agent (or bun run bin/am.ts init-agent from a source checkout); it writes a non-clobbering AGENTS.md section, root skills/ bundle, and .mcp.json sample.
Use strict preview for human inspection and mutate --op/--ops for verified one-shot or batched edits.
For multi-step MCP edits, use Code Mode execute(code) with the same mermaid.* SDK names. See the agent API cookbook for library, CLI and MCP recipes.
MCP server
Agentic Mermaid ships a Model Context Protocol server so MCP-capable agents can render and safely edit diagrams without shelling out.
After installation, start the local stdio server:
Use the library, CLI or local MCP for private diagrams, offline work, larger inputs or local PNG files. The MCP transport guide covers HTTP/SSE and file/URL artifacts; agent setup shows how to generate a sample client configuration. The tool reference and Code Mode guide explains the available tools and multi-step edits.
An optional public, unauthenticated MCP endpoint runs at https://agentic-mermaid.dev/mcp. It accepts MCP JSON-RPC rather than REST render requests, caps inputs at 64 KB and returns PNG as base64. Hosted calls send your source or code to the server; see the privacy notice. Directory maintainers can use the MCP listing record.
Structured edit example
Change the API node's displayed label while keeping its connection to DB:
Output:
The node ID is still API; its displayed label is now API gateway, and the API → DB connection remains. Verification checks for structural and geometry problems; review the rendered result and confirm it expresses your intent before saving.
Rules:
- Use the matching exported
as<Family> narrower before mutating an existing structured diagram.
- Mutation ops use
kind, not type.
- Run
verifyMermaid before every commit point.
- Do not call
mutate on opaque fallback bodies; the narrower returns null for unmodeled syntax.
- To edit an existing file without reformatting it, use source-preserving edits:
mutatePreservingSource, applyOps with mode: 'source-preserving', CLI --preserve-source, or the same MCP and editor-worker mode. Untouched lines stay byte-identical; preservation.method is canonical when an edit had to be re-serialized. For opaque Class/Flowchart inputs the mode supports Class add_member/remove_member and Flowchart set_label/rename_node; save exact source and inspect the retained portability diagnostics.
Supported diagram families
Run am capabilities --summary for the supported families and edit operations in
your installed version, then am capabilities --family <id> for one family's
full entry. See diagram families for
syntax examples and compatibility notes.
More documentation
- System architecture — how Mermaid source becomes a diagram, from parsing to layout and output.
- API reference — renderers, agent API, options, CLI/MCP pointers.
- Vocabulary — families, source objects, Scene parts, resolved primitives and typed-family narrowing.
- Agent API cookbook — practical recipes for agents.
- Theming — two-color themes, built-ins, Shiki compatibility.
- Custom style cookbook — JSON style files, screenshots, schema usage, and CLI commands.
- Fonts in custom styles — font selection, SVG declarations, PNG directories, fallbacks, and browser usage.
- React integration — browser-safe, family-loaded rendering.
- ASCII output — terminal output, color modes, XY charts.
- Mermaid config — frontmatter, init directives, runtime config.
- Features, quality, security, fork differences.
- Adding diagram types for contributors.
Live editor and examples
Contributing and reporting bugs
Report a bug with the Mermaid source, render options and the result you expected. For changes to the project, read the contributor instructions for implementation and testing rules.
To work from a source checkout, use Bun 1.4.0 or later:
Attribution
Agentic Mermaid is a fork of Beautiful Mermaid by Luki Labs. The ASCII rendering engine is based on mermaid-ascii by Alexander Grooff and extended for Agentic Mermaid.
License
MIT
Native Event Modeling and ZenUML authoring and rendering have documented
capability and runtime contracts.