unity-local-mcp
<div align="center">
<img src="assets/banner.svg" alt="Unity Local MCP: your own AI models, working inside the Unity Editor" width="100%">
<br>
[](https://github.com/isaiahagi/unity-local-mcp/stargazers)
[](https://github.com/isaiahagi/unity-local-mcp/forks)
[](https://github.com/isaiahagi/unity-local-mcp/issues)
[](LICENSE)
[](https://github.com/isaiahagi/unity-local-mcp/actions/workflows/ci.yml)





**Connect the AI models running on your own computer to the Unity Editor.**<br>
No cloud model, no API key, no per-token bill.
[Quick start](#-quick-start) · [Tools](#-tools) · [Modest PCs](#-running-on-a-modest-pc) · [Security](#-security) · [Troubleshooting](#-troubleshooting)
</div>
---
## ✨ Features
| | Feature | What you get |
|:-:|---|---|
| 🧠 | **Built for local models** | 18 tools with flat schemas, short replies, forgiving arguments and errors that say what to do next |
| 🔌 | **Ollama and LM Studio** | LM Studio connects over MCP. For Ollama, a built-in terminal chat does the MCP part |
| 🎮 | **Real editor control** | Create, move, color and inspect objects, components, properties and prefabs |
| 📝 | **Scripts with feedback** | The model writes C#, waits for the compile and reads the errors |
| ↩️ | **Easy undo** | Each scene edit is a single <kbd>Ctrl</kbd>+<kbd>Z</kbd> |
| ✋ | **You stay in charge** | The chat asks before every change. Read-only mode is one checkbox in Unity |
| 🔒 | **Stays on your machine** | The editor listens only on `127.0.0.1` and requires a random token |
> [!NOTE]
> This is an early release (0.1). The whole chain has been tested on Windows with Unity 6000.6.8f1 and Ollama. CI runs the Python tests on Windows, macOS and Linux, but LM Studio and the Unity package on macOS or Linux have not been tested yet, so [reports are welcome](https://github.com/isaiahagi/unity-local-mcp/issues).
## 🧩 How it works
```mermaid
flowchart LR
M["🧠 Your model<br/>Ollama or LM Studio"] <--> H["MCP host<br/>LM Studio, or the built-in chat"]
H <-- "MCP" --> S["unity-local-mcp<br/>Python server"]
S <-- "127.0.0.1" --> U["🎮 Unity Editor<br/>bridge package"]
```
The repository holds both halves: the Unity package in [`unity-package/`](unity-package) and the Python server in [`src/`](src/unity_local_mcp).
## 🚀 Quick start
### What you need
- **Unity 6**
- **[uv](https://docs.astral.sh/uv/getting-started/installation/)** and **Git** (uv fetches Python for you)
- **[Ollama](https://ollama.com)** or **[LM Studio](https://lmstudio.ai)** 0.3.17 or newer
- A model that supports **tool calling**
### 1. Add the package to Unity
In Unity, open **Window → Package Manager → + → Install package from git URL** and paste:
```text
https://github.com/isaiahagi/unity-local-mcp.git?path=/unity-package
```
Then open **Window → Unity Local MCP**. It should say `Running on 127.0.0.1:8737` (the port moves up if that one is taken).
### 2. Connect your model
<details open>
<summary><b>🦙 Ollama</b></summary>
<br>
Ollama runs models but does not connect to MCP servers by itself, so this project includes a chat that does.
```bash
ollama pull qwen3:4b-instruct
uvx --from git+https://github.com/isaiahagi/unity-local-mcp unity-local-mcp chat --model qwen3:4b-instruct
```
A session looks like this:
```text
you> Create a red cube named Player at position 0,1,0 and then add a Rigidbody to it.
.. waiting for the model
.. replied in 24s
-> create_object name=Player shape=cube position=0,1,0 color=red
Allow create_object? [y]es / [N]o / [a]lways for this tool: y
ok: {"created":"Player","position":"0,1,0", ...}
.. waiting for the model
.. replied in 6s
-> add_component target=Player component=Rigidbody
Allow add_component? [y]es / [N]o / [a]lways for this tool: y
ok: {"added":"Rigidbody","to":"Player"}
```
Leave out `--model` to pick from your installed models that can call tools. Type `/reset` to clear the conversation and `/exit` to quit.
</details>
<details>
<summary><b>🖥️ LM Studio</b></summary>
<br>
1. In LM Studio, open the **Program** tab in the right sidebar, then **Install → Edit mcp.json**.
2. Add the `unity` server (the Unity window has a button that copies this):
```json
{
"mcpServers": {
"unity": {
"command": "uvx",
"args": ["--from", "git+https://github.com/isaiahagi/unity-local-mcp", "unity-local-mcp"]
}
}
}
```
3. Load a tool-capable model, enable the `unity` server and ask it to change your scene.
If you prefer the terminal, start LM Studio's local server and use the built-in chat instead:
```bash
uvx --from git+https://github.com/isaiahagi/unity-local-mcp unity-local-mcp chat --provider lmstudio
```
</details>
### 3. Check the connection
```bash
uvx --from git+https://github.com/isaiahagi/unity-local-mcp unity-local-mcp doctor
```
It reports whether Unity, Ollama and LM Studio can be reached.
## 🧰 Tools
| Toolset | Tool | What it does |
|---|---|---|
| `inspect` | `get_editor_state` | Unity version, scene, play mode, compile status, selection |
| | `get_hierarchy` | Tree of GameObjects with their components |
| | `find_objects` | Search by name, component or tag |
| | `get_object` | Transform, components and property values |
| `edit` | `create_object` | Empty, primitive, camera, light or prefab, with transform and color |
| | `update_object` | Rename, move, rotate, scale, reparent, enable or tag |
| | `delete_object` | Delete an object and its children |
| | `add_component` | Add a built-in component or your own script |
| | `remove_component` | Remove a component |
| | `set_property` | Set a serialized property, including object and asset references |
| | `set_color` | Color an object, sprite or light |
| | `create_prefab` | Save a scene object as a prefab and link it |
| `scripts` | `list_assets` | Search project files |
| | `read_script` | Read a text file |
| | `write_script` | Create or replace a C# file under `Assets/` |
| `editor` | `get_console_logs` | Console messages and compile errors |
| | `set_play_mode` | Play, stop, pause |
| | `save_scene` | Save the scene |
Objects are addressed by path, such as `Enemies/Orc[1]`, which small models handle better than numeric IDs.
## 🐢 Running on a modest PC
You don't need a GPU, but you do need some patience. These are single measurements from an 8-core desktop CPU with 16 GB of RAM and **no dedicated graphics card**, with Unity open, running `qwen3:4b-instruct` (about 3 GB in memory) at `--num-ctx 4096`:
| Request | Time |
|---|---|
| First reply with every tool enabled (17 at the time), including loading the model | **55 s** (40 s of it reading the prompt, mostly tool definitions) |
| "Create a red cube named Player and add a Rigidbody", model already loaded | **38 s** |
| "Which objects are in the scene?" with read-only tools, including loading the model | **22 s** |
To make it faster:
- **Use a small instruct model.** Thinking models write a lot of text before they act. Choose an instruct variant, or try `--no-think`.
- **Offer fewer tools.** `--toolsets inspect,edit` shrinks the first prompt from about 1,860 to 1,370 tokens.
- **Use a smaller context** with `--num-ctx 4096`. The chat trims old results to fit.
- **Keep the model loaded.** Ollama unloads idle models. Set the `OLLAMA_KEEP_ALIVE` environment variable (for example `30m`) before starting Ollama.
- **Ask for one thing at a time**, naming the objects you mean.
- **Watch it work.** Replies appear as they are generated.
- **Allow more time** with `--timeout 1200` if the first words take longer than ten minutes.
## ⚙️ Options
| Option | Applies to | Meaning |
|---|---|---|
| `--toolsets inspect,edit,scripts,editor` | `serve`, `chat` | Expose only these groups |
| `--read-only` | `serve`, `chat` | Expose only tools that change nothing |
| `--project NAME` | `serve`, `chat`, `doctor` | Choose an editor when several are open |
| `--provider ollama\|lmstudio` | `chat` | Model server (default `ollama`) |
| `--model NAME` | `chat` | Model to use |
| `--url URL` | `chat` | Model server on another address |
| `--api-key TOKEN` | `chat` | LM Studio API token, or set `LM_API_TOKEN` |
| `--num-ctx N` | `chat` | Context length (default 8192). For LM Studio, match the app's setting |
| `--think` / `--no-think` | `chat` | Ollama thinking mode |
| `--max-steps N` | `chat` | Model steps allowed per request (default 12) |
| `--timeout SECONDS` | `chat` | Longest silence from the model server (default 600) |
| `--no-stream` | `chat` | Wait for whole replies instead of showing text as it arrives |
| `--prompt TEXT` | `chat` | Run one request and exit |
| `--yes` | `chat` | Approve every change without asking |
The server also reads `UNITY_MCP_TOOLSETS`, `UNITY_MCP_READ_ONLY` and `UNITY_MCP_PROJECT`. In LM Studio, add options to `args`, for example `"--toolsets", "inspect,edit"`.
## 🔒 Security
> [!WARNING]
> A script that a model writes runs with your user account's permissions once Unity compiles it. Read it before you approve it, and keep your project under version control.
- The editor accepts connections from `127.0.0.1` only. Every request needs a random token, stored in `~/.unity-local-mcp/instances/` while Unity is open. Programs running as your user can read it.
- Models can write only `.cs` scripts and `.prefab` files, under `Assets/`. A replaced file is first copied to `Library/UnityLocalMcp/Backups/`. Reading is limited to text files under `Assets/` and `Packages/`.
- **Window → Unity Local MCP** has switches for **Read-only** and **Allow writing scripts**. Unity enforces them whatever the client asks.
- The built-in chat asks before each change unless you pass `--yes` or answer *always*. In LM Studio, tool permissions are controlled by LM Studio.
- Undo covers scene edits. It does not cover files or prefab links: new scripts, prefabs and the color materials in `Assets/UnityLocalMcp/Materials/` stay in your project.
## 🩺 Troubleshooting
| Problem | Try this |
|---|---|
| `No running Unity Editor found` | Open the project and check **Window → Unity Local MCP** says *Running*. Then run `doctor` |
| `Unity is busy` or `not answering` | Close any open Unity dialog, and wait for imports or compiling to finish |
| The Unity window is missing | Fix compile errors in the Console, and check the package appears in Package Manager |
| `Cannot reach Ollama` | Start the Ollama app or run `ollama serve` |
| `cannot call tools` | Pick another model. `doctor` lists which of your Ollama models can |
| The model describes steps but changes nothing | Name the objects you mean, or try a larger model |
| The model forgets what you asked | Raise `--num-ctx`, or `/reset` between tasks |
| LM Studio cannot start the server | Replace `uvx` with its full path (`where uvx` on Windows, `which uvx` elsewhere) |
Changes made while Unity is in Play mode are lost when it stops, as with manual edits.
## 🧪 Development
```bash
git clone https://github.com/isaiahagi/unity-local-mcp.git
cd unity-local-mcp
uv sync
uv run pytest
```
The tests use stand-ins for Unity and the model servers, so neither needs to be running.
To work on the Unity package, use **Package Manager → + → Install package from disk** and pick `unity-package/package.json`. To point LM Studio at your clone, use `"command": "uv"` with `"args": ["--directory", "/path/to/unity-local-mcp", "run", "unity-local-mcp"]`.
## 🗺️ Roadmap
- [ ] Test LM Studio, and the Unity package on macOS and Linux
- [ ] Scene screenshots for vision models
- [ ] Edit materials
- [ ] Publish to PyPI
## 🤝 Contributing
Issues and pull requests are welcome. For a bug, include your Unity version, model, and the output of `doctor`.
## ⭐ Star history
If this saves you time, a star helps other people find it.
<a href="https://www.star-history.com/#isaiahagi/unity-local-mcp&type=date">
<img src="https://api.star-history.com/chart?repos=isaiahagi/unity-local-mcp&type=date&legend=top-left" alt="Star history chart" width="640">
</a>
## 📄 License
[MIT](LICENSE)
<sub>Not affiliated with or endorsed by Unity Technologies, Ollama or LM Studio. Product names belong to their owners.</sub>
TDQS
Scored across 18 tools
Most tools target a clearly distinct resource+action: hierarchy inspection (get_hierarchy, find_objects, get_object), mutation (create_object, update_object, delete_object), components (add_component, remove_component, set_property), and editor control (get_editor_state, set_play_mode, save_scene). The only soft overlaps are set_color versus set_property (color is a special case of a property) and update_object versus set_property for transform-like changes, but the descriptions steer an agent reasonably well.
Every tool follows a strict snake_case verb_noun pattern (delete_object, list_assets, get_editor_state, add_component, set_property, write_script, set_play_mode, save_scene). Verb choice is also semantically consistent (get_ for single-item reads, list_/find_ for searches, set_ for single-value mutations).
18 tools is at the upper end but each maps to a real Unity editor capability across scene hierarchy, components, properties, prefabs, scripts, console, and play mode. A few could theoretically be folded together (set_color into set_property), but nothing feels like filler.
Core lifecycle is well covered: inspect state/hierarchy, create/update/delete objects, add/remove components, edit properties, author scripts, read logs, drive play mode, and save the scene. Gaps are the prefab lifecycle (create_prefab exists but no instantiate/apply/revert) and asset management beyond listing (no create folder, delete, move, or import), which agents can partially work around but not fully.