code-visualizer-mcp

code-visualizer-mcp

An MCP server that generates Excalidraw diagrams to visualize algorithm execution step-by-step, supporting multiple data structures and integration with AI assistants.

Category
访问服务器

README

🎨 Code Visualizer MCP

An MCP server that generates Excalidraw diagrams to visualize algorithm execution step-by-step. Give it your code + an example input, and get a single .excalidraw file showing every iteration.

Python License MCP

Code Visualizer Output


✨ Features

  • Single-file traces — All iterations in ONE .excalidraw diagram
  • 12 data structures — Array, LinkedList, Tree, Graph, HashMap, Stack, Queue, Matrix, Heap, Trie, Priority Queue, Set
  • Dark-mode palette — YouTube-friendly colors with semantic highlighting
  • MCP + CLI — Use via AI assistants (Claude, Cursor, Gemini) or command line

📐 Supported Data Structures

Data Structure Type Key Visualization
Array array Horizontal cells with index labels + pointer arrows
Linked List linkedlist Nodes with next-pointers and cycle detection
Binary Tree tree Hierarchical layout with parent-child edges
Graph graph Circular layout with directed/undirected edges
HashMap hashmap Vertical key-value pair list
Stack stack Vertical cells with TOP label
Queue queue Horizontal cells with FRONT/REAR labels
Matrix matrix 2D grid with row/col labels
Heap heap Binary tree + array representation
Priority Queue priority_queue Same as heap
Trie trie Tree with character-labeled edges
Set set Rounded-rectangle collection

🚀 Quick Start

Prerequisites

  • Python 3.10+
  • uv (recommended) or pip

Installation

git clone https://github.com/your-username/code-visualizer-mcp.git
cd code-visualizer-mcp
uv sync

🔌 Client Integration & Ways to Use

This MCP server is standard Model Context Protocol compliant and works with a variety of AI assistants and IDEs:

1. Claude Desktop

Add to claude_desktop_config.json (~/Library/Application Support/Claude/claude_desktop_config.json on macOS or %APPDATA%\Claude\claude_desktop_config.json on Windows):

{
  "mcpServers": {
    "code-visualizer": {
      "command": "uv",
      "args": [
        "--directory",
        "/absolute/path/to/code-visualizer-mcp",
        "run",
        "code-visualizer"
      ]
    }
  }
}

2. Google Antigravity (AGY)

Add to your Antigravity MCP config file (~/.gemini/antigravity/mcp_config.json or your project settings):

{
  "mcpServers": {
    "code-visualizer": {
      "command": "uv",
      "args": [
        "--directory",
        "/absolute/path/to/code-visualizer-mcp",
        "run",
        "code-visualizer"
      ]
    }
  }
}

3. Cursor IDE

  1. Open Cursor Settings > Features > MCP.
  2. Click + Add New MCP Server.
  3. Set Name: code-visualizer, Type: stdio
  4. Set Command:
    uv --directory /absolute/path/to/code-visualizer-mcp run code-visualizer
    

4. VS Code (Cline / Roo Code / Continue)

Add to your extension's MCP settings file (e.g. cline_mcp_settings.json):

{
  "mcpServers": {
    "code-visualizer": {
      "command": "uv",
      "args": [
        "--directory",
        "/absolute/path/to/code-visualizer-mcp",
        "run",
        "code-visualizer"
      ]
    }
  }
}

5. MCP Inspector (Interactive Testing)

To test and debug tools directly in a browser UI without an AI assistant:

npx @modelcontextprotocol/inspector uv --directory /absolute/path/to/code-visualizer-mcp run code-visualizer

CLI Usage

# Generate an array diagram
uv run python examples/generate_cli.py array \
  --title "Two Sum" \
  --data "2,7,11,15" \
  --highlights "0:visited,1:found" \
  --pointers "i:1"

# Generate a full algorithm trace
uv run python examples/sliding_window_maximum.py

Output files are saved to the output/ directory as .excalidraw files. Open them at excalidraw.com or in the VS Code Excalidraw extension.


🏗️ Project Structure

code-visualizer-mcp/
├── pyproject.toml                 # Project config, dependencies, entry points
├── LICENSE
├── README.md
│
├── src/code_visualizer/           # Main package
│   ├── __init__.py
│   ├── server.py                  # MCP server entry point (FastMCP)
│   ├── renderer.py                # Excalidraw JSON file writer
│   │
│   ├── primitives/                # Low-level element factories
│   │   ├── elements.py            # make_rectangle, make_ellipse, make_arrow, ...
│   │   ├── colors.py              # Semantic color palette (PALETTE, get_color)
│   │   └── styles.py              # Style presets (CELL_STYLE, NODE_STYLE, ...)
│   │
│   ├── layout/                    # Spatial position calculators
│   │   ├── linear.py              # Arrays, matrices, stacks, queues, hashmaps, sets
│   │   ├── tree_layout.py         # Binary trees, heaps, tries
│   │   └── graph_layout.py        # Circular graph layout
│   │
│   └── tools/                     # MCP tool implementations
│       ├── visualize_array.py     # Array + hashmap diagrams
│       ├── visualize_linkedlist.py
│       ├── visualize_tree.py
│       ├── visualize_graph.py
│       └── visualize_trace.py     # ⭐ Multi-step trace (primary tool)
│
├── tests/                         # Test suite
│   ├── conftest.py                # Shared fixtures
│   ├── test_primitives.py         # Element factory tests
│   └── test_tools.py              # Tool integration tests
│
├── examples/                      # Usage examples
│   ├── generate_cli.py            # CLI diagram generator
│   └── sliding_window_maximum.py  # Full algorithm trace example
│
├── docs/
│   └── architecture.md            # System architecture & workflow guide
│
└── output/                        # Generated .excalidraw files 

🧪 Running Tests

uv run pytest -v

🎨 Color Palette

Color Name Use Case Preview
default Unvisited elements
current Currently processing 🟧
highlighted Active window/range 🟦
visited Already processed
found Match / answer found 🟨
comparing Being compared 🟠
swapping Being swapped 🩷
pointer_a / pointer_b / pointer_c Named pointers 🟩🟪💛
success / error Result indicators ✅❌

📄 License

MIT — see LICENSE.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选