Skip to main content
Glama
README.md
# Unturned Map Editor MCP

**Read, edit, validate and preview Unturned level files — through MCP or a CLI.**

![Python](https://img.shields.io/badge/python-3.11%2B-3776AB)
[![CI](https://github.com/triplessbaba-systems/unturned-map-editor-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/triplessbaba-systems/unturned-map-editor-mcp/actions/workflows/ci.yml)
![License](https://img.shields.io/badge/license-MIT-2ea44f)
![MCP](https://img.shields.io/badge/MCP-41%20tools-6f42c1)
![Tests](https://img.shields.io/badge/tests-34%20passing-brightgreen)

![A procedurally generated island rendered from its heightmap](docs/images/synthetic.png)

![The same island from a perspective camera](docs/images/synthetic-3d.png)

Both images are a map built entirely by this repo: no game assets, no editor,
just the same files Unturned reads.

## What it is

Unturned maps are folders of binary files. The in-game editor is a UI on top of
them. The tool works on the files directly, so an agent or a script can:

- place, move and delete objects and trees by name;
- sculpt terrain and paint ground materials;
- set player spawns;
- create a blank map from a template;
- validate regions, IDs, assets, spawns and placement height;
- render a top-down preview;
- snapshot and restore.

The MCP layer exposes semantic tools (`object_place`, `terrain_paint`,
`validate_map`). Raw bytes stay inside the library, where the writers are
version-gated and tested against real maps.

## Features

| Area | What works |
|---|---|
| Objects | v9 / v11 / v12 read + write, byte-identical round-trip on 10 stock maps |
| Trees | v8 read + write, v5/v6 read, placement |
| Spawns | `Players.dat` v4 read + write |
| Terrain | `raise/lower/smooth/flatten/set`, 16-bit PNG import/export |
| Holes | 1-bit `Landscape/Holes` cells; open/fill cave entrances |
| Materials | 8-layer splatmap painting by material GUID |
| Roads | `Paths.dat` v6 + `Roads.dat` materials; add/delete, Bezier splines |
| Zombie bounds | `Bounds.dat` + `Flags_Data.dat`; add/delete, spawn coverage check |
| Navmesh | `Navigation_*.dat` reader, 4 m XZ coverage grid, spawn validation |
| Road-side placement | objects along a spline: tangent yaw, offset, scale jitter |
| Assets | 1,233 object/tree assets indexed by name |
| Placement | region bucketing, ground snapping, median pivot profile |
| Validation | regions, duplicate IDs, missing assets, water spawns, pivot deviation |
| Map creation | template → blank map with spawn, terrain, trees, objects |
| Previews | top-down hillshade, perspective 3D, and `look_at_map` returning the PNG to the model |

## Install

```bash
git clone https://github.com/triplessbaba-systems/unturned-map-editor-mcp.git
cd unturned-map-editor-mcp
python -m pip install -e ".[dev]"
```

Python 3.11+. Unturned is only needed for `integration` tests and real maps.

## Quick start

```bash
python -m pytest -m "not integration" -q   # no game required
python -m pytest -q                        # all, integration skips without a game
python -m unturned_mcp.cli doctor          # scan every installed map
```

Generate a map and a preview without owning any assets:

```bash
python -m unturned_mcp.cli demo --map PEI --dest out/demo/PEI_AI --force
python -m unturned_mcp.cli newmap --force
```

`newmap` builds a blank map from PEI: clears objects and trees, raises a hill,
plants pines, places a fence line and drops a spawn point.

`verify` runs the whole chain on a generated map without Unturned: build, edit,
save, reopen, validate, render both views.

```bash
python -m unturned_mcp.cli verify
```

## MCP

```json
{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "unturned-map-editor": {
      "type": "local",
      "command": ["python", "-m", "unturned_mcp.server"],
      "enabled": true,
      "environment": { "PYTHONPATH": "/absolute/path/to/unturned-map-editor-mcp" }
    }
  }
}
```

Claude Desktop uses the `mcpServers` form. Full tool list and flows:
[MCP.md](MCP.md).

Typical agent loop:

```
fork_map("PEI", "C:/work/PEI_AI")
object_search("Fence Wood")
object_place(guid, [[-576,0,192], [-571,0,192]])
terrain_sculpt("raise", [[-576,192]], radius=60, strength=12)
terrain_materials(-576, 192)          # 8 material GUIDs for that tile
terrain_paint(<grass guid>, [[-576,192]], radius=40)
road_add([[-640,192], [-576,200], [-500,210]], material=0)
object_place_along_road(0, <fence guid>, spacing=12, offset=4.5, side="both")
nav_add([-576,192], [400,400], max_zombies=32)
terrain_hole([[-600,200]], radius=12)
navmesh_coverage([[-576,192], [0,0]])
validate_map()
render_preview("C:/work/after.png")
render_view(width=960, height=540)
look_at_map(width=960, height=540)
save_map()
```

## Verification

| Check | Result |
|---|---|
| `Objects.dat` round-trip, 10 stock maps | byte-identical (v9, v11, v12) |
| `Trees.dat` round-trip, PEI | byte-identical, 1,694 trees |
| `Players.dat` round-trip, PEI | byte-identical, 22 spawns |
| Heightmap PNG round-trip | 16/16 tiles identical |
| Splatmap paint | 15/15 untouched tiles identical |
| Roads round-trip | 23 paths + 10 materials byte-identical |
| Zombie bounds round-trip | 19 bounds + 1 orphan flag entry byte-identical |
| Holes round-trip | PEI hole tiles byte-identical |
| Navmesh parse | 19 flags, 42,642 triangles; spawn coverage verified |
| Along-road placement | 58 objects, ±6 m offset, yaw follows tangent |
| Region formula | 24,882 objects, all match |
| Pivot profile | 575 assets; +30 m displaced object detected and fixed |
| 3D preview | synthetic render, 320×180 test, 20+ colours |
| Tests | 34 passing (11 hermetic, 23 integration) |

## Docs

- [docs/FORMAT.md](docs/FORMAT.md) — byte-level level format, version gates, equations
- [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) — layers, invariants, testing strategy
- [ROADMAP.md](ROADMAP.md) — done / next / non-goals
- [CHANGELOG.md](CHANGELOG.md)
- [ANALIZ.md](ANALIZ.md) — Turkish long-form analysis: can an AI make a map?

## Limitations

- **Navmesh is not generated.** Zombies need a bake in the editor.
- **No prefab bounds.** Placement height uses an empirical per-asset median, not
  mesh geometry.
- **No in-game test.** Validation is file-level, not a launched server.

These are tracked in [ROADMAP.md](ROADMAP.md).

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md). The short version: no game assets, every
format change needs a round-trip test, keep the MCP surface semantic.

## License

MIT — see [LICENSE](LICENSE). Unturned belongs to Smartly Dressed Games; this
project ships no game content. See [NOTICE.md](NOTICE.md).