Skip to main content
Glama
LufiSprite Studio

LufiSprite Studio

by Lufi735
README.md
# lufisprite-mcp

> **Model Context Protocol (MCP) Server & Agent Skill for LufiSprite Studio v1.224+**

[![Node.js >= 18](https://img.shields.io/badge/node-%3E%3D18.0.0-brightgreen.svg)](https://nodejs.org/)
[![Zero Dependencies](https://img.shields.io/badge/dependencies-zero-blue.svg)](#installation)
[![MCP Compatible](https://img.shields.io/badge/MCP-2024--11--05-purple.svg)](https://modelcontextprotocol.io/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)

`lufisprite-mcp` bridges **LufiSprite Studio v1.224+** with AI coding agents such as **Google Antigravity**, **Cursor**, **Claude Code**, and **Windsurf**. Just like **Blender MCP**, it lets your AI assistant control the live studio canvas in real time—creating projects, painting 2D pixel art, managing layers and animation frames, building 3D scenes/models, and inspecting its own work via PNG screenshots.

---

## Features

- **Zero External Dependencies** — Built purely on Node.js native `http`, `crypto`, `readline`, and `fs`. No `npm install` required.
- **2D Pixel Art Creation** — Paint whole sprites fast with ASCII character grids (`draw_grid_ascii`), individual pixels (`draw_pixels`), geometric shapes (`draw_shape`), flood fill (`flood_fill`), and palette management.
- **Layer & Animation Control** — Create, reorder/select, toggle visibility/opacity on 2D and 3D layers, add/duplicate animation frames, and adjust FPS.
- **3D Low-Poly Modeling & Scene Building** — Open the 3D viewport, add primitives (`cube`, `cuboid`, `sphere`, `cylinder`, `cone`, `torus`, `plane`), import procedural or custom Wavefront `.obj` meshes (`import_3d_obj`), transform objects, and add lights, cameras, groups, or bones.
- **Visual Feedback Loop** — Capture crisp 2D composite or 3D viewport PNG screenshots (`get_canvas_screenshot`) so the AI agent can visually inspect and refine what it drew.
- **Included Agent Skill (`SKILL.md`)** — Ships with [`skill/lufisprite-studio/SKILL.md`](skill/lufisprite-studio/SKILL.md) so AI agents automatically follow best practices for palette design, ASCII sprite grids, Y-up 3D modeling, and visual verification.

---

## Architecture

```text
+-----------------------------------+   stdio (JSON-RPC 2.0)   +-----------------------------------+
| AI Coding Agent                   | <----------------------> | lufisprite-mcp                    |
| (Google Antigravity / Cursor /    |                          | server/index.js                   |
|  Claude Code + SKILL.md)          |                          | WebSocket Server: 127.0.0.1:41924 |
+-----------------------------------+                          +-----------------+-----------------+
                                                                                 ^
                                                                                 | WebSocket (RFC 6455)
                                                                                 v
                                                               +-----------------------------------+
                                                               | LufiSprite Studio v1.224+         |
                                                               | (Browser / Desktop / Capacitor)   |
                                                               | Top-Right MCP Connection Panel    |
                                                               +-----------------------------------+
```

Because LufiSprite Studio runs in a web/Capacitor environment (where the browser cannot bind a listening TCP port directly), `lufisprite-mcp` starts the local WebSocket bridge on `ws://127.0.0.1:41924`, and LufiSprite Studio connects to it from its built-in **MCP** panel.

---

## Installation

### 1. Clone the Repository

```bash
git clone https://github.com/<your-username>/lufisprite-mcp.git
cd lufisprite-mcp
```

**Requirements:**
- **Node.js 18+** (`node -v`)
- **LufiSprite Studio v1.224+**

*(No `npm install` step is needed—there are zero runtime dependencies.)*

### 2. Configure Your AI Coding Tool

#### Google Antigravity
Add `lufisprite-studio` to your `~/.gemini/config/mcp_config.json` (see [`examples/antigravity-mcp-config.json`](examples/antigravity-mcp-config.json)):

```json
{
  "mcpServers": {
    "lufisprite-studio": {
      "command": "node",
      "args": [
        "C:\\path\\to\\lufisprite-mcp\\server\\index.js",
        "--port",
        "41924"
      ]
    }
  }
}
```

#### Cursor / Claude Code / Windsurf
See [`examples/cursor-mcp-config.json`](examples/cursor-mcp-config.json):

```json
{
  "mcpServers": {
    "lufisprite-studio": {
      "command": "node",
      "args": [
        "/absolute/path/to/lufisprite-mcp/server/index.js"
      ],
      "env": {
        "LUFISPRITE_MCP_PORT": "41924"
      }
    }
  }
}
```

### 3. Install the Agent Skill (`SKILL.md`)

Copy the `skill/lufisprite-studio` folder into your agent's skills directory so the AI knows the recommended 2D/3D workflows automatically:

- **Google Antigravity (Global):** `~/.gemini/config/skills/lufisprite-studio/SKILL.md`
- **Workspace-level:** `<your-project>/.agent/skills/lufisprite-studio/SKILL.md`

---

## How to Use

1. Start your AI coding agent (e.g., **Google Antigravity**)—it automatically launches `lufisprite-mcp` and opens `ws://127.0.0.1:41924`.
2. Open **LufiSprite Studio v1.224+**.
3. On the **Home Page** (top-right corner, next to the Guide and Settings buttons) or in the **Editor** top-right bar, click the **MCP plug icon**.
4. Verify the WebSocket URL is `ws://127.0.0.1:41924` (optional: enable **Auto-reconnect**) and click **Connect**.
   - The indicator dot turns **green** when connected.
   - All incoming MCP tool calls appear in real time in the **Live MCP Activity Log**.
5. Prompt your AI agent!

### Example Prompts

- **2D Pixel Art:**
  > *"Create a 32x32 pixel art project in LufiSprite Studio and draw a glowing blue mana potion with highlight shading and a cork stopper. Take a screenshot to verify."*
- **Sprite Animation:**
  > *"Add a 4-frame idle bounce animation to the current sprite at 8 FPS."*
- **3D Low-Poly Modeling:**
  > *"Open the 3D viewport in LufiSprite Studio and build a low-poly stylized pine tree next to a wooden cabin using 3D primitives and custom OBJ meshes, then inspect the 3D screenshot."*

---

## Available MCP Tools (23 Tools)

### App & Project
| Tool | Description |
| --- | --- |
| `get_app_state` | Inspect current screen (`splash`/`editor`), project dimensions, layers, 3D status, and 3D objects. |
| `create_project` | Create and open a new project (`name`, `width`, `height`, `enable3D`). |
| `list_projects` | List projects saved in LufiSprite Studio IndexedDB. |
| `open_project` | Open a saved project by `id` or `name`. |
| `undo_redo` | Undo or redo recent operations (`steps`). |

### 2D Pixel Art
| Tool | Description |
| --- | --- |
| `draw_grid_ascii` | Paint a full sprite or region using ASCII character rows + a char-to-hex palette map. |
| `draw_pixels` | Set an array of `{ x, y, color }` pixels in one undoable step. |
| `draw_shape` | Draw filled or outlined `line`, `rect`, `circle`, or `ellipse`. |
| `flood_fill` | Contiguous 4-way flood fill starting at `(x, y)`. |
| `clear_layer` | Clear all pixels on a 2D layer. |
| `get_layer_pixels` | Read non-empty pixels from a 2D layer or bounding box. |

### Layers, Palette & Animation
| Tool | Description |
| --- | --- |
| `list_layers` | List all layers with indices, IDs, types (`2d`/`3d`/`group`), visibility, and opacity. |
| `create_layer` | Create a new `2d` or `3d` layer. |
| `update_layer` | Select, rename, toggle visibility/opacity/blendMode, or delete a layer. |
| `set_palette_colors` | Set the active color and/or append colors to the active palette. |
| `manage_frames` | `list`, `add`, `duplicate`, `select`, `delete` animation frames or `set_fps`. |

### 3D Modeling & Scene
| Tool | Description |
| --- | --- |
| `open_3d_viewport` | Ensure a 3D layer exists and open the interactive 3D viewport. |
| `add_3d_primitive` | Add `cube`, `cuboid`, `sphere`, `cylinder`, `cone`, `torus`, or `plane` with position/rotation/scale/color. |
| `import_3d_obj` | Import custom/procedural Wavefront `.obj` mesh text directly into the 3D layer. |
| `transform_3d_object` | Move, rotate (degrees), scale, recolor, rename, toggle visibility, or delete any 3D object. |
| `add_3d_scene_item` | Add `light`, `sun`, `point`, `ambient`, `camera`, `group`, or `bone`. |
| `list_3d_objects` | List all 3D objects in the 3D layer with their transforms. |

### Visual Inspection
| Tool | Description |
| --- | --- |
| `get_canvas_screenshot` | Capture a PNG screenshot of the `2d` composite canvas or `3d` viewport/layer. |

---

## CLI Options & Health Endpoint

- `--port <number>` or `LUFISPRITE_MCP_PORT`: WebSocket bridge port (default: `41924`)
- `--host <ip>` or `LUFISPRITE_MCP_HOST`: Bind address (default: `127.0.0.1`)
- Health check endpoint: `GET http://127.0.0.1:41924/health` returns JSON `{ ok, connected, client, wsUrl }`.

---

## Running Tests

```bash
npm test
```

Runs `test/test-mcp-server.js`, verifying MCP `initialize`, `tools/list` (23 tools), `/health` endpoint, WebSocket client connection, JSON tool calls, and >64 KB base64 PNG image round-trips.

---

## Troubleshooting

- **"No LufiSprite Studio instance is connected to ws://127.0.0.1:41924"**
  Open LufiSprite Studio v1.224+, click the **MCP** plug button in the top-right corner, and click **Connect**.
- **Port `41924` already in use**
  Pass `--port 41925` in `mcp_config.json`, restart your MCP client, and select the `localhost:41925` preset in LufiSprite Studio's MCP panel.
- **Standalone / Manual Bridge Check**
  You can test the bridge directly with `node server/index.js --port 41924` and open `http://127.0.0.1:41924/health` in your browser.

---

## License

[MIT](LICENSE)

TDQS

B3.3/5.0

Scored across 23 tools

Disambiguation4/5

Each tool targets a fairly distinct resource and action: drawing (draw_pixels/flood_fill/draw_shape/draw_grid_ascii) is separated by method, and 2D vs 3D operations are clearly namespaced (add_3d_primitive vs create_layer). Minor ambiguity between add_3d_primitive, import_3d_obj, and add_3d_scene_item, and update_layer is a multi-purpose grab-bag, but descriptions disambiguate them well.

Naming Consistency4/5

Nearly all tools follow a verb_noun snake_case pattern (create_project, list_layers, transform_3d_object, get_canvas_screenshot). Small deviations exist: undo_redo lacks a noun, and manage_frames/update_layer are vague multi-action verbs, but overall the convention is predictable.

Tool Count4/5

23 tools is on the heavy side of the 3-15 sweet spot, but the domain genuinely spans 2D drawing, layers, frames, palette, 3D meshes, and screenshots, so most tools earn their place. It could be trimmed slightly (e.g. merging some 3D scene-item tools).

Completeness4/5

Core lifecycle is covered: project create/open/list, layer create/update/list, drawing primitives, frame management, undo/redo, and visual verification via screenshot. Minor gaps remain—no explicit project delete or export/save-to-file tool, and palette can be set but not read back—but these are workable.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues