agentleFS
simonkurtz-MSFTsimonkurtz-MSFT/drawio-mcp-server/.github/copilot-instructions.md

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
  1. Distinctive:

    Use the Draw.io MCP server for all diagram generation tasks.

    line 19
  2. Distinctive:

    When asked to create diagrams such as flowcharts, decision trees, technical architecture diagrams, etc., always use the Draw.io MCP server …

    line 20
  3. Distinctive:

    Follow the coding conventions and project structure outlined below to ensure consistency and readability across the codebase.

    line 24
  4. Very specific:

    Pure functions: Prefer pure functions with no side effects for logic (config parsing, validation).

    line 48
  5. Very specific:

    Input validation: All tool inputs are validated with Zod schemas defined in tool_definitions.ts and applied at registration time in …

    line 50
  6. Distinctive:

    Shape resolution order: When resolving shape names, the code checks in order: basic shapes (exact, case-insensitive) → Azure exact match …

    line 51
  7. Very specific:

    ESM path helpers: Use esmDirname(import.meta.url) (from src/utils.ts) instead of the raw dirname(fromFileUrl(import.meta.url)) boilerplate …

    line 52
  8. Distinctive:

    Follow this 3-step pattern:

    line 56
  9. Very specific:

    Run tests: deno task test | Watch mode: deno task test:watch | With coverage: deno task test:coverage

    line 68
  10. Distinctive:

    Always add or update tests when modifying tool handlers or core model logic.

    line 70
  11. Very specific:

    All diagram generation conventions — layout, shape selection, styling, labels, batch workflow, containment, import/export, and saving — are …

    line 107
  12. Very specific:

    When generating diagrams, follow the conventions in src/instructions.md.

    line 110
  13. Very specific:

    When modifying diagram conventions, update only src/instructions.md.

    line 111

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
copilot-instructions.md

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 .drawio file 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 code
  • docs/ — Generated Markdown documentation
  • src/index.ts — Entry point, server lifecycle (startup, shutdown, transport)
  • src/tool_definitions.ts — Centralized tool metadata (names, descriptions, Zod input schemas, TOOL_NAMES constant)
  • src/tool_registrations.ts — Loops over TOOL_DEFINITIONS to register all tools on the MCP server
  • src/tools.ts — Tool handler implementations (the handlers object)
  • src/tool_handler.ts — Factory that wires handlers to the MCP server
  • src/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 initialization
  • src/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 by deno task compile)
  • assets/azure-public-service-icons/ — Azure icon library XML

Coding Conventions

  • Error handling: Return Error | T union types instead of throwing exceptions. See parseConfig(), parseHttpPortValue(), and parseLoggerType() in config.ts for examples. In tool handlers, return errorResult() with a StructuredError containing code, message, and suggestion fields.
  • 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_NAMES object in tool_definitions.ts using UPPER_SNAKE_CASE keys (e.g., TOOL_NAMES.ADD_CELLS). Tool names exposed to MCP clients use kebab-case (e.g., add-cells).
  • Input validation: All tool inputs are validated with Zod schemas defined in tool_definitions.ts and applied at registration time in tool_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) (from src/utils.ts) instead of the raw dirname(fromFileUrl(import.meta.url)) boilerplate for __dirname. Use readRelativeFile(import.meta.url, ...segments) to read a text file relative to the calling module. Both helpers use @std/path for path manipulation and Deno.readTextFileSync for file reads.

Adding New Tools

Follow this 3-step pattern:

  1. Define the tool in src/tool_definitions.ts — add a TOOL_DEFINITIONS entry with key, name, description, hasArgs, and (if applicable) inputSchema.
  2. Add the handler in src/tools.ts — add a new entry to the handlers object with the tool's kebab-case name as the key.
  3. Add tests in tests/ — create or extend a *.test.ts file covering the new handler logic.

tool_registrations.ts loops over TOOL_DEFINITIONS automatically — no manual registration step needed.

Testing

  • Tests live in tests/*.test.ts and use Deno's built-in test runner with @std/testing/bdd (describe/it) and @std/assert.
  • src/index.ts is 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 (runs tests/performance.bench.ts)
  • Always add or update tests when modifying tool handlers or core model logic.

Build and CI

CommandDescription
deno task compileCompile to a self-contained native binary in build/
deno task devWatch mode — auto-rebuild on changes
deno task lintLint and type-check (deno lint + deno check src/ tests/)
deno task fmtFormat all files
deno task fmt:checkCheck formatting without modifying files
deno task testRun all tests
deno task test:watchRun tests in watch mode
deno task test:coverageRun tests with V8 coverage (HTML report)
deno task benchRun performance benchmarks
deno task inspectLaunch MCP Inspector for interactive debugging
deno task updateUpdate dependencies, lockfile, and Docker Deno version
deno task startStart with stdio + HTTP transports
deno task start:httpStart with HTTP transport only
  • deno.json is the single configuration file — it defines tasks, imports, compiler options, lint/fmt rules, and test settings.
  • tsconfig.json exists for IDE compatibility but deno.json compilerOptions are 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.

VariableDescription
AZURE_ICON_LIBRARY_PATHPath to Azure icon library XML file (auto-detected from assets/ if unset)
LOGGER_TYPEconsole (default) or mcp_server
HTTP_PORTHTTP server port (default: 8080, CLI --http-port takes precedence)
TRANSPORTTransport 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 instructions field.
  • 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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.