code-visualizer-mcp
README.md
# ๐จ 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.




---
## โจ 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](https://docs.astral.sh/uv/) (recommended) or pip
### Installation
```bash
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):
```json
{
"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):
```json
{
"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**:
```bash
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`):
```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:
```bash
npx @modelcontextprotocol/inspector uv --directory /absolute/path/to/code-visualizer-mcp run code-visualizer
```
### CLI Usage
```bash
# 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](https://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
```bash
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](LICENSE).
This server cannot be deployed
Maintenance
ActivitySlowing
ResponsivenessNo issues