excalidraw-mcp

lesleslie/excalidraw-mcp

3.3

If you are the rightful owner of excalidraw-mcp and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

Excalidraw MCP Server is an AI-powered live visual diagramming tool that integrates Excalidraw's drawing capabilities with AI agents for real-time diagram creation and manipulation.

Tools
5
Resources
0
Prompts
0

Excalidraw MCP Server: AI-Powered Live Visual Diagramming

Code style: crackerjack Python: 3.13+ Coverage

๐Ÿ™ Acknowledgments This project is based on and extends the excellent work from yctimlin/mcp_excalidraw. Special thanks to the original contributors for creating the foundation that made this enhanced version possible.

A dual-language MCP (Model Context Protocol) server that combines Excalidraw's powerful drawing capabilities with AI integration, enabling AI agents like Claude to create and manipulate diagrams in real-time on a live canvas.

Features Python FastMCP server with TypeScript canvas server for optimal performance and maintainability.

๐Ÿš€ What This System Does

  • ๐ŸŽจ Live Canvas: Real-time Excalidraw canvas accessible via web browser
  • ๐Ÿค– AI Integration: MCP server allows AI agents (like Claude) to create visual diagrams
  • โšก Real-time Sync: Elements created via MCP API appear instantly on the canvas
  • ๐Ÿ”„ WebSocket Updates: Live synchronization across multiple connected clients
  • ๐Ÿ—๏ธ Production Ready: Clean, minimal UI suitable for end users

๐ŸŽฅ Demo Video

See MCP Excalidraw in Action!

MCP Excalidraw Demo

Watch how AI agents create and manipulate diagrams in real-time on the live canvas

๐Ÿ›๏ธ Architecture Overview

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   AI Agent      โ”‚โ”€โ”€โ”€โ–ถโ”‚   MCP Server     โ”‚โ”€โ”€โ”€โ–ถโ”‚  Canvas Server  โ”‚
โ”‚   (Claude)      โ”‚    โ”‚    (Python)      โ”‚    โ”‚ (Express.js)    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                                         โ”‚
                                                         โ–ผ
                                               โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                               โ”‚  Frontend       โ”‚
                                               โ”‚  (React + WS)   โ”‚
                                               โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Hybrid Architecture Benefits:

  • Python FastMCP: Handles MCP protocol, tool registration, and auto-manages canvas server
  • TypeScript Canvas: Express.js API + WebSocket for real-time canvas synchronization
  • Auto-Management: Python server monitors and restarts canvas server as needed
  • Type Safety: Comprehensive TypeScript definitions ensure consistency across the stack

๐ŸŒŸ Key Features

Modern TypeScript Architecture

  • Full TypeScript Migration: Complete type safety for backend and frontend
  • Comprehensive Type Definitions: Excalidraw elements, API responses, WebSocket messages
  • Strict Type Checking: Enhanced development experience and compile-time error detection
  • Type-Safe React Components: TSX components with proper props typing

Real-time Canvas Integration

  • Elements created via MCP appear instantly on the live canvas
  • WebSocket-based real-time synchronization
  • Multi-client support with live updates

Production-Ready Interface

  • Clean, minimal UI with connection status
  • Simple "Clear Canvas" functionality
  • No development clutter or debug information

Comprehensive MCP API

  • Element Creation: rectangles, ellipses, diamonds, arrows, text, lines
  • Element Management: update, delete, query with filters
  • Batch Operations: create multiple elements in one call
  • Advanced Features: grouping, alignment, distribution, locking

Robust Architecture

  • TypeScript-based Express.js backend with REST API + WebSocket
  • React frontend with official Excalidraw package and TypeScript
  • Dual-path element loading for reliability
  • Auto-reconnection and error handling

๐Ÿ“ฆ Installation & Setup

โœ… Quick Start (Recommended)

1. Clone and Setup
git clone https://github.com/lesleslie/excalidraw-mcp.git
cd excalidraw-mcp

