I needed an mcp for lexidraw.app
README.md

Lexidraw MCP App Server #

An MCP server that draws Excalidraw diagrams in your chat and saves them to your PDS.

Lexidraw compatible. Sign in with an atproto account and the model gets four extra tools — list_scenes, load_scene, save_scene, delete_scene — that manage app.lexidraw.scene drawings on the user's own PDS. Records open unchanged at lexidraw.app. See Lexidraw setup.

Demo

Install #

This fork has no hosted endpoint — run it yourself, either locally (below) or as a server (see Docker or Vercel).

Run it locally #

To build from source:

git clone https://tangled.org/scoiattolo.mountainherder.xyz/lexidraw-mcp
cd lexidraw-mcp
pnpm install && pnpm run build

Lexidraw setup (atproto) #

With atproto auth configured, users sign in with their Bluesky/atproto identity and the model can manage their Lexidraw drawings on the user's own PDS. A drawing is an app.lexidraw.scene record: the scene JSON (exactly {type, version, source, elements, appState}, gzipped at level 6) stored as a blob. Those are the same bytes lexidraw.app writes, so records round-trip between the two with no conversion. Share links look like https://lexidraw.app/s/<did>/<rkey>.

Set no atproto environment variables and you get the plain anonymous server described above — the PDS tools don't exist. The atproto layer is opt-in.

Environment variables #

Variable Default What it does
LEXIDRAW_MCP_PUBLIC_URL (unset) Public bare https origin (no path or query). Setting it turns on hosted mode: web OAuth login and a bearer-gated /mcp.
LEXIDRAW_MCP_AUTH (unset) off forces the anonymous server; required or loopback enables bearer auth without a public URL (tokens come from --login); hosted requires the URL.
LEXIDRAW_MCP_DATA_DIR ./.lexidraw-mcp-data (/data in Docker) OAuth sessions, states, bearer tokens (hashed, mode 0600), and per-user checkpoints.
LEXIDRAW_MCP_SCOPE atproto repo:app.lexidraw.scene blob:application/gzip OAuth scope. Use atproto transition:generic only for old self-hosted PDSs without granular scopes.
LEXIDRAW_MCP_LEXIDRAW_BASE https://lexidraw.app Base URL for share links.
LEXIDRAW_MCP_MAX_CHECKPOINTS 1000 Per-user cap on stored render checkpoints, pruned oldest-first.
LEXIDRAW_MCP_HANDLE (unset) Default handle for --login.
LEXIDRAW_MCP_DID (unset) Picks a session when several are stored on one instance.
LEXIDRAW_MCP_LOGIN_PASTE (unset) 1/true/yes forces the paste-the-callback fallback for --login even when stdin is piped (human-run only).
LEXIDRAW_MCP_LOGIN_TIMEOUT_MS 300000 How long --login waits for the OAuth callback (loopback or pasted) before timing out.
PORT 3001 HTTP listen port.

Local single-user login #

node dist/index.js --login alice.bsky.social   # opens a localhost OAuth callback, prints a bearer token once, exits
node dist/index.js --stdio                     # serves the PDS tools from the stored session

--login stores the session under LEXIDRAW_MCP_DATA_DIR, so the next plain --stdio run serves the PDS tools without re-auth. --stdio --login <handle> does both: it logs in and continues into serving, printing diagnostics to stderr because stdout carries the MCP protocol.

Headless over SSH: if the browser runs on a different machine, its redirect can never reach this one's 127.0.0.1 callback — the browser shows a "connection refused" page, which is expected. The login still completes: approve in the browser on any device, copy the full address-bar URL (it starts with http://127.0.0.1:<port>/oauth/callback?code=…), and paste it into the terminal. The code is exchanged server-to-server from the headless machine, so no local browser is needed. Paste mode is automatic on interactive terminals; pass --paste or set LEXIDRAW_MCP_LOGIN_PASTE=1 to force it when stdin is piped — for scripted drivers that keep stdin open and answer the prompt after reading the printed URL from the process output (a one-shot echo url | pipe can't work, since the callback URL is only printed after the process starts). LEXIDRAW_MCP_LOGIN_TIMEOUT_MS (default 300000) extends the 5-minute wait if you need to switch machines mid-flow.

Hosted deployment #

  1. Put the server behind a public HTTPS origin that proxies /mcp and the auth routes: /, /login, /login/start, /oauth/callback, /oauth-client-metadata.json, /whoami, /logout.
  2. Set LEXIDRAW_MCP_PUBLIC_URL=https://your.host. The client metadata is served at ${PUBLIC_URL}/oauth-client-metadata.json, and that URL is the OAuth client id — atproto web clients host their metadata at their own client id, so there's nothing to pre-register.
  3. Users open /login, authorize, and get a bearer token shown once, plus a ready-to-paste config:
[mcp_servers.lexidraw]
transport = "http"
url = "https://your.host/mcp"

[mcp_servers.lexidraw.auth]
type = "authorization-header"
value = "Bearer <token>"

Any MCP client works the same way: send Authorization: Bearer <token> to /mcp. Without it you get 401 {"error":"unauthorized"}.

Docker #

docker build --platform linux/amd64 -t lexidraw-mcp .
scripts/container-smoke.sh
docker run -p 3001:3001 -e LEXIDRAW_MCP_PUBLIC_URL=https://your.host -v lexidraw-data:/data lexidraw-mcp

The smoke script builds both runtime variants (bundled and install-fallback) and asserts the OAuth metadata and the /mcp auth gate in each. Shipping to an x86_64 host from an arm64 machine? Build with --platform linux/amd64, then load it remotely: docker save lexidraw-mcp | ssh host "sudo ctr -n k8s.io images import --all-platforms -".

Security model #

  • Bearer tokens are 32 random bytes, stored only as SHA-256 hashes on disk, and shown once at login. GET /logout revokes the presented token. GET /logout?all=1 also revokes the atproto grant, every token issued for that DID, and the cached agent.
  • The OAuth scope is deliberately narrow — the server can only touch Lexidraw drawings, not the rest of your repo.
  • Login is bound to the browser that started it via a short-lived HttpOnly SameSite=Lax cookie. /login/start is rate-limited. URL-shaped login targets must be public HTTPS DNS names — no localhost, IP literals, or private networks. OAuth and PDS fetches run through an SSRF-protected fetch with timeouts and a 50 MiB response cap, and gzip decompression is capped at 50 MiB so a malicious PDS can't exhaust the server.
  • save_scene updates use compare-and-swap (swapRecord), so a concurrent edit surfaces as a conflict instead of being overwritten. Saved scenes are canonical snapshots: they open in Lexidraw but don't join its merge/revision history. The server never generates thumbnails, but preserves any existing thumb on update.
  • load_scene is own-repo only — a <did>/<rkey> reference must carry the signed-in user's own DID.
  • Run one replica. OAuth refresh locks and the token store are process-local; two instances sharing a data dir will corrupt session state.

Deploy your own instance (Vercel) #

The anonymous drawing tools deploy to Vercel in a few clicks:

  1. Fork this repo
  2. Import your fork at vercel.com/new
  3. No environment variables needed — just deploy
  4. Your server will be at https://your-project.vercel.app/mcp

The Vercel build serves the drawing tools only. The Lexidraw features need the long-running server (or the Docker image) because OAuth sessions live on disk and can't survive serverless cold starts.

Contributing #

PRs welcome! See Run it locally for build instructions.

Release checklist #

For maintainers
# 1. Bump version in manifest.json and package.json.
# 2. Build and pack.
pnpm run build && mcpb pack .

# 3. Create the GitHub release.
gh release create v0.3.0 excalidraw-mcp-app.mcpb --title "v0.3.0" --notes "What changed"

# 4. Deploy to Vercel.
vercel --prod

Credits #

Built with Excalidraw — a virtual whiteboard for sketching hand-drawn-like diagrams.

License #

MIT