Excalidraw MCP Server

repository·main·Indexed 26 days ago

https://github.com/excalidraw/excalidraw-mcp

A Model Context Protocol (MCP) server that enables AI clients to generate and display interactive, hand-drawn Excalidraw diagrams. It supports remote deployment via Vercel, local installation via stdio, and provides state persistence through CheckpointStore implementations including File, Memory, and Redis. The server includes utilities for managing editor state, computing diffs of user edits, and streaming diagrams within chat interfaces.

Tokens
2.4K
Snippets
6
Records
18
Agent score
89%

What's inside excalidraw-mcp

  1. Use Excalidraw MCP Server with prompts

    main

    Once installed, you can use the server by asking your MCP-compatible client to generate diagrams. The server will stream hand-drawn Excalidraw diagrams with smooth viewport camera control and interactive fullscreen editing.

    Example prompts:

    • "Draw a cute cat using excalidraw"
    • "Draw an architecture diagram showing a user connecting to an API server which talks to a database"
  2. Install Excalidraw MCP Server via Remote URL

    main

    For MCP clients that support custom connectors (like Claude, ChatGPT, VS Code, or Goose), you can use the recommended remote endpoint. This is the easiest way to get started without local installation.

    Remote Endpoint: https://mcp.excalidraw.com

  3. Install Excalidraw MCP Server locally

    main

    You can install the Excalidraw MCP server locally using one of two methods:

    Option A: Download Extension

    1. Download the excalidraw-mcp-app.mcpb file from the Releases page.
    2. Double-click the file to install it directly into Claude Desktop.

    Option B: Build from Source

    1. Clone the repository and build the project using pnpm:
      git clone https://github.com/excalidraw/excalidraw-mcp.git
      cd excalidraw-mcp-app
      pnpm install && pnpm run build
    2. Add the server to your Claude Desktop configuration file located at ~/Library/Application Support/Claude/claude_desktop_config.json:
      {
        "mcpServers": {
          "excalidraw": {
            "command": "node",
            "args": ["/path/to/excalidraw-mcp-app/dist/index.js", "--stdio"]
          }
        }
      }
    3. Restart Claude Desktop.
    {
      "mcpServers": {
        "excalidraw": {
          "command": "node",
          "args": ["/path/to/excalidraw-mcp-app/dist/index.js", "--stdio"]
        }
      }
    }
  4. Deploy your own Excalidraw MCP instance to Vercel

    main

    You can host your own instance of the Excalidraw MCP server on Vercel by following these steps:

    1. Fork the repository.
    2. Import your fork into Vercel.
    3. Deploy without any additional environment variables.

    Your deployed server will be accessible at: https://your-project.vercel.app/mcp

  5. Configure RedisCheckpointStore via environment variables

    main

    To use the RedisCheckpointStore (or the store returned by createVercelStore when Redis is detected), you must provide connection details via the following environment variables:

    Upstash Redis / Vercel KV Variables:

    • KV_REST_API_URL or UPSTASH_REDIS_REST_URL
    • KV_REST_API_TOKEN or UPSTASH_REDIS_REST_TOKEN
  6. Manage Excalidraw editor state and persistence

    main

    The edit-context.ts module provides utilities for managing the lifecycle of an Excalidraw editor instance within an MCP App. It handles local storage persistence, state snapshots (checkpoints), and computing diffs of user edits to update the Model Context Protocol (MCP) model.

    Key Lifecycle Tasks

    1. Initialize Storage: Set a unique key for the widget instance using setStorageKey(key: string). This is typically a viewUUID or a tool-call-derived ID.
    2. Set Checkpoints: When a server provides a checkpointId via a tool result, register it using setCheckpointId(id: string) to enable state saving.
    3. Capture Baseline: After the initial render, call captureInitialElements(elements: readonly any[]) to establish a baseline for future diffing.
    4. Handle Changes: Use onEditorChange(app: App, elements: readonly any[]) as the Excalidraw onChange handler. This function is debounced (2000ms) and performs the following:
      • Persists elements to localStorage.
      • Calls the save_checkpoint server tool if a checkpointId is set.
      • Computes a text-based diff of additions, removals, and movements/resizes.
      • Updates the MCP model context with the diff description.
    5. Retrieve Edits: When exiting fullscreen or syncing back to a React state, use getLatestEditedElements() to retrieve the most recent user edits.
  7. Start the MCP server via Streamable HTTP

    main

    Use startStreamableHTTPServer to run the MCP server using the Streamable HTTP transport in stateless mode. This allows the server to be hosted as a web service.

    • The server listens on the port specified by the PORT environment variable (defaults to 3001).
    • The MCP endpoint is exposed at /mcp.
    • It uses CORS to allow cross-origin requests.
    • Requires a factory function that returns an McpServer instance.
  8. Start the MCP server via stdio

    main

    Use startStdioServer to run the MCP server using the standard input/output transport. This is typically used for local integrations where the client communicates with the server process directly via stdin/stdout.

    Requires a factory function that returns an McpServer instance.

  9. Implement diagram state persistence with CheckpointStore

    main

    The CheckpointStore interface provides a way to persist Excalidraw diagram elements (checkpoints). You can use one of the following implementations depending on your environment:

    • FileCheckpointStore: Persists checkpoints as JSON files in the system's temporary directory (excalidraw-mcp-checkpoints).
    • MemoryCheckpointStore: Stores checkpoints in memory. Note that data is lost when the process restarts and it is limited to 100 entries.
    • RedisCheckpointStore: Uses Upstash Redis to store checkpoints with a TTL of 30 days. Requires specific environment variables.
    • createVercelStore(): A factory function that returns a RedisCheckpointStore if Redis environment variables are present, otherwise returns a MemoryCheckpointStore.
  10. Checkpoint data size limits

    main

    All CheckpointStore implementations enforce a maximum serialized size for checkpoint data to prevent excessive resource usage.

    • Maximum Size: 5 MB (5 * 1024 * 1024 bytes).

    If the JSON-serialized data exceeds this limit, the save method will throw: Checkpoint data exceeds 5242880 byte limit.

  11. Checkpoint ID validation rules

    main

    When calling save or load on any CheckpointStore implementation, the id must follow these constraints:

    • Must be alphanumeric, hyphens (-), or underscores (_).
    • Maximum length of 64 characters.

    If the ID violates these rules, an error will be thrown: Invalid checkpoint id: must be alphanumeric, hyphens, or underscores or Invalid checkpoint id: exceeds 64 character limit.