Skip to main content
Glama
README.md
# PartBuilder

MCP server for generating 3D models from images using [SAM 3D Objects](https://github.com/facebookresearch/sam-3d-objects) by Meta. Designed for AI agents to request 3D parts from images and receive Three.js-compatible models.

## Features

- **Image to 3D**: Generate 3D Gaussian Splats from a single image
- **MCP Integration**: Works with Claude, GPT, and any MCP-compatible agent
- **Dual Backend**: Switch between cloud GPU (RunPod) and self-hosted Linux
- **Three.js Ready**: Automatic PLY to GLTF conversion for web rendering
- **Flexible Output**: Get PLY (Gaussian Splat), GLTF, or both
- **Claude Code Skills**: Guided workflows for interactive 3D generation

## Claude Code Skills

PartBuilder includes skills for guided 3D generation workflows:

| Skill | Description |
|-------|-------------|
| `/generate-3d` | Full guided workflow: image input → analysis → generation → Three.js code |
| `/partbuilder-status` | Check backend health and configuration |
| `/switch-backend` | Switch between cloud_gpu and remote_linux backends |

### Example: Generate 3D Model

```
> /generate-3d ./photo.png

Step 1: Analyzing image...
- Dimensions: 1024x768
- Subject: A wooden chair with curved armrests

Step 2: Backend Status
- Type: cloud_gpu
- Status: healthy

Step 3: Generating 3D model...
[Progress indicator]

Step 4: Complete!
- PLY: ./output/chair.ply
- GLTF: ./output/chair.glb

Three.js code provided for both formats.
```

## Quickstart

### 1. Install

```bash
git clone https://github.com/darland6/partbuilder.git
cd partbuilder
pip install -e .
```

### 2. Configure

```bash
cp .env.example .env
# Edit .env with your backend settings
```

### 3. Run MCP Server

```bash
partbuilder
# Or: python -m partbuilder.server
```

### 4. Add to Claude Desktop

Add to `~/Library/Application Support/Claude/claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "partbuilder": {
      "command": "partbuilder",
      "env": {
        "PARTBUILDER_BACKEND": "cloud_gpu",
        "PARTBUILDER_CLOUD_GPU__API_KEY": "your_key",
        "PARTBUILDER_CLOUD_GPU__ENDPOINT_ID": "your_endpoint"
      }
    }
  }
}
```

## Backend Setup

### Option A: Cloud GPU (RunPod)

Best for: Getting started quickly, no local GPU required.

1. Create a [RunPod](https://runpod.io) account
2. Deploy a serverless endpoint with SAM 3D Objects
3. Set your API key and endpoint ID in `.env`

```env
PARTBUILDER_BACKEND=cloud_gpu
PARTBUILDER_CLOUD_GPU__API_KEY=your_runpod_api_key
PARTBUILDER_CLOUD_GPU__ENDPOINT_ID=your_endpoint_id
```

### Option B: Remote Linux (Self-Hosted)

Best for: Production use, cost control, privacy.

**Requirements:**
- Linux 64-bit machine
- NVIDIA GPU with 32GB+ VRAM (A100, RTX 4090, etc.)
- CUDA 12.1

**On your Linux server:**

```bash
# Clone and set up SAM 3D Objects
cd partbuilder/sam-3d-objects
mamba env create -f environments/default.yml
mamba activate sam3d-objects

# Install dependencies
export PIP_EXTRA_INDEX_URL="https://pypi.ngc.nvidia.com https://download.pytorch.org/whl/cu121"
pip install -e '.[dev]'
pip install -e '.[p3d]'
export PIP_FIND_LINKS="https://nvidia-kaolin.s3.us-east-2.amazonaws.com/torch-2.5.1_cu121.html"
pip install -e '.[inference]'

# Download model weights (requires HuggingFace access)
pip install 'huggingface-hub[cli]<1.0'
hf auth login
hf download --repo-type model --local-dir checkpoints/hf-download --max-workers 1 facebook/sam-3d-objects
mv checkpoints/hf-download/checkpoints checkpoints/hf

# Run inference server
pip install fastapi uvicorn
python scripts/inference_server.py --host 0.0.0.0 --port 8000
```

**On your local machine:**

```env
PARTBUILDER_BACKEND=remote_linux
PARTBUILDER_REMOTE_LINUX__HOST=your-server-ip
PARTBUILDER_REMOTE_LINUX__PORT=8000
PARTBUILDER_REMOTE_LINUX__API_KEY=optional_api_key
```

## MCP Tools

### `generate_3d_from_image`

Generate a 3D model from an image.

```json
{
  "image_base64": "...",
  "mask_index": 0,
  "seed": 42,
  "output_format": "both"
}
```

**Parameters:**
| Parameter | Type | Description |
|-----------|------|-------------|
| `image_base64` | string | Base64 encoded PNG/JPEG |
| `image_path` | string | Alternative: path to image file |
| `mask_base64` | string | Optional mask image |
| `mask_index` | int | Which auto-mask to use (default: 0) |
| `seed` | int | Random seed for reproducibility |
| `output_format` | string | `ply`, `gltf`, or `both` |
| `output_name` | string | Base filename for output |

**Returns:**
- Path(s) to generated PLY and/or GLTF files
- Inference metadata

### `check_backend_status`

Check if the backend is healthy.

### `switch_backend`

Switch between `cloud_gpu` and `remote_linux` at runtime.

## Output Formats

### PLY (Gaussian Splat)

Native SAM 3D Objects output. Best quality, but requires specialized viewer.

**Three.js usage:**
```javascript
import { GaussianSplats3D } from '@mkkellogg/gaussian-splats-3d';

const viewer = new GaussianSplats3D.Viewer();
viewer.loadSplat('model.ply');
```

### GLTF/GLB

Converted mesh format. Universal compatibility, slight quality loss.

**Three.js usage:**
```javascript
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';

const loader = new GLTFLoader();
loader.load('model.glb', (gltf) => {
  scene.add(gltf.scene);
});
```

## Architecture

```
┌─────────────────────────────────────────────────────────────┐
│                      MCP Client                              │
│              (Claude, GPT, Custom Agent)                     │
└─────────────────────┬───────────────────────────────────────┘
                      │ MCP Protocol
┌─────────────────────▼───────────────────────────────────────┐
│                   PartBuilder MCP Server                     │
│  ┌─────────────────────────────────────────────────────┐    │
│  │                    server.py                         │    │
│  │  - Tool definitions                                  │    │
│  │  - Request handling                                  │    │
│  │  - Output management                                 │    │
│  └─────────────────────┬───────────────────────────────┘    │
│                        │                                     │
│  ┌─────────────────────▼───────────────────────────────┐    │
│  │              Backend Abstraction                     │    │
│  │  ┌─────────────────┐  ┌─────────────────────────┐   │    │
│  │  │  CloudGPUBackend│  │  RemoteLinuxBackend     │   │    │
│  │  │  (RunPod)       │  │  (Self-hosted)          │   │    │
│  │  └────────┬────────┘  └───────────┬─────────────┘   │    │
│  └───────────┼───────────────────────┼─────────────────┘    │
│              │                       │                       │
│  ┌───────────▼───────────────────────▼─────────────────┐    │
│  │              Utils (conversion.py)                   │    │
│  │  - PLY to GLTF conversion                           │    │
│  │  - Gaussian Splat to mesh                           │    │
│  └─────────────────────────────────────────────────────┘    │
└─────────────────────────────────────────────────────────────┘
                      │
         ┌────────────┴────────────┐
         ▼                         ▼
┌─────────────────┐    ┌─────────────────────────────────────┐
│   RunPod API    │    │      Remote Linux Server            │
│   (Serverless)  │    │  ┌─────────────────────────────┐    │
└─────────────────┘    │  │   inference_server.py       │    │
                       │  │   - FastAPI                  │    │
                       │  │   - SAM 3D Objects model     │    │
                       │  │   - GPU inference            │    │
                       │  └─────────────────────────────┘    │
                       │  ┌─────────────────────────────┐    │
                       │  │   sam-3d-objects/           │    │
                       │  │   (Meta's model)            │    │
                       │  └─────────────────────────────┘    │
                       └─────────────────────────────────────┘
```

## File Structure

```
partbuilder/
├── src/partbuilder/
│   ├── __init__.py          # Package init
│   ├── server.py            # MCP server implementation
│   ├── config.py            # Configuration management
│   ├── cli.py               # CLI entry point
│   ├── backends/
│   │   ├── __init__.py
│   │   ├── base.py          # Backend interface
│   │   ├── cloud_gpu.py     # RunPod backend
│   │   └── remote_linux.py  # Self-hosted backend
│   └── utils/
│       ├── __init__.py
│       └── conversion.py    # PLY to GLTF conversion
├── scripts/
│   └── inference_server.py  # Server for remote Linux
├── sam-3d-objects/          # Meta's SAM 3D Objects (submodule)
├── output/                  # Generated models (gitignored)
├── pyproject.toml
├── .env.example
├── LICENSE
└── README.md
```

## Requirements

### MCP Server (Local)
- Python 3.10+
- No GPU required

### Inference Backend
- Linux 64-bit
- NVIDIA GPU with 32GB+ VRAM
- CUDA 12.1
- ~20GB disk space for model weights

## Troubleshooting

### "Model checkpoints not found"

Download weights from HuggingFace:
```bash
hf auth login  # Need access approval first
hf download --repo-type model --local-dir checkpoints/hf-download facebook/sam-3d-objects
```

### "RuntimeError: Not compiled with GPU support"

Build PyTorch3D on a GPU node:
```bash
# SSH to GPU machine, then:
mamba activate sam3d-objects
pip install -e '.[p3d]'
```

### Connection refused to remote server

1. Check firewall allows port 8000
2. Verify server is running: `curl http://your-server:8000/health`
3. Check API key matches

## License

MIT License - see [LICENSE](LICENSE)

## Credits

- [SAM 3D Objects](https://github.com/facebookresearch/sam-3d-objects) by Meta AI Research
- [MCP Protocol](https://modelcontextprotocol.io) by Anthropic