Docs / For AI agents
open-diagram for AI agents
This page is for AI coding agents, such as Claude Code, Cursor and Amp, and for the people who set them up. It lists each way an agent can use open-diagram, with the exact command. open-diagram draws architecture diagrams as SVG and PNG files from JSON, Mermaid or Python, and names each layout problem in plain words.
Updated
How does an agent connect to the MCP server?
Add the server to the app's MCP settings, with one of the setups below. An MCP server is a small program that an AI app starts on your computer, so the AI can draw diagrams as one of its own actions. open-diagram's MCP server accepts JSON and Mermaid only, never Python, and writes files only inside one output folder.
Claude Code:
claude mcp add open-diagram -- uvx open-diagram mcpAmp:
amp mcp add open-diagram -- uvx open-diagram mcpIn Amp, a server added to one folder's settings (amp mcp add --workspace) also needs amp mcp approve open-diagram.
Claude Desktop (claude_desktop_config.json) or Cursor (~/.cursor/mcp.json):
{
"mcpServers": {
"open-diagram": {
"command": "uvx",
"args": ["open-diagram", "mcp", "--out", "/Users/you/Documents/open-diagram"]
}
}
}Replace /Users/you/Documents/open-diagram with the folder for the SVG and PNG files.
uvx is part of uv. The first time, it fetches open-diagram and Python 3.10 or later. uv keeps a copy of what it downloaded. To pick up a new release, add --refresh once after uvx.
Without uv, run pip install open-diagram. Then use open-diagram as the command and mcp as its first argument.
The server has five tools: format_guide, template, check, describe and draw. MCP tools gives each tool's arguments and what it returns.
How does an agent load the agent skill?
Install it with the skills tool. An agent skill is a folder of instructions that an agent loads when it needs them. open-diagram's skill is skills/open-diagram/SKILL.md.
npx skills add lukendeasy/open-diagram --skill open-diagram --agent claude-codeThis writes the skill to .claude/skills/ in the current folder. Add -g to install it for all your projects. For another app, name that app after --agent.
In a copy of the open-diagram repo, you can copy the folder instead:
cp -r skills/open-diagram ~/.claude/skills/How does an agent use the command line?
Run open-diagram with one of these commands. Each one takes a JSON file (.json), a Mermaid flowchart (.mmd or .mermaid), or a Python script (.py) with a build() function that returns a Diagram.
open-diagram check plan.json # lists the layout problems; writes no files
open-diagram describe plan.json # prints what the picture says, in plain words
open-diagram draw plan.json # writes plan.svg and plan.png next to plan.json
open-diagram new # lists the templates
open-diagram new azure_web_app # writes azure_web_app.json to start fromcheck and draw exit with status 1 when the layout has problems. Status 2 means the file could not be read. The message after error: names the place, such as columns[0][0].tiles[0].
PNG files need Chrome, Chromium or Edge. If the browser is not found, set CHROME to its path. The SVG is always written.
Command line lists every option.
How does an agent use the Python library?
Install it with pip, then write a script whose build() function returns a Diagram.
pip install open-diagram
python3 -c "import open_diagram; print(open_diagram.__version__)"open-diagram needs Python 3.10 or later. Check a script with open-diagram check script.py. Python lists every block and placing method.
Where are the docs as plain text?
They are in two text files and in the Markdown copy of each page.
- llms.txt lists the pages, with one line for each.
- llms-full.txt has the Docs pages and the pages in these sections as Markdown, one after another: Diagram examples, Compared, Layout problems, Guides, Prompts and For AI agents.
- Each Docs page, and each page in those six sections, has a Markdown copy at the same address, with
.mdin place of.html. This page's copy is https://open-diagram.dev/for-agents.md.
What are the steps for one diagram?
Write, check, fix, describe, then draw. The steps come from the agent skill. Each step names the command, then the MCP tool.
- If you use the MCP server, call
format_guideonce. - Write the diagram as JSON, Mermaid or Python.
- Run
open-diagram check plan.json, or callcheck. - Fix every problem the check names.
- Run the check again. Repeat until it reports
0 layout problem(s). - Run
open-diagram describe plan.json, or calldescribe. - Compare the description with the request. Every system, state, owner and line the user named must be there, and nothing they did not name.
- Run
open-diagram draw plan.json, or calldraw. - Look at the PNG.
- Tell the user where the SVG and PNG are, and which facts in the picture are your assumptions.
A check that finds a problem prints one line for it:
plan.json: 1 layout problem(s)
- line 'web' -> 'ops' crosses 'orders'; route it with via_x/via_y, move a block, or pass cross_ok=TrueAfter "lane": "top" was added to that link, which routes it above the picture, the check printed plan.json: 0 layout problem(s). Layout problem messages gives the fix for each message.
Which version does this page describe?
Version 0.6.2, from the library's pyproject.toml. To upgrade an install made with pip, run pip install -U open-diagram.
Check PyPI for the latest version: https://pypi.org/project/open-diagram/