tldraw-mcp

tldraw-mcp

Minimal MCP server for editing tldraw .tldr files via JSON manipulation. Headless, no browser needed.

Category
访问服务器

README

tldraw-mcp

Minimal MCP server for editing tldraw .tldr files via JSON manipulation. Headless, no browser needed.

Status

Working skeleton. Schema validation is wired (@tldraw/tlschema validators run before every write), fractional indexing uses @tldraw/utils, file writes are guarded by proper-lockfile. Output verified end-to-end against the real tldraw runtime via Store.loadStoreSnapshot() in the contract test layer.

Quick Start

Requires Node ≥ 20.

1. Install (user scope — available in every project):

claude mcp remove tldraw-m9810223 -s user 2>/dev/null; rm -rf ~/.npm/_npx
claude mcp add -s user tldraw-m9810223 -- npx -y github:m9810223/tldraw-mcp

Restart Claude Code. /mcp should now list tldraw-m9810223.

2. Try the demo prompt in Claude Code:

Draw the Shai-Hulud supply-chain attack flow described in this article with MCP `tldraw-m9810223`, save to `./demo.tldr`:
https://semgrep.dev/blog/2026/malicious-dependency-in-pytorch-lightning-used-for-ai-training/

- Match the actors and how data/control flows between them
- Polish the result at the end

3. View the result — drop ./demo.tldr onto tldraw.com, or use the tldraw VS Code extension for live preview.

Shai-Hulud supply-chain attack flow recreated by tldraw-mcp

Source file: docs/demo.tldr

Tools

File / page lifecycle

Tool What it does
create_empty_file Create a fresh .tldr with a default page
create_page Add a new page
list_pages List pages with id, name, ordering index
move_to_page Move shapes; bindings: 'error' | 'pull' | 'cut' controls binding handling

Shapes

Tool What it does
create_rect Create a rectangle (geo shape)
create_text Create a text shape
create_group Group shapes by reparenting them
ungroup Dissolve a group, reparenting its children to the group's parent
connect Arrow + bindings between two same-page shapes
list_shapes List shapes — id, type, x, y, label only
get_shape Full record of one shape by id
update_shape Shallow-merge patch (use nested { "props": {...} } for prop edits)
delete_shape Delete by id; cascade: true (default) also removes attached arrows + bindings

Layout / text fitting

Tool What it does
fit_to_text Resize a geo/text shape to fit its current text content
align Align shapes on an axis (left/right/top/bottom/center-x/center-y)
distribute Even-space shapes between the outermost two
auto_layout Lay shapes out in a horizontal/vertical chain
graph_layout Dagre layout for arrow-connected shapes (best for non-chain topologies)
measure_arrow_labels Report label sizes + endpoint distances for labeled arrows
bend_overlapping_arrows Bend parallel arrows (same shape pair) symmetrically; priority[] keeps important arrows straight. graph_layout calls this automatically.
polish_layout One-shot finisher: fit_to_text every node + graph_layout (auto-bends arrows). Use as the last step after building a fresh diagram.

Discovery & escape hatch

Tool What it does Token cost
search_api List supported shape types + curated required props. Pass {type, verbose:true} to dump live prop names from @tldraw/tlschema for any type (including ones not in the curated list) low / medium
exec_jq Run a jq filter against the file. write=true persists (auto-checkpoint first) varies

Checkpoints (safety)

Tool What it does Token cost
save_checkpoint Copy .tldr to a timestamped backup low
list_checkpoints List backups, newest first low
restore_checkpoint Restore a backup (most recent if checkpoint omitted) low

The token-saving design: tools take primitive args, return ids or ok. The full JSON only enters context when you call get_shape deliberately.

Install / Update / Remove

jq only needed for exec_jq (brew install jq / apt-get install jq).

# Install — user scope: every project on this machine (recommended)
claude mcp remove tldraw-m9810223 -s user 2>/dev/null; rm -rf ~/.npm/_npx
claude mcp add -s user tldraw-m9810223 -- npx -y github:m9810223/tldraw-mcp

# Install — local scope (default): only the current project directory
claude mcp remove tldraw-m9810223 2>/dev/null; rm -rf ~/.npm/_npx
claude mcp add tldraw-m9810223 -- npx -y github:m9810223/tldraw-mcp

The first arg (tldraw-m9810223) is the local server name — pick whatever you like, then refer to it the same way in subsequent commands. Restart Claude Code, then /mcp lists it with 26 tools.

Wire up to other MCP clients

Same JSON shape, different config file location:

Client Config path
Claude Desktop ~/Library/Application Support/Claude/claude_desktop_config.json (macOS)
Cursor ~/.cursor/mcp.json
VS Code .vscode/mcp.json

Bootstrapping a .tldr file

Use the create_empty_file tool, or save an empty canvas from tldraw.com and point tools at the absolute path.

create_empty_file({ file: "/tmp/demo.tldr" })

Viewing / editing the output

Tool Notes
tldraw.com Drag the .tldr file onto the page
tldraw VS Code extension Native .tldr preview + edit inside VS Code; survives file changes from the MCP server
Tldraw Desktop / official editor Drop the file in

The VS Code extension is the smoothest dev loop — keep code path/to/file.tldr open in a tab while the MCP edits it; the editor refreshes on disk change.

Design comparison vs official tldraw-mcp-app

The Cloudflare-hosted official MCP exposes only search + exec (run any JS in a live tldraw Editor). This skeleton goes the opposite way — typed JSON edits over .tldr files — and borrows the discovery pattern (search_api) and escape hatch (exec_jq) so an LLM can fall through when typed tools don't cover an operation.

Official tldraw-mcp-app This skeleton
Transport streamable-http + sse (Cloudflare) stdio (works in Claude Code directly)
Runtime Real tldraw Editor in widget iframe Pure Node, edits raw JSON
Tools 2 (search, exec) + checkpoints 26: file/page (4) + shape (9) + layout (8) + discovery (2) + ckpt (3)
Live preview Yes (widget iframe) No (open the file in tldraw to view)
Coverage Whole Editor API Geo / text / arrow + jq escape hatch

Known gaps

  • index (z-order) only supports appending above the current max — no insert-between
  • No image / video / asset support
  • Schema version pinning is informational only — opening a file in a newer tldraw may trigger migrations
  • search_api curated list is hand-maintained alongside the live @tldraw/tlschema reflection

Architecture

src/
  index.ts       MCP server entry, tool registration (stdio transport)
  tools.ts       Tool handlers + zod input schemas
  shapes.ts      tldraw record factories (geo/text/arrow/group/binding)
  store.ts       Load/save .tldr + withFileLock; helpers (id gen, indexing, find, page-of-shape, bindings-for-shape)
  template.ts    Empty .tldr generator using @tldraw/tlschema serialize()
  validate.ts    validateShape / validateBinding using createShapeValidator + createBindingValidator
  checkpoint.ts  Timestamped backups under .tldraw-mcp-checkpoints/
  jq.ts          Shell-out to jq for the exec_jq escape hatch
  text-metrics.ts Text size heuristics for autoFit + label measurement
  graph-layout.ts Dagre wrapper for graph_layout
  arrow-bending.ts Detect parallel-edge overlap + assign symmetric bend values

test/
  unit/          store + validate + text-metrics + arrow-bending (34 tests)
  integration/   tools end-to-end on tmp .tldr (39 tests)
  contract/      loadStoreSnapshot against real @tldraw/store (4 tests)
  boundary/      N-1 / N / N+1 limits + concurrent writes (89 tests)

Pure JSON manipulation — no @tldraw/store, no DOM, no React.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选