# Install Python dependencies
uv sync

# Install Node.js dependencies and build
npm install
npm run build
2. Start the System
# The Python MCP server auto-starts the canvas server
uv run python excalidraw_mcp/server.py

# Or manually start canvas server (optional)
npm run canvas
3. Access the Canvas

Open your browser and navigate to:

http://localhost:3031

๐Ÿ“‹ Development Setup

# Development mode (TypeScript watch + Vite dev server)
npm run dev

# Or production mode
npm run production

๐Ÿ”ง Available Scripts

ScriptDescription
npm startBuild and start MCP server (dist/index.js)
npm run canvasBuild and start canvas server (dist/server.js)
npm run canvas-bgBuild and start canvas server in background
npm run start-canvasBuild and start canvas server
npm run canvas-for-npxSpecial script for npx usage
npm run start-allStart both servers together
npm run buildBuild both frontend and TypeScript backend
npm run build:frontendBuild React frontend only
npm run build:serverCompile TypeScript backend to JavaScript
npm run build:typesGenerate TypeScript declaration files only
npm run devStart TypeScript watch mode + Vite dev server
npm run dev:serverStart TypeScript in watch mode only
npm run type-checkRun TypeScript type checking without compilation
npm run productionBuild + start in production mode
npm testRun all tests
npm run test:watchRun tests in watch mode
npm run test:coverageRun tests with coverage report
npm run test:unitRun unit tests only
npm run test:integrationRun integration tests only

๐ŸŽฏ Usage Guide

For End Users

  1. Open the canvas at http://localhost:3031
  2. Check connection status (should show "Connected")
  3. AI agents can now create diagrams that appear in real-time
  4. Use "Clear Canvas" to remove all elements

For AI Agents (via MCP)

The MCP server provides these tools for creating visual diagrams:

Basic Element Creation
// Create a rectangle
{
  "type": "rectangle",
  "x": 100,
  "y": 100,
  "width": 200,
  "height": 100,
  "backgroundColor": "#e3f2fd",
  "strokeColor": "#1976d2",
  "strokeWidth": 2
}
Create Text Elements
{
  "type": "text",
  "x": 150,
  "y": 125,
  "text": "Process Step",
  "fontSize": 16,
  "strokeColor": "#333333"
}
Create Arrows & Lines
{
  "type": "arrow",
  "x": 300,
  "y": 130,
  "width": 100,
  "height": 0,
  "strokeColor": "#666666",
  "strokeWidth": 2
}
Batch Creation for Complex Diagrams
{
  "elements": [
    {
      "type": "rectangle",
      "x": 100,
      "y": 100,
      "width": 120,
      "height": 60,
      "backgroundColor": "#fff3e0",
      "strokeColor": "#ff9800"
    },
    {
      "type": "text",
      "x": 130,
      "y": 125,
      "text": "Start",
      "fontSize": 16
    }
  ]
}

๐Ÿ”Œ Integration with Claude Code

โœ… Recommended: uvx Configuration

Add this configuration to your Claude Code .mcp.json:

{
  "mcpServers": {
    "excalidraw": {
      "command": "uvx",
      "args": ["excalidraw-mcp"],
      "env": {
        "EXPRESS_SERVER_URL": "http://localhost:3031",
        "ENABLE_CANVAS_SYNC": "true"
      }
    }
  }
}

Alternative: Local Development Configuration

For local development, use:

{
  "mcpServers": {
    "excalidraw": {
      "command": "uv",
      "args": ["run", "python", "excalidraw_mcp/server.py"],
      "cwd": "/absolute/path/to/excalidraw-mcp"
    }
  }
}

Important: Replace /absolute/path/to/excalidraw-mcp with the actual absolute path to your cloned repository.

๐Ÿ”ง Integration with Other Tools

Cursor IDE

Add to your .cursor/mcp.json:

