drawio-mcp-server
Copilot instructions81 starsChanged 9 months agoMITView on GitHub
This is a TypeScript MCP (Model Context Protocol) server for programmatic Draw.io diagram generation. It produces standard Draw.io XML directly — no browser extension or Draw.io instance required.
- Reads credentials
The file
Show its rules and text
We split this copilot-instructions.md into the rules it gives an agent
13 rules. About 0 are common, 6 are distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 19
Use the Draw.io MCP server for all diagram generation tasks.
- Distinctive: line 20
When asked to create diagrams such as flowcharts, decision trees, technical architecture diagrams, etc., always use the Draw.io MCP server …
- Distinctive: line 24
Follow the coding conventions and project structure outlined below to ensure consistency and readability across the codebase.
- Very specific: line 48
Pure functions: Prefer pure functions with no side effects for logic (config parsing, validation).
- Very specific: line 50
Input validation: All tool inputs are validated with Zod schemas defined in tool_definitions.ts and applied at registration time in …
- Distinctive: line 51
Shape resolution order: When resolving shape names, the code checks in order: basic shapes (exact, case-insensitive) → Azure exact match …
- Very specific: line 52
ESM path helpers: Use esmDirname(import.meta.url) (from src/utils.ts) instead of the raw dirname(fromFileUrl(import.meta.url)) boilerplate …
- Distinctive: line 56
Follow this 3-step pattern:
- Very specific: line 68
Run tests: deno task test | Watch mode: deno task test:watch | With coverage: deno task test:coverage
- Distinctive: line 70
Always add or update tests when modifying tool handlers or core model logic.
- Very specific: line 107
All diagram generation conventions — layout, shape selection, styling, labels, batch workflow, containment, import/export, and saving — are …
- Very specific: line 110
When generating diagrams, follow the conventions in src/instructions.md.
- Very specific: line 111
When modifying diagram conventions, update only src/instructions.md.
≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
GitHub Copilot Instructions for this Repository
Project Overview
This is a TypeScript MCP (Model Context Protocol) server for programmatic Draw.io diagram generation. It produces standard Draw.io XML directly — no browser extension or Draw.io instance required.
- Runtime: Deno ≥ 2.7
- Language: TypeScript (strict mode)
- Key dependencies:
@modelcontextprotocol/sdk,hono(HTTP transport),zod(input validation),fuzzy-search,fast-xml-parser - Deno standard libraries:
@std/path,@std/cli,@std/assert,@std/testing,@std/encoding - Test framework: Deno's built-in test runner (
deno test) with V8 coverage
General
- Use the Draw.io MCP server for all diagram generation tasks.
- When asked to create diagrams such as flowcharts, decision trees, technical architecture diagrams, etc., always use the Draw.io MCP server and XML format.
- Content returned from the Draw.io MCP server will be in XML format. Take this content and create or update a
.drawiofile in the repository with that content. - Store generated Markdown documents in
docs/and update any links accordingly. - Prioritize speed, memory footprint, and maintainability in all implementations. The server should be efficient and responsive, even with large diagrams.
- Follow the coding conventions and project structure outlined below to ensure consistency and readability across the codebase.
Repository Structure
src/— Source codedocs/— Generated Markdown documentationsrc/index.ts— Entry point, server lifecycle (startup, shutdown, transport)src/tool_definitions.ts— Centralized tool metadata (names, descriptions, Zod input schemas,TOOL_NAMESconstant)src/tool_registrations.ts— Loops overTOOL_DEFINITIONSto register all tools on the MCP serversrc/tools.ts— Tool handler implementations (thehandlersobject)src/tool_handler.ts— Factory that wires handlers to the MCP serversrc/diagram_model.ts— Core diagram model (cells, layers, pages, XML generation)src/config.ts— CLI/env configuration parsing (pure functions)src/utils.ts— Shared utilities (esmDirname,readRelativeFile— ESM path helpers)src/instructions.md— Server instructions sent to MCP clients during initializationsrc/shapes/— Shape libraries (Azure icons, basic shapes)src/loggers/— Logger implementations (console, MCP server)tests/— Test files (*.test.ts)build/— Compiled binary (git-ignored, generated bydeno task compile)assets/azure-public-service-icons/— Azure icon library XML
Coding Conventions
- Error handling: Return
Error | Tunion types instead of throwing exceptions. SeeparseConfig(),parseHttpPortValue(), andparseLoggerType()inconfig.tsfor examples. In tool handlers, returnerrorResult()with aStructuredErrorcontainingcode,message, andsuggestionfields. - Pure functions: Prefer pure functions with no side effects for logic (config parsing, validation). Side effects are isolated to
index.ts. - Tool naming: Tool name constants are centralized in the
TOOL_NAMESobject intool_definitions.tsusingUPPER_SNAKE_CASEkeys (e.g.,TOOL_NAMES.ADD_CELLS). Tool names exposed to MCP clients usekebab-case(e.g.,add-cells). - Input validation: All tool inputs are validated with Zod schemas defined in
tool_definitions.tsand applied at registration time intool_registrations.ts. - Shape resolution order: When resolving shape names, the code checks in order: basic shapes (exact, case-insensitive) → Azure exact match (by title/ID) → Azure fuzzy search (top result). This priority prevents fuzzy search from hijacking basic shape names like "start" or "end".
- ESM path helpers: Use
esmDirname(import.meta.url)(fromsrc/utils.ts) instead of the rawdirname(fromFileUrl(import.meta.url))boilerplate for__dirname. UsereadRelativeFile(import.meta.url, ...segments)to read a text file relative to the calling module. Both helpers use@std/pathfor path manipulation andDeno.readTextFileSyncfor file reads.
Adding New Tools
Follow this 3-step pattern:
- Define the tool in
src/tool_definitions.ts— add aTOOL_DEFINITIONSentry with key, name, description,hasArgs, and (if applicable)inputSchema. - Add the handler in
src/tools.ts— add a new entry to thehandlersobject with the tool'skebab-casename as the key. - Add tests in
tests/— create or extend a*.test.tsfile covering the new handler logic.
tool_registrations.ts loops over TOOL_DEFINITIONS automatically — no manual registration step needed.
Testing
- Tests live in
tests/*.test.tsand use Deno's built-in test runner with@std/testing/bdd(describe/it) and@std/assert. src/index.tsis excluded from coverage (entry point with side effects).- Run tests:
deno task test| Watch mode:deno task test:watch| With coverage:deno task test:coverage - Benchmarks:
deno task bench(runstests/performance.bench.ts) - Always add or update tests when modifying tool handlers or core model logic.
Build and CI
| Command | Description |
deno task compile | Compile to a self-contained native binary in build/ |
deno task dev | Watch mode — auto-rebuild on changes |
deno task lint | Lint and type-check (deno lint + deno check src/ tests/) |
deno task fmt | Format all files |
deno task fmt:check | Check formatting without modifying files |
deno task test | Run all tests |
deno task test:watch | Run tests in watch mode |
deno task test:coverage | Run tests with V8 coverage (HTML report) |
deno task bench | Run performance benchmarks |
deno task inspect | Launch MCP Inspector for interactive debugging |
deno task update | Update dependencies, lockfile, and Docker Deno version |
deno task start | Start with stdio + HTTP transports |
deno task start:http | Start with HTTP transport only |
deno.jsonis the single configuration file — it defines tasks, imports, compiler options, lint/fmt rules, and test settings.tsconfig.jsonexists for IDE compatibility butdeno.jsoncompilerOptionsare authoritative.
Environment Variables
The server automatically loads .env files at startup using @std/dotenv. Create a .env file from .env.example for local development configuration.
| Variable | Description |
AZURE_ICON_LIBRARY_PATH | Path to Azure icon library XML file (auto-detected from assets/ if unset) |
LOGGER_TYPE | console (default) or mcp_server |
HTTP_PORT | HTTP server port (default: 8080, CLI --http-port takes precedence) |
TRANSPORT | Transport type: stdio, http, or stdio,http (CLI --transport takes precedence) |
SAVE_DIAGRAMS | ⚠️ DEV MODE ONLY — Auto-save diagram XML to ./diagrams/ (accepts true or 1) |
Diagrams
All diagram generation conventions — layout, shape selection, styling, labels, batch workflow, containment, import/export, and saving — are defined in src/instructions.md. That file is the single source of truth:
- It is loaded by the MCP server at startup and sent to every MCP client (including Copilot) via the server's
instructionsfield. - When generating diagrams, follow the conventions in
src/instructions.md. - When modifying diagram conventions, update only
src/instructions.md. Do not duplicate diagram rules in this file.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

