# 8th Wall Desktop Element Adding Guide
## ā
**What's Included**
This MCP server now includes **validated tools** for adding elements to `.expanse.json` that are **fully compatible with 8th Wall Desktop**.
---
## š ļø **Available Tools**
### **1. `desktop_add_shape`** - Add 3D Shapes ā
**Supports all geometry types:**
- `box` - Cube/rectangle
- `sphere` - Perfect sphere
- `cylinder` - Cylindrical shape
- `plane` - Flat plane
- `circle` - Circular disk
- `cone` - Cone shape
- `torus` - Donut shape
- `ring` - Flat ring/annulus
**Usage Examples:**
```
Add a red sphere named "ball" at [0, 1, -3]
```
```
Add a blue box named "platform" at [0, 0, -5] with scale [2, 0.1, 2]
```
```
Add a torus named "ring" at [1, 1.5, -2] with color #ff00ff
```
**All properties are validated:**
- ā
`components: {}` always initialized (prevents crashes)
- ā
All numeric values validated (no `undefined`, `null`, `NaN`)
- ā
Material type defaults to `"standard"` with proper properties
- ā
Colors validated as hex (#rrggbb)
- ā
Position, rotation, scale always arrays of 3 numbers
---
### **2. `desktop_read_json`** - Read .expanse.json
**Read the entire file or use JSON Pointer:**
```
Read the .expanse.json file
```
```
Read the objects array from .expanse.json using pointer /spaces/0/objects
```
---
### **3. `desktop_patch_json`** - Modify JSON
**Three operations: `set`, `remove`, `push`**
**Set a value:**
```
Set the scene background to #87ceeb using desktop_patch_json
```
**Add to array:**
```
Push a new object to /spaces/0/objects
```
**Remove property:**
```
Remove the debug mesh using operation "remove"
```
---
### **4. `desktop_write_json`** - Replace Entire File
**Use with caution - replaces entire .expanse.json**
---
### **5. `desktop_enable_face_tracking`** - Enable Face AR
```
Enable face tracking with debug mesh
```
---
## šÆ **8th Wall Compatibility Guarantees**
### ā
**Prevents All Known Errors:**
1. **`TypeError: Cannot read properties of undefined (reading 'toFixed')`**
- ā
All numeric properties validated
- ā
Defaults provided for all geometry dimensions
- ā
No `undefined`, `null`, or `NaN` values
2. **`TypeError: Cannot convert undefined or null to object`**
- ā
`components: {}` **always** initialized
- ā
All objects have required structure
3. **`Unexpected material`**
- ā
Material type validated (`basic`, `standard`, `phong`)
- ā
Proper properties for each material type
- ā
`standard` material includes `roughness` and `metalness`
4. **`Invalid component`**
- ā
No custom components added
- ā
`components` always empty object `{}`
- ā
Interactions should be added via JavaScript files
---
## š **Object Structure (Fully Validated)**
Every object added has this structure:
```json
{
"name": "my-object",
"position": [0, 0, 0],
"rotation": [0, 0, 0],
"scale": [1, 1, 1],
"geometry": {
"type": "sphere",
"radius": 0.5,
"widthSegments": 32,
"heightSegments": 16
},
"material": {
"type": "standard",
"color": "#ffffff",
"roughness": 0.5,
"metalness": 0.5,
"opacity": 1,
"emissiveIntensity": 0
},
"components": {}
}
```
**Every property is validated and guaranteed to be valid!**
---
## šØ **Material Types**
### **`basic`** - Simple unlit material
```json
{
"type": "basic",
"color": "#ff0000",
"opacity": 1
}
```
### **`standard`** - Physically based (PBR) ā (Default)
```json
{
"type": "standard",
"color": "#ff0000",
"roughness": 0.5,
"metalness": 0.5,
"opacity": 1
}
```
### **`phong`** - Classic lighting model
```json
{
"type": "phong",
"color": "#ff0000",
"roughness": 0.5,
"metalness": 0.5,
"opacity": 1
}
```
---
## š **Geometry Types & Properties**
### **Box**
```
Add a box with width 2, height 1, depth 3
```
Properties: `width`, `height`, `depth`
### **Sphere**
```
Add a sphere with radius 0.8
```
Properties: `radius`, `widthSegments`, `heightSegments`
### **Cylinder**
```
Add a cylinder with radius 0.5 and height 2
```
Properties: `radiusTop`, `radiusBottom`, `height`, `radialSegments`
### **Plane**
```
Add a plane with width 4 and height 4
```
Properties: `width`, `height`
### **Circle**
```
Add a circle with radius 1
```
Properties: `radius`, `segments`
### **Cone**
```
Add a cone with radius 0.5 and height 1.5
```
Properties: `radius`, `height`, `radialSegments`
### **Torus**
```
Add a torus with radius 0.5 and tube 0.2
```
Properties: `radius`, `tube`, `radialSegments`, `tubularSegments`
### **Ring**
```
Add a ring with inner radius 0.5 and outer radius 1
```
Properties: `innerRadius`, `outerRadius`, `thetaSegments`
---
## š **Example Workflows**
### **Create a Simple Scene**
```
You: Set project to fire3
You: Add a blue box named "ground" at [0, 0, -5] with scale [10, 0.1, 10]
You: Add a red sphere named "ball" at [0, 2, -5]
You: Add a yellow cylinder named "pillar" at [2, 1, -5] with height 2
You: Add a torus named "ring" at [-2, 1.5, -5] with color #ff00ff
```
### **Create a Platform Game Setup**
```
You: Add a plane named "floor" at [0, 0, -5] with width 20 and height 20
You: Add a box named "platform1" at [0, 1, -5] with scale [3, 0.2, 3] and color #8B4513
You: Add a sphere named "player" at [0, 2, -5] with radius 0.3 and color #00ff00
You: Add a cone named "obstacle" at [2, 1.5, -5] with color #ff0000
```
### **Modify Existing Objects**
```
You: Read the .expanse.json file
You: Patch /spaces/0/objects/0/material/color to set it to #00ff00
You: Remove the debug mesh at /spaces/0/objects/5
```
---
## š”ļø **Validation & Safety**
### **Automatic Repairs:**
The `repairObject()` function ensures:
1. **Components initialized**: `components: {}`
2. **Vectors validated**: `position`, `rotation`, `scale` are `[number, number, number]`
3. **Geometry properties**: All dimensions are finite numbers
4. **Material properties**: Type, color, roughness, metalness validated
5. **Light properties**: Intensity, color, distance validated
### **No Invalid States:**
- ā Can't add `undefined` numeric values
- ā Can't add `null` components
- ā Can't add invalid colors
- ā Can't add unsupported material types
- ā Can't add invalid geometry properties
**Result: 100% compatible with 8th Wall Desktop!** ā
---
## ā ļø **Limitations**
### **No Custom Components**
Don't try to add components via MCP:
```
ā Add a "tap" component
ā Add a "physics" component
```
**Instead:** Use JavaScript files for interactions (see next section)
### **Single Space Only**
Currently adds to `spaces[0].objects` only.
---
## š® **Adding Interactions**
For interactive elements, use JavaScript files:
### **Example: Tap Handler**
**In Cursor:**
```
You: Create a file src/tap-handler.js with tap interaction for "ball" object
```
**Then in .expanse.json, reference the script:**
```json
{
"scripts": ["src/tap-handler.js"]
}
```
**Or use `desktop_patch_json`:**
```
You: Add src/tap-handler.js to the scripts array using desktop_patch_json
```
---
## š **Comparison: Before vs After**
### **Before (Broken):**
```json
{
"name": "sphere_1",
"position": [0, 1, -3],
"geometry": { "type": "sphere" },
"material": { "type": "standard" }
}
```
**Problems:**
- ā No `components` ā crashes Desktop
- ā No `radius` ā `toFixed` error
- ā No `rotation`, `scale` ā undefined errors
- ā No material properties ā "Unexpected material"
### **After (Working):**
```json
{
"name": "sphere_1",
"position": [0, 1, -3],
"rotation": [0, 0, 0],
"scale": [1, 1, 1],
"geometry": {
"type": "sphere",
"radius": 0.5,
"widthSegments": 32,
"heightSegments": 16
},
"material": {
"type": "standard",
"color": "#ffffff",
"roughness": 0.5,
"metalness": 0.5,
"opacity": 1,
"emissiveIntensity": 0
},
"components": {}
}
```
**ā
Every property validated and complete!**
---
## šÆ **Quick Reference**
**Add a shape:**
```
Add a [color] [shape] named "[name]" at [x, y, z]
```
**Read JSON:**
```
Read the .expanse.json file
```
**Modify JSON:**
```
Set [property] to [value] using desktop_patch_json
```
**Enable face tracking:**
```
Enable face tracking with debug mesh
```
---
## ā
**Ready to Use!**
Just restart Cursor and start adding elements:
```
You: Set project to fire3
You: Add a red sphere named "ball" at [0, 1, -3]
Assistant: ā
Added sphere "ball" to .expanse.json
```
**All elements are guaranteed to be valid and compatible with 8th Wall Desktop!** š