{
  "mcpServers": {
    "excalidraw": {
      "command": "uvx",
      "args": ["excalidraw-mcp"],
      "env": {
        "EXPRESS_SERVER_URL": "http://localhost:3031"
      }
    }
  }
}

VS Code MCP Extension

For VS Code MCP extension, add to your settings:

{
  "mcp": {
    "servers": {
      "excalidraw": {
        "command": "uvx",
        "args": ["excalidraw-mcp"],
        "env": {
          "EXPRESS_SERVER_URL": "http://localhost:3031"
        }
      }
    }
  }
}

๐Ÿ› ๏ธ Environment Variables

VariableDefaultDescription
EXPRESS_SERVER_URLhttp://localhost:3031Canvas server URL for MCP sync
ENABLE_CANVAS_SYNCtrueEnable/disable canvas synchronization
CANVAS_AUTO_STARTtrueAuto-start canvas server with MCP server
SYNC_RETRY_ATTEMPTS3Number of retry attempts for failed operations
SYNC_RETRY_DELAY_SECONDS1.0Base delay between retry attempts (seconds)
SYNC_RETRY_MAX_DELAY_SECONDS30.0Maximum delay between retry attempts (seconds)
SYNC_RETRY_EXPONENTIAL_BASE2.0Exponential base for backoff calculation
SYNC_RETRY_JITTERtrueEnable/disable jitter for retry delays
PORT3031Canvas server port
HOSTlocalhostCanvas server host
DEBUGfalseEnable debug logging

๐Ÿ“Š API Endpoints

The canvas server provides these REST endpoints:

MethodEndpointDescription
GET/api/elementsGet all elements
POST/api/elementsCreate new element
PUT/api/elements/:idUpdate element
DELETE/api/elements/:idDelete element
POST/api/elements/batchCreate multiple elements
GET/healthServer health check

๐ŸŽจ MCP Tools Available

Element Management

  • create_element - Create any type of Excalidraw element
  • update_element - Modify existing elements
  • delete_element - Remove elements
  • query_elements - Search elements with filters

Batch Operations

  • batch_create_elements - Create complex diagrams in one call

Element Organization

  • group_elements - Group multiple elements
  • ungroup_elements - Ungroup element groups
  • align_elements - Align elements (left, center, right, top, middle, bottom)
  • distribute_elements - Distribute elements evenly
  • lock_elements / unlock_elements - Lock/unlock elements

Resource Access

  • get_resource - Access scene, library, theme, or elements data

๐Ÿ—๏ธ Development Architecture

Frontend (frontend/src/)

  • React + TypeScript: Modern TSX components with full type safety
  • Vite Build System: Fast development and optimized production builds
  • Official Excalidraw: @excalidraw/excalidraw package with TypeScript types
  • WebSocket Client: Type-safe real-time element synchronization
  • Clean UI: Production-ready interface with proper TypeScript typing

Canvas Server (src/server.ts โ†’ dist/server.js)

  • TypeScript + Express.js: Fully typed REST API + static file serving
  • WebSocket: Type-safe real-time client communication
  • Element Storage: In-memory with comprehensive type definitions
  • CORS: Cross-origin support with proper typing
  • Middleware: Custom Express middleware components
  • Storage: Element storage implementations
  • WebSocket: Dedicated WebSocket server components
  • Utils: Utility functions for various operations

MCP Server (excalidraw_mcp/server.py)

  • Python FastMCP: Python-based Model Context Protocol implementation
  • Canvas Sync: HTTP requests to canvas server for element synchronization
  • Element Management: Full CRUD operations for Excalidraw elements
  • Batch Support: Complex diagram creation through batch operations
  • Process Management: Canvas server lifecycle management
  • HTTP Client: Async HTTP client with retry mechanisms
  • Configuration: Centralized configuration management

Type System (src/types.ts)

  • Excalidraw Element Types: Complete type definitions for all element types
  • API Response Types: Strongly typed REST API interfaces
  • WebSocket Message Types: Type-safe real-time communication
  • Server Element Types: Enhanced element types with metadata

๐Ÿ› Troubleshooting

Canvas Not Loading

  • Ensure npm run build completed successfully
  • Verify canvas server is running on port 3031
  • Python MCP server auto-starts canvas server - check console for errors

Elements Not Syncing

  • Python server automatically manages canvas server
  • Check ENABLE_CANVAS_SYNC=true in environment
  • Verify canvas server health at http://localhost:3031/health

WebSocket Connection Issues

  • Check browser console for WebSocket errors
  • Ensure no firewall blocking WebSocket connections
  • Try refreshing the browser page

Build Errors

  • Delete node_modules and run npm install
  • Check Node.js version (requires 16+)
  • Run npm run type-check to identify TypeScript issues
  • Run uv sync to update Python dependencies

Python Dependencies

  • Use uv sync to install/update Python dependencies
  • Ensure Python 3.13+ is installed
  • Check uv --version to verify uv installation

๐Ÿ“‹ Project Structure

excalidraw-mcp/
โ”œโ”€โ”€ examples/                 # Usage examples
โ”œโ”€โ”€ excalidraw_mcp/           # Python FastMCP server
โ”‚   โ”œโ”€โ”€ monitoring/           # Monitoring and health check utilities
โ”‚   โ”œโ”€โ”€ server.py             # Main MCP server (Python)
โ”‚   โ”œโ”€โ”€ config.py             # Configuration management
โ”‚   โ”œโ”€โ”€ element_factory.py    # Element creation utilities
โ”‚   โ”œโ”€โ”€ http_client.py        # HTTP client for canvas server
โ”‚   โ”œโ”€โ”€ process_manager.py    # Canvas server lifecycle management
โ”‚   โ”œโ”€โ”€ retry_utils.py        # Retry mechanisms for failed operations
โ”‚   โ”œโ”€โ”€ cli.py                # Command-line interface
โ”‚   โ”œโ”€โ”€ mcp_tools.py          # MCP tool implementations
โ”‚   โ”œโ”€โ”€ __init__.py           # Package initialization
โ”‚   โ””โ”€โ”€ __main__.py           # Main entry point
โ”œโ”€โ”€ frontend/                 # React frontend
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ App.tsx           # Main React component (TypeScript)
โ”‚   โ”‚   โ””โ”€โ”€ main.tsx          # React entry point (TypeScript)
โ”‚   โ””โ”€โ”€ index.html            # HTML template
โ”œโ”€โ”€ src/                      # TypeScript canvas server
โ”‚   โ”œโ”€โ”€ middleware/           # Express middleware components
โ”‚   โ”œโ”€โ”€ storage/              # Element storage implementations
โ”‚   โ”œโ”€โ”€ utils/                # Utility functions
โ”‚   โ”œโ”€โ”€ websocket/            # WebSocket server components
โ”‚   โ”œโ”€โ”€ config.ts             # Server configuration
โ”‚   โ”œโ”€โ”€ server.ts             # Express server + WebSocket (TypeScript)
โ”‚   โ””โ”€โ”€ types.ts              # Type definitions
โ”œโ”€โ”€ dist/                     # Compiled TypeScript output
โ”‚   โ”œโ”€โ”€ server.js             # Compiled canvas server
โ”‚   โ”œโ”€โ”€ server.d.ts           # Server type definitions
โ”‚   โ”œโ”€โ”€ server.js.map         # Server source maps
โ”‚   โ”œโ”€โ”€ types.js              # Compiled type definitions
โ”‚   โ”œโ”€โ”€ types.d.ts            # Type definition files
โ”‚   โ”œโ”€โ”€ types.js.map          # Type definition source maps
โ”‚   โ”œโ”€โ”€ utils/                # Compiled utilities
โ”‚   โ”œโ”€โ”€ assets/               # Frontend assets
โ”‚   โ””โ”€โ”€ frontend/             # Built React frontend
โ”œโ”€โ”€ tests/                    # Python test suite
โ”‚   โ”œโ”€โ”€ unit/                 # Unit tests
โ”‚   โ”œโ”€โ”€ integration/         # Integration tests
โ”‚   โ”œโ”€โ”€ security/             # Security tests
โ”‚   โ”œโ”€โ”€ performance/         # Performance tests
โ”‚   โ””โ”€โ”€ e2e/                  # End-to-end tests
โ”œโ”€โ”€ .github/                  # GitHub configurations
โ”œโ”€โ”€ pyproject.toml            # Python project configuration
โ”œโ”€โ”€ package.json             # Node.js dependencies and scripts
โ”œโ”€โ”€ tsconfig.json             # TypeScript configuration
โ””โ”€โ”€ README.md                 # This file

๐Ÿ“ฆ Package Naming

This project uses consistent naming across different contexts:

  • Python Package: excalidraw_mcp (underscore) - used in imports and Python module references
  • PyPI Distribution: excalidraw-mcp (hyphen) - used for uvx excalidraw-mcp and pip installation
  • npm Package: excalidraw-mcp (hyphen) - used for Node.js dependencies
  • MCP Server Name: excalidraw - used in .mcp.json configuration

Example Usage:

# Python imports (underscore)
from excalidraw_mcp.server import main

# Shell commands (hyphen)
uvx excalidraw-mcp
pip install excalidraw-mcp

๐Ÿงช Testing & Quality Assurance

Coverage Requirements

  • Python: 85% minimum test coverage (enforced by pytest)
  • TypeScript: 70% minimum test coverage (enforced by Jest)

Running Tests

# Python tests with coverage
pytest --cov=excalidraw_mcp --cov-report=html
pytest --cov=excalidraw_mcp --cov-report=term-missing

# TypeScript tests with coverage
npm run test:coverage

# Run all tests
pytest && npm test

# Specific test categories
pytest tests/unit/                  # Python unit tests
pytest tests/integration/           # Python integration tests
pytest -m security                 # Security tests
pytest -m performance              # Performance benchmarks

npm run test:unit                   # TypeScript unit tests
npm run test:integration            # TypeScript integration tests

Quality Standards

This project enforces strict quality standards:

  • All code must pass type checking (Pyright for Python, TSC for TypeScript)
  • Security scanning with Bandit for Python
  • Linting and formatting with Ruff (Python) and built-in TypeScript rules
  • Comprehensive test coverage as specified above

๐Ÿ“ฆ Publishing & Distribution

PyPI Distribution

The Python package is published to PyPI as excalidraw-mcp:

# Install from PyPI
pip install excalidraw-mcp

# Use with uvx (recommended)
uvx excalidraw-mcp

Local Development

For local development and testing:

# Install in editable mode
pip install -e .

# Or use UV for development
uv sync
uv run python excalidraw_mcp/server.py

Version Management

  • Semantic versioning (SemVer) is used
  • Version is managed in both pyproject.toml and package.json
  • Releases are tagged in git with version numbers

๐Ÿ”ฎ Development Roadmap

  • โœ… Python FastMCP Architecture: Modern hybrid implementation with auto-management
  • โœ… TypeScript Canvas Server: Complete type safety for enhanced development experience
  • โœ… Comprehensive Testing: Security, performance, and integration test suites
  • ๐Ÿ”ง Enhanced Features: Additional MCP tools and canvas capabilities
  • ๐Ÿ”ง Performance Optimization: Real-time sync improvements
  • ๐Ÿ”ง Docker Deployment: Containerized deployment options

๐Ÿค Contributing

We welcome contributions! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“ License

This project is licensed under the MIT License - see the file for details.

๐Ÿ™ Acknowledgments

  • Excalidraw Team - For the amazing drawing library
  • MCP Community - For the Model Context Protocol specification