unity-ui-agent-mcp 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- unity_ui_agent_mcp-0.3.0/.gitignore +18 -0
- unity_ui_agent_mcp-0.3.0/PKG-INFO +52 -0
- unity_ui_agent_mcp-0.3.0/README.md +21 -0
- unity_ui_agent_mcp-0.3.0/pyproject.toml +64 -0
- unity_ui_agent_mcp-0.3.0/src/unity_ui_agent_mcp/__init__.py +3 -0
- unity_ui_agent_mcp-0.3.0/src/unity_ui_agent_mcp/compare.py +168 -0
- unity_ui_agent_mcp-0.3.0/src/unity_ui_agent_mcp/crop.py +35 -0
- unity_ui_agent_mcp-0.3.0/src/unity_ui_agent_mcp/server.py +865 -0
- unity_ui_agent_mcp-0.3.0/src/unity_ui_agent_mcp/unity_client.py +89 -0
- unity_ui_agent_mcp-0.3.0/tests/__init__.py +0 -0
- unity_ui_agent_mcp-0.3.0/tests/conftest.py +116 -0
- unity_ui_agent_mcp-0.3.0/tests/test_client.py +94 -0
- unity_ui_agent_mcp-0.3.0/tests/test_compare.py +187 -0
- unity_ui_agent_mcp-0.3.0/tests/test_crop.py +153 -0
- unity_ui_agent_mcp-0.3.0/tests/test_fake_bridge.py +33 -0
- unity_ui_agent_mcp-0.3.0/tests/test_sprite.py +52 -0
- unity_ui_agent_mcp-0.3.0/tests/test_text_tmp.py +132 -0
- unity_ui_agent_mcp-0.3.0/tests/test_tools.py +926 -0
- unity_ui_agent_mcp-0.3.0/tests/test_ui_effects.py +117 -0
- unity_ui_agent_mcp-0.3.0/tests/test_version.py +37 -0
- unity_ui_agent_mcp-0.3.0/uv.lock +2182 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
.venv/
|
|
5
|
+
*.egg-info/
|
|
6
|
+
dist/
|
|
7
|
+
build/
|
|
8
|
+
|
|
9
|
+
# OS / IDE
|
|
10
|
+
.DS_Store
|
|
11
|
+
Thumbs.db
|
|
12
|
+
.idea/
|
|
13
|
+
.vscode/
|
|
14
|
+
*.swp
|
|
15
|
+
|
|
16
|
+
# Unity creates these when it imports the package; scripts/ holds only PowerShell tools
|
|
17
|
+
/scripts.meta
|
|
18
|
+
/scripts/*.meta
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: unity-ui-agent-mcp
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: MCP server that lets AI agents build and inspect uGUI layouts in the Unity Editor.
|
|
5
|
+
Project-URL: Homepage, https://github.com/maguera93/unity-ui-agent-mcp
|
|
6
|
+
Project-URL: Repository, https://github.com/maguera93/unity-ui-agent-mcp
|
|
7
|
+
Project-URL: Issues, https://github.com/maguera93/unity-ui-agent-mcp/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/maguera93/unity-ui-agent-mcp/blob/master/CHANGELOG.md
|
|
9
|
+
Author-email: Marc Agüera Garcia <magueracoras@gmail.com>
|
|
10
|
+
License: MIT
|
|
11
|
+
Keywords: ai-agent,claude,mcp,ugui,ui,unity
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Requires-Dist: mcp<3,>=2.0
|
|
26
|
+
Requires-Dist: numpy>=2.2.6
|
|
27
|
+
Requires-Dist: pillow>=12.3.0
|
|
28
|
+
Requires-Dist: pydantic>=2
|
|
29
|
+
Requires-Dist: scikit-image>=0.25.2
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# unity-ui-agent-mcp (Python MCP server)
|
|
33
|
+
|
|
34
|
+
MCP server that lets AI agents such as Claude Code build, inspect and visually check uGUI layouts in the Unity Editor. It talks to the Unity Editor bridge (the `com.marcaguera.unity-ui-agent` package) over HTTP on `127.0.0.1:6400`.
|
|
35
|
+
|
|
36
|
+
Requires [uv](https://docs.astral.sh/uv/) and the Unity package from the repository: https://github.com/maguera93/unity-ui-agent-mcp
|
|
37
|
+
|
|
38
|
+
## Run
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
uvx unity-ui-agent-mcp
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Register it in Claude Code:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
claude mcp add unity-ui-agent -- uvx unity-ui-agent-mcp
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Set `UNITY_UI_AGENT_PORT` if the Unity bridge does not use the default port 6400.
|
|
51
|
+
|
|
52
|
+
The full setup, the tool list and the design loop are in the [repository README](https://github.com/maguera93/unity-ui-agent-mcp#readme).
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# unity-ui-agent-mcp (Python MCP server)
|
|
2
|
+
|
|
3
|
+
MCP server that lets AI agents such as Claude Code build, inspect and visually check uGUI layouts in the Unity Editor. It talks to the Unity Editor bridge (the `com.marcaguera.unity-ui-agent` package) over HTTP on `127.0.0.1:6400`.
|
|
4
|
+
|
|
5
|
+
Requires [uv](https://docs.astral.sh/uv/) and the Unity package from the repository: https://github.com/maguera93/unity-ui-agent-mcp
|
|
6
|
+
|
|
7
|
+
## Run
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
uvx unity-ui-agent-mcp
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Register it in Claude Code:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
claude mcp add unity-ui-agent -- uvx unity-ui-agent-mcp
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Set `UNITY_UI_AGENT_PORT` if the Unity bridge does not use the default port 6400.
|
|
20
|
+
|
|
21
|
+
The full setup, the tool list and the design loop are in the [repository README](https://github.com/maguera93/unity-ui-agent-mcp#readme).
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "unity-ui-agent-mcp"
|
|
3
|
+
version = "0.3.0"
|
|
4
|
+
description = "MCP server that lets AI agents build and inspect uGUI layouts in the Unity Editor."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
license = { text = "MIT" }
|
|
8
|
+
authors = [{ name = "Marc Agüera Garcia", email = "magueracoras@gmail.com" }]
|
|
9
|
+
keywords = ["mcp", "unity", "ugui", "ui", "ai-agent", "claude"]
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Development Status :: 4 - Beta",
|
|
12
|
+
"Environment :: Console",
|
|
13
|
+
"Intended Audience :: Developers",
|
|
14
|
+
"License :: OSI Approved :: MIT License",
|
|
15
|
+
"Operating System :: OS Independent",
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
18
|
+
"Programming Language :: Python :: 3.10",
|
|
19
|
+
"Programming Language :: Python :: 3.11",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"Topic :: Software Development :: Code Generators",
|
|
23
|
+
]
|
|
24
|
+
dependencies = [
|
|
25
|
+
"mcp>=2.0,<3",
|
|
26
|
+
"numpy>=2.2.6",
|
|
27
|
+
"pillow>=12.3.0",
|
|
28
|
+
"pydantic>=2",
|
|
29
|
+
"scikit-image>=0.25.2",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.urls]
|
|
33
|
+
Homepage = "https://github.com/maguera93/unity-ui-agent-mcp"
|
|
34
|
+
Repository = "https://github.com/maguera93/unity-ui-agent-mcp"
|
|
35
|
+
Issues = "https://github.com/maguera93/unity-ui-agent-mcp/issues"
|
|
36
|
+
Changelog = "https://github.com/maguera93/unity-ui-agent-mcp/blob/master/CHANGELOG.md"
|
|
37
|
+
|
|
38
|
+
[project.scripts]
|
|
39
|
+
unity-ui-agent-mcp = "unity_ui_agent_mcp.server:main"
|
|
40
|
+
|
|
41
|
+
[dependency-groups]
|
|
42
|
+
dev = [
|
|
43
|
+
"pytest>=8",
|
|
44
|
+
"ruff>=0.6",
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
[tool.pytest.ini_options]
|
|
48
|
+
testpaths = ["tests"]
|
|
49
|
+
|
|
50
|
+
[tool.ruff]
|
|
51
|
+
line-length = 100
|
|
52
|
+
target-version = "py310"
|
|
53
|
+
|
|
54
|
+
[tool.ruff.lint]
|
|
55
|
+
select = ["E", "F", "W", "I"]
|
|
56
|
+
# Tool descriptions in server.py are long by design (the agent reads them).
|
|
57
|
+
ignore = ["E501"]
|
|
58
|
+
|
|
59
|
+
[build-system]
|
|
60
|
+
requires = ["hatchling"]
|
|
61
|
+
build-backend = "hatchling.build"
|
|
62
|
+
|
|
63
|
+
[tool.hatch.build.targets.wheel]
|
|
64
|
+
packages = ["src/unity_ui_agent_mcp"]
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"""Image comparison between the target mockup and a render of the UI (SSIM).
|
|
2
|
+
|
|
3
|
+
Pure functions over image bytes: no Unity and no files, so they run in CI and in tests.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import io
|
|
9
|
+
|
|
10
|
+
import numpy as np
|
|
11
|
+
from PIL import Image
|
|
12
|
+
from skimage import measure
|
|
13
|
+
from skimage.metrics import structural_similarity
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def load_rgb(data: bytes) -> np.ndarray:
|
|
17
|
+
"""Decode PNG or JPG bytes into an RGB uint8 array of shape (height, width, 3)."""
|
|
18
|
+
with Image.open(io.BytesIO(data)) as image:
|
|
19
|
+
return np.asarray(image.convert("RGB"), dtype=np.uint8)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def pixel_diff(reference: bytes, rendered: bytes) -> float:
|
|
23
|
+
"""Mean difference per pixel channel, from 0 (identical) to 1 (every channel opposite).
|
|
24
|
+
|
|
25
|
+
Both images must have the same size, as for ssim_score.
|
|
26
|
+
"""
|
|
27
|
+
expected = load_rgb(reference)
|
|
28
|
+
actual = load_rgb(rendered)
|
|
29
|
+
if expected.shape != actual.shape:
|
|
30
|
+
raise ValueError(
|
|
31
|
+
f"Image sizes differ: reference is {expected.shape[1]}x{expected.shape[0]}, "
|
|
32
|
+
f"rendered is {actual.shape[1]}x{actual.shape[0]}. Render at the target size first."
|
|
33
|
+
)
|
|
34
|
+
difference = np.abs(expected.astype(np.int16) - actual.astype(np.int16))
|
|
35
|
+
return float(difference.mean() / 255.0)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def error_map(reference: bytes, rendered: bytes) -> np.ndarray:
|
|
39
|
+
"""Per-pixel error in 0..1: mean absolute difference over the RGB channels.
|
|
40
|
+
|
|
41
|
+
Returns a float array of shape (height, width). Both images must have the same size.
|
|
42
|
+
"""
|
|
43
|
+
expected = load_rgb(reference)
|
|
44
|
+
actual = load_rgb(rendered)
|
|
45
|
+
if expected.shape != actual.shape:
|
|
46
|
+
raise ValueError(
|
|
47
|
+
f"Image sizes differ: reference is {expected.shape[1]}x{expected.shape[0]}, "
|
|
48
|
+
f"rendered is {actual.shape[1]}x{actual.shape[0]}. Render at the target size first."
|
|
49
|
+
)
|
|
50
|
+
difference = np.abs(expected.astype(np.int16) - actual.astype(np.int16))
|
|
51
|
+
return difference.mean(axis=2) / 255.0
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def worst_regions(
|
|
55
|
+
reference: bytes, rendered: bytes, count: int = 5, threshold: float = 0.1
|
|
56
|
+
) -> list[dict[str, float | int]]:
|
|
57
|
+
"""The `count` regions with the most total error, largest first.
|
|
58
|
+
|
|
59
|
+
A region is a connected group of pixels whose error is at least `threshold` (0..1).
|
|
60
|
+
Each entry has x, y, width, height (pixels, top-left origin), `pixels` (area),
|
|
61
|
+
`mean_error` and `total_error` (sum of the per-pixel error inside the region, 0..pixels).
|
|
62
|
+
Returns an empty list when nothing reaches the threshold.
|
|
63
|
+
"""
|
|
64
|
+
if count < 1:
|
|
65
|
+
raise ValueError("count must be at least 1.")
|
|
66
|
+
if not 0.0 <= threshold <= 1.0:
|
|
67
|
+
raise ValueError("threshold must be between 0 and 1.")
|
|
68
|
+
|
|
69
|
+
error = error_map(reference, rendered)
|
|
70
|
+
mask = error >= threshold
|
|
71
|
+
labels = measure.label(mask, connectivity=2)
|
|
72
|
+
|
|
73
|
+
regions: list[dict[str, float | int]] = []
|
|
74
|
+
for region in measure.regionprops(labels, intensity_image=error):
|
|
75
|
+
min_row, min_col, max_row, max_col = region.bbox
|
|
76
|
+
values = region.image_intensity[region.image]
|
|
77
|
+
regions.append(
|
|
78
|
+
{
|
|
79
|
+
"x": int(min_col),
|
|
80
|
+
"y": int(min_row),
|
|
81
|
+
"width": int(max_col - min_col),
|
|
82
|
+
"height": int(max_row - min_row),
|
|
83
|
+
"pixels": int(region.area),
|
|
84
|
+
"mean_error": float(values.mean()),
|
|
85
|
+
"total_error": float(values.sum()),
|
|
86
|
+
}
|
|
87
|
+
)
|
|
88
|
+
regions.sort(key=lambda item: item["total_error"], reverse=True)
|
|
89
|
+
return regions[:count]
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def diff_heatmap(reference: bytes, rendered: bytes) -> bytes:
|
|
93
|
+
"""PNG heat map of the error: black where the images match, through red, to yellow where they differ most.
|
|
94
|
+
|
|
95
|
+
The colour ramp is linear in the error, so the same colour always means the same difference.
|
|
96
|
+
"""
|
|
97
|
+
error = error_map(reference, rendered)
|
|
98
|
+
red = np.clip(error * 2.0, 0.0, 1.0)
|
|
99
|
+
green = np.clip(error * 2.0 - 1.0, 0.0, 1.0)
|
|
100
|
+
rgb = np.stack([red, green, np.zeros_like(error)], axis=2)
|
|
101
|
+
buffer = io.BytesIO()
|
|
102
|
+
Image.fromarray((rgb * 255).astype(np.uint8), mode="RGB").save(buffer, format="PNG")
|
|
103
|
+
return buffer.getvalue()
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def fit_to_size(data: bytes, width: int, height: int) -> bytes:
|
|
107
|
+
"""Resize an image to width x height (Lanczos) and return it as PNG bytes.
|
|
108
|
+
|
|
109
|
+
Used to bring the mockup to the size of the render, so both can be compared pixel by pixel.
|
|
110
|
+
An image that already has that size is re-encoded unchanged in content.
|
|
111
|
+
"""
|
|
112
|
+
with Image.open(io.BytesIO(data)) as image:
|
|
113
|
+
resized = image.convert("RGB").resize((width, height), Image.Resampling.LANCZOS)
|
|
114
|
+
buffer = io.BytesIO()
|
|
115
|
+
resized.save(buffer, format="PNG")
|
|
116
|
+
return buffer.getvalue()
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def align_reference(reference: bytes, rendered: bytes) -> bytes:
|
|
120
|
+
"""Return the mockup at the render's size, so the two can be compared.
|
|
121
|
+
|
|
122
|
+
The render is what the UI produces at the target resolution, so it keeps its size and
|
|
123
|
+
the mockup is scaled to match it. Returns the mockup unchanged when the sizes already match.
|
|
124
|
+
"""
|
|
125
|
+
rendered_rgb = load_rgb(rendered)
|
|
126
|
+
height, width = rendered_rgb.shape[:2]
|
|
127
|
+
reference_rgb = load_rgb(reference)
|
|
128
|
+
if reference_rgb.shape[:2] == (height, width):
|
|
129
|
+
return reference
|
|
130
|
+
return fit_to_size(reference, width, height)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
# skimage's SSIM uses 7x7 windows by default and fails on smaller images.
|
|
134
|
+
MIN_SSIM_SIDE = 7
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def ssim_score(reference: bytes, rendered: bytes) -> float:
|
|
138
|
+
"""Structural similarity between two images of the same size, from -1 to 1 (1 = identical).
|
|
139
|
+
|
|
140
|
+
The raw SSIM can be negative for images that are anti-correlated; use ssim_unit for 0..1.
|
|
141
|
+
Both images must have the same width and height; aligning them is the caller's job.
|
|
142
|
+
Raises ValueError with an actionable message when the sizes differ or an image is smaller
|
|
143
|
+
than MIN_SSIM_SIDE pixels on either side.
|
|
144
|
+
"""
|
|
145
|
+
expected = load_rgb(reference)
|
|
146
|
+
actual = load_rgb(rendered)
|
|
147
|
+
if expected.shape != actual.shape:
|
|
148
|
+
raise ValueError(
|
|
149
|
+
f"Image sizes differ: reference is {expected.shape[1]}x{expected.shape[0]}, "
|
|
150
|
+
f"rendered is {actual.shape[1]}x{actual.shape[0]}. Render at the target size first."
|
|
151
|
+
)
|
|
152
|
+
height, width = expected.shape[:2]
|
|
153
|
+
if height < MIN_SSIM_SIDE or width < MIN_SSIM_SIDE:
|
|
154
|
+
raise ValueError(
|
|
155
|
+
f"Image is {width}x{height}px; SSIM needs at least {MIN_SSIM_SIDE}x{MIN_SSIM_SIDE}px. "
|
|
156
|
+
"Capture the UI at a larger size (pass width and height to capture_game_view)."
|
|
157
|
+
)
|
|
158
|
+
score = structural_similarity(expected, actual, channel_axis=2, data_range=255)
|
|
159
|
+
return float(score)
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def ssim_unit(reference: bytes, rendered: bytes) -> float:
|
|
163
|
+
"""ssim_score clamped to 0..1: 1 = identical, 0 = no structural similarity or worse.
|
|
164
|
+
|
|
165
|
+
Negative SSIM values (anti-correlated images) are reported as 0, so the result never goes
|
|
166
|
+
below zero. The raw value is still available from ssim_score.
|
|
167
|
+
"""
|
|
168
|
+
return max(0.0, min(1.0, ssim_score(reference, rendered)))
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""Crop a rectangle out of the target mockup (PNG or JPG) and encode it as PNG.
|
|
2
|
+
|
|
3
|
+
Pure functions over image bytes: no Unity and no files, so they run in CI and in tests.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import io
|
|
9
|
+
|
|
10
|
+
from PIL import Image
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def crop_png(data: bytes, x: int, y: int, width: int, height: int) -> bytes:
|
|
14
|
+
"""Return the rectangle [x, y, width, height] of the image as PNG bytes, keeping alpha.
|
|
15
|
+
|
|
16
|
+
Origin is top-left, in pixels of the source image. Raises ValueError when the rectangle is
|
|
17
|
+
empty or does not fit inside the image.
|
|
18
|
+
"""
|
|
19
|
+
if width < 1 or height < 1:
|
|
20
|
+
raise ValueError(f"The crop size must be at least 1x1, got {width}x{height}.")
|
|
21
|
+
if x < 0 or y < 0:
|
|
22
|
+
raise ValueError(f"The crop origin must be inside the image, got x={x}, y={y}.")
|
|
23
|
+
|
|
24
|
+
with Image.open(io.BytesIO(data)) as image:
|
|
25
|
+
source_width, source_height = image.size
|
|
26
|
+
if x + width > source_width or y + height > source_height:
|
|
27
|
+
raise ValueError(
|
|
28
|
+
f"The crop [{x}, {y}, {width}, {height}] does not fit the mockup ({source_width}x{source_height}). "
|
|
29
|
+
"Use a region inside the image, with x + width and y + height at most the image size."
|
|
30
|
+
)
|
|
31
|
+
cropped = image.convert("RGBA").crop((x, y, x + width, y + height))
|
|
32
|
+
|
|
33
|
+
out = io.BytesIO()
|
|
34
|
+
cropped.save(out, format="PNG")
|
|
35
|
+
return out.getvalue()
|