# noddle draw MCP server Lets an AI agent (Claude Code, Claude Desktop, or any MCP client) **work on a board alongside you**: read, create and edit boards, browse version history, and comment like any other collaborator. noddle draw is **anonymous**. There are no accounts and no tokens. A board id (12 hex chars) or a board URL is the capability. The agent can open any board you give it, and anyone holding the link of a board the agent creates can open it too. The agent signs its comments and version snapshots with `NODDLE_AGENT_NAME`. - **Stdlib-only** Python ≥ 3.9 (`urllib` + `json`), so there is nothing to install. - **stdio transport**: one JSON-RPC 2.0 message per line. stdout carries only protocol messages, and logs go to stderr. - **MCP protocol, dual-era**: - **2026-07-28 (modern, stateless)**: every request carries `_meta["io.modelcontextprotocol/protocolVersion"]` + `clientCapabilities`. The server implements `server/discover`, and sets `resultType` and `_meta["io.modelcontextprotocol/serverInfo"]` on every result, plus `ttlMs`/`cacheScope` on list/read results. An unsupported version returns `-32022 UnsupportedProtocolVersion`. - **Legacy `initialize` handshake**: 2025-11-25, 2025-06-18, 2025-03-26, 2024-11-05. The server answers with the client's version when it supports it, and otherwise with 2025-11-25. `ping` works in this mode. JSON-RPC batches are accepted only for 2025-03-26, the only revision that allowed them. ## 1. Register **Claude Code** (from the repo root; an absolute script path is more robust): ```bash claude mcp add noddle -- python3 mcp/noddle_mcp.py # a self-hosted instance instead of draw.noddle.dev: claude mcp add noddle --env NODDLE_BASE_URL=http://127.0.0.1:8000 -- python3 mcp/noddle_mcp.py ``` **Claude Desktop** (`~/Library/Application Support/Claude/claude_desktop_config.json`) or a project `.mcp.json` use the same shape: ```json { "mcpServers": { "noddle": { "command": "python3", "args": ["/absolute/path/to/noddle-draw/mcp/noddle_mcp.py"], "env": { "NODDLE_BASE_URL": "https://draw.noddle.dev" } } } } ``` **MCP Bundle** (one-click install in Claude Desktop and other MCPB clients): download `noddle-draw.mcpb` from the [latest `mcpb-v*` release](https://github.com/noddle-dev/noddle-draw/releases) and open it. It needs only Python 3.10+ (standard library, no install step). **From a checkout** (`pyproject.toml` here): ```bash uvx --from ./mcp noddle-draw-mcp # or: pipx install ./mcp && noddle-draw-mcp ``` The server is listed in the [official MCP Registry](https://registry.modelcontextprotocol.io) as `dev.noddle/draw` (see [Releasing](#releasing)). | Env | Default | | |---|---|---| | `NODDLE_BASE_URL` | `https://draw.noddle.dev` | http(s) origin of the noddle draw instance. A non-http(s) value exits with code 2 | | `NODDLE_AGENT_NAME` | `MCP agent` | display name on comments and version history (max 40 chars) | | `NODDLE_TIMEOUT` | `30` | seconds per board API call | | `NODDLE_AI_TIMEOUT` | `180` | seconds for `generate_diagram` | | `NODDLE_AI_PROVIDER` | — | optional BYOK for `generate_diagram`: `claude`, `openai`, `gemini`, `openrouter` or `custom` | | `NODDLE_AI_KEY` | — | your AI provider key. It is sent only to `NODDLE_BASE_URL`, as the same `X-AI-*` headers the web app uses, and never stored. Unset means the instance's shared pool is used, if it has one | | `NODDLE_AI_MODEL` | — | optional model override | | `NODDLE_AI_BASE` | — | OpenAI-compatible base URL (provider `custom` only) | CLI: `--help`, `--version`, `--list-tools` (prints the tool definitions as JSON). Exit codes: `0` when stdin closes (normal shutdown), `2` for bad configuration. ## 2. Tools Every tool returns `structuredContent` that conforms to its `outputSchema`, plus the same JSON as a text block. Board tools also return a `resource_link` to `noddle://board/{id}` (revisions ≥ 2025-06-18). Wherever a tool takes `doc_id`, you can pass either the 12-hex id or the board URL (`{base}/d/{id}` or `/embed/{id}`). A URL on a different origin than `NODDLE_BASE_URL` is refused. | Tool | readOnly | destructive | idempotent | openWorld | What it does | |---|---|---|---|---|---| | `read_board_summary` | ✓ | | | ✗ | **Read this first.** Geometry-free semantic graph: diagram/page `metadata`, `groups` (frames + members), `nodes` `{id,text,kind,group,meta}`, `flows` (`A --[HTTPS]--> B`) and an `edit_revision`. Legacy boards get groups/roles inferred from frames and shape kinds | | `get_board` | ✓ | | | ✗ | Name, url, `my_role` (`editor`/`viewer`), `updated_at`, diagram `metadata`, a short-lived `edit_revision`, page summary and the LIVE diagram JSON (includes edits awaiting browser autosave). Optional `page_id`, `compact` (drops default fields), `node_ids` (subset + their edges) and `include_svg` (a `page_id` on a multi-page board returns `svg_note` instead of the wrong page's SVG) | | `create_board` | ✗ | ✗ | ✗ | ✗ | Only for an explicitly requested NEW board, with optional diagram JSON and diagram `metadata` (`category` fills `metadata.category`). `category`/`palette`/`auto_fit`/`auto_layout` apply category colors and layout hygiene; `capture=true` returns the PNG + DOM lint in the same call. Anyone with its url can edit it | | `patch_board` | ✗ | ✗ | ✗ | ✗ | **Preferred write.** Small atomic ops (`add`/`update`/`delete` nodes and edges, `add_page`, `rename_page`, `set_metadata`) merged onto the live board with `edit_revision`, plus `metadata` / `page_metadata`. Same hygiene and `capture` / `capture_node_ids` options as `create_board`. Returns `post_save_check` | | `update_board` | ✗ | ✓ | ✓ | ✗ | Send the WHOLE diagram back with `edit_revision` (or `expected_updated_at`): only the fields you changed merge with the live board. A version snapshot is kept. Optional hygiene + `capture`. Returns `post_save_check` | | `clone_diagram` | ✗ | ✗ | ✗ | ✗ | Copy all/selected nodes of one page to the RIGHT on the same page (groups, edges, waypoints remapped) and return old→new id maps plus `clone_node_ids`. The first step before revising a diagram | | `capture_board` | ✓ | | | ✗ | Render one saved page through the editor's own renderer and return an MCP `image/png` block plus pixel-exact DOM `lint` (`include_lint`, default on). `node_ids` crops tightly around a clone/section at 2x. `expected_updated_at` makes a stale capture fail | | `lint_board` | ✓ | | | ✗ | Self-review without a PNG: layout errors/warnings with ids and a fix each, using browser-measured text boxes and the rendered edge routes when a renderer is available | | `join_board` | ✗ | ✗ | ✓ | ✗ | Show the agent (`NODDLE_AGENT_NAME`) in the board's live presence for ~5 min without writing | | `rename_board` | ✗ | ✗ | ✓ | ✗ | Rename | | `list_versions` | ✓ | | | ✗ | Version-history snapshots, newest first | | `get_version` | ✓ | | | ✗ | One snapshot's diagram. To restore it, pass it to `update_board` | | `list_comments` | ✓ | | | ✗ | Comment threads | | `add_comment` | ✗ | ✗ | ✗ | ✗ | Pin to ONE of `node_id` / `edge_id` / `parent_id` (reply) / point `x`,`y` (+ `page_id`). Works on view-only links too | | `generate_diagram` | ✓ | | | ✓ | Turns prose or Mermaid into diagram JSON through the instance's AI (your BYOK key or its shared pool). It **saves nothing**, so pass the result to `create_board`/`update_board` | There is deliberately **no `list_boards` and no delete**: the API has neither. Link access is not discovery, and an anonymous board has no owner who could be trusted to delete it. Writes to a board whose link is view-only fail with a 403 tool error. Diagram payloads are **pass-through**. The server checks only the envelope (`{pages:[{id,nodes,edges}]}` or legacy `{nodes,edges}`, with string ids). Node and edge fields are forwarded untouched, so new editor fields (e.g. the `freedraw` kind with `points`, or `curved` routing) work without a server update. See `DiagramNode` / `DiagramEdge` in `contracts/openapi.yaml`. On writes the MCP server itself may expand `style` / `role` shorthands into category colors and grow/separate the shapes you touched (`auto_fit` / `auto_layout`); every such change is listed in `auto_fixed`. **Semantic metadata (2.1.0).** Boards carry optional, bounded semantics at three levels — diagram `metadata` `{category, summary, domain, tags, owner, version, links, custom}`, page `metadata` `{category, summary, tags, notes, custom}` and node/edge `meta` (≤ 20 keys of primitives, e.g. `role`, `tech`, `layer`, `protocol`, `sla`). `patch_board` takes `metadata` / `page_metadata` or the op `{op:"set_metadata", metadata, page_id?}` (a key set to `null` is removed; `meta` on an `update` op merges key by key). The `role` styling shorthand is also kept as `meta.role`. The server sanitizes everything (`backend/app/domain/diagram_metadata.py`), and the editor shows it quietly (title-island popover, inspector "Semantics", a hover badge). **MCP Apps inline preview.** `capture_board`, `create_board`, `patch_board` and `read_board_summary` declare `_meta.ui.resourceUri = "ui://noddle/preview"`: a static, self-contained `text/html;profile=mcp-app` card (no CDN) that renders the PNG + metadata pushed by the host over `ui/notifications/tool-result`, fits/zooms/pans the image, asks the host to run `capture_board` itself when a result carries no PNG, and opens the board via `ui/open-link`. Errors: - **Bad arguments, API failures (400/403/404/413/422/429/503) and conflicts** come back as `isError: true` tool results that the model can act on. - **Protocol errors** use standard JSON-RPC codes: unknown tool or invalid params `-32602`, unknown method `-32601`, malformed JSON `-32700`, invalid request `-32600`. ## 3. Resources & prompts - **Resources**: `resources/list` lists the boards **this session** has created, read or edited, as `noddle://board/{id}` (`application/json`, `lastModified`). It starts empty, because the API has no listing. `resources/templates/list` exposes `noddle://board/{doc_id}`, so a client can read any board by id. `resources/read` returns the same JSON as `get_board`. An unknown board returns `-32602`. `noddle://style-guide` (markdown: category color maps, style presets, label rules) and `ui://noddle/preview` (MCP Apps HTML) are static and always listed first. - **Prompts**: - `design_board(topic, notes?, doc_id?)`: without `doc_id`, generate → sanity-check → `create_board` → lint/capture → reply with the url. With `doc_id`, the revise-beside-the- original workflow below. - `review_board(doc_id)`: embeds the board as a resource, runs `lint_board` + `capture_board`, and asks for a critique posted as anchored comments. ## 4. Example (Claude Code) ``` > Create a board "Payment flow" with Client → API Gateway → Payment Service → Database, then comment on the Database node reminding the team to review indexes. Claude: generate_diagram(text="Client -> API Gateway -> Payment Service -> Database") → create_board(name="Payment flow", diagram=…) → add_comment(doc_id, body="Please review indexes for the payments table", node_id="db") → returns https://draw.noddle.dev/d/{id} ``` Comments and diagram writes reach an open board in realtime. ## 5. Tests ```bash python3 -m pytest mcp -q # or: python3 -m unittest discover mcp ``` `test_noddle_mcp.py` runs the real server over stdio against a fake in-process REST backend. It covers version negotiation (modern and legacy), schema validity, read and write tools (incl. `edit_revision` read bases, `post_save_check`, `clone_diagram`, `capture_board`, `lint_board`, `join_board`), board-URL ids, view-only links, resources, prompts, BYOK header forwarding and error paths. `backend/tests/test_mcp_comparison.py` and `test_mcp_live_collab.py` drive the same tool table in-process against the real app. The stdio tests also assert that stdout carries only JSON-RPC, that no request ever carries an `Authorization` header, and that a BYOK key never leaks into output or logs. ## Releasing `mcp/server.json` is the registry listing (`dev.noddle/draw`); it points at the MCP Bundle attached to a GitHub release. The `dev.noddle/*` namespace is verified over HTTP: noddle.dev serves the publisher's ed25519 public key at `/.well-known/mcp-registry-auth`. 1. Bump the version everywhere, all equal: `__version__` in `noddle_mcp.py`, `version` in `mcpb/manifest.json`, `version` in `pyproject.toml`, and `version` in `server.json`. Registry versions are immutable; a metadata-only fix uses a suffix such as `1.0.0-1`. 2. Build the bundle: `mcp/build_mcpb.sh` → `mcp/dist/noddle-draw.mcpb` (prints its SHA-256). 3. Create the release with that exact file: `gh release create mcpb-v mcp/dist/noddle-draw.mcpb --title "MCP server "`. 4. In `server.json`, set the package `identifier` to the release download URL and `fileSha256` to the printed hash, then publish with the namespace key holder's `mcp-publisher login http --domain noddle.dev --private-key …` and `mcp-publisher publish mcp/server.json`. ## Notes - `update_board` keeps the stored SVG preview. The preview refreshes on the next save in the editor. - Cross-origin HTTP redirects are refused, so a BYOK key is never forwarded to another host. A BYOK key over plain `http` to a non-loopback host logs a warning. - `generate_diagram` sends text to an AI provider. Never pass customer PII, credentials or account numbers. ## Revising a board beside the original For an existing board, `get_board`, then `clone_diagram` with the saved `expected_updated_at` and the intended `page_id` (mandatory for multi-page boards). The clone sits to the right on the **same canvas**; its new node/group/edge ids come back as maps and originals and other pages stay intact. `node_ids` limits the clone to a fragment; edges crossing outside it are omitted and reported. Edit only the clone ids with `update_board`, then `capture_board` with `page_id` and the returned `updated_at`, inspect the PNG, fix and capture again. Show the before/after and ask whether to keep both, replace the original or move the revision to a new board. Results say `visual_validation: "pending_image_inspection"` — generating an image is not a review. PNG capture needs `web/dist/capture.js` (`npm run build`) and Chromium on the server; the Docker image ships both. It runs offline in a throwaway profile under a network-denying CSP, one capture at a time, 25-second timeout. A missing browser/bundle returns a 503 tool error and nothing else is affected. ## Live collaboration MCP edits don't require closing an open editor. `get_board` returns the live board plus a short-lived `edit_revision`; `update_board` sends that read base as `base_diagram` and the server merges only the fields the agent changed onto the live board — a human's move and the agent's label change both survive; the same field is last-write-wins. Read bases live only in this stdio process (bound to `NODDLE_BASE_URL` + agent name and the board), expire after ten minutes and are capped at twelve. Passing just `expected_updated_at` also uses a cached read base when one matches; without one, a stale revision is a conflict error. Saves are pushed to open editors immediately and show the agent in presence for 30 s; `join_board` shows it for ~5 min without writing. Agent presence carries `kind: "agent"`, and when the agent name contains the word "Claude" the server adds `icon: "claude"` so the editor draws the Claude mark. Like every anonymous identity, the name is display-only. ## Post-save check and lint Every `patch_board` / `update_board` / `clone_diagram` / `create_board` result carries `post_save_check`: `manual_changes` (objects someone else added/removed/modified while you worked — never revert them silently) and `issues` on the pages you changed, each with `yours` (fix yours, report and ask about the rest). Lists are capped at 20 with `*_count` totals. `lint_board {doc_id, page_id?, check_routes?}` uses the same detectors. **Errors**: `stray_shape`, `tiny_shape`, `duplicate`, `overlap`, `straddles_frame`, `text_overlap`, `dangling_edge`, `edge_crosses_shape`, `edge_crosses_text`. **Warnings**: `text_overflow`, `misaligned`, `empty_shape`, `orphan`, `empty_container`, `duplicate_edge`, `verbose_text`, `monochrome_board`. When the page was rendered (`capture=true`, `capture_board`, `lint_board`), text overflow/overlap use the browser-measured `` boxes (`dom_verified: true`) instead of the font-width estimate. Route checks render each page (~2 s); without a renderer the result lists `routes_unchecked` + a `note`.