unity-ui-agent-mcp

v0.3.0
unity-ui-agent-mcp Checked 1 day ago Published 1 day ago

MCP server that lets AI agents build and inspect uGUI layouts in the Unity Editor.

These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.

unity_status

Check the connection to the Unity Editor: version, project, Play Mode and open prefab.

get_hierarchy

Return the scene hierarchy with UI details: paths, RectTransforms, colours, texts and components.

ParameterTypeDescription
include_inactivebooleanInclude disabled GameObjects.
max_depthintegerHow many levels of children to include.
rootPath to start from, e.g. 'Canvas/MainMenu'. Omit for the whole scene (or the open prefab).

create_ui_element

Create a uGUI element and return its path and RectTransform. Types: panel, image, text, button, empty (container), and the interactive controls toggle, slider, inputfield, dropdown and scrollrect. A scrollrect's content goes in its Content child, created by the Editor. For text, font_size, font_style, alignment and text_color apply to TextMeshPro or legacy Text. Import a font with import_font first to get a TMP Font Asset. An inputfield or a dropdown supports text_engine legacy or auto only.

build_ui_tree

Create a whole UI hierarchy in one call (up to 500 elements) as a single Undo step. Prefer this over many create_ui_element calls when building a screen from a design. If any element fails, nothing is created and the error names the failing node. Returns the paths of all created elements, for later update_ui_element calls. Interactive controls: toggle (is_on), slider (min_value, max_value, value, whole_numbers), inputfield (text, placeholder, character_limit), dropdown (options, selected_index) and scrollrect (horizontal, vertical; its children go into the Content).…

update_ui_element

Change an existing element: RectTransform, colour, sprite, text, layout group, name, parent, active state or the state of an interactive control (toggle on/off, slider value, input field placeholder and limit, dropdown options and selection, scroll rect axes).

delete_object

Delete a GameObject. The user can restore it with Undo.

ParameterTypeDescription
path *stringPath of the GameObject to delete (with its children).

set_component_property

Set one serialized field of a component on a GameObject, in a single Undo step. Use it for properties that have no dedicated tool, for example an Image's raycast target or a Text's font size. The value is checked against the field type first; a wrong type changes nothing and the error names the expected type. Returns the path, component and property that were set.

ParameterTypeDescription
component *stringComponent type name, such as 'Image', 'Button' or 'Text'.
path *stringPath of the GameObject that holds the component, e.g. 'Canvas/MainMenu/PlayButton'.
property *stringUnity serialized field name, such as 'm_Color', 'm_Interactable' or 'm_FontData.m_FontSize' (nested fields use dots).
value *The new value as JSON: a number, bool, string, enum name or index, hex colour '#RRGGBB', [x, y], [x, y, z], [x, y, z, w], [x, y, width, height], an asset path under Assets/ for an object reference, or…

save_as_prefab

Save a scene object as a prefab asset. The scene object stays as it is and is not linked to the prefab. Returns the prefab path, the source path, how many children it has, and sceneObjectLinked=false. Not undoable. Refuses while a prefab is open in Prefab Mode.

ParameterTypeDescription
path *stringPath of the scene object to save as a prefab, e.g. 'Canvas/MainMenu'.
prefab_path *stringProject path of the new prefab, e.g. 'Assets/UI/MainMenu.prefab'. Its folder must already exist.
overwritebooleanReplace a prefab that already exists at prefab_path.

save_scene

Save the active scene, or save it to a new path. Refuses while a prefab is open in Prefab Mode. Returns the scene path and dirty (true if it still has unsaved changes).

ParameterTypeDescription
overwritebooleanReplace a scene that already exists at path.
pathProject path to save the active scene to, e.g. 'Assets/Scenes/Main.unity'. Omit to save the scene in place; a scene that was never saved needs a path.

set_target_design

Set the mockup the UI must match and its resolution. The Canvas Scalers are fitted to that size. Returns the stored path, width, height and how many canvases were adjusted.

ParameterTypeDescription
path *stringPath of the mockup image to reproduce (PNG or JPG), e.g. 'Assets/Design/menu.png'.

import_font

Import a font into the project and, by default, generate its TextMeshPro Font Asset. Returns the font path, the TMP Font Asset path (null if not generated) and an optional note, for example when TextMeshPro is not installed.

ParameterTypeDescription
path *stringFont file inside the project's Assets folder, .ttf or .otf, e.g. 'Assets/Fonts/Inter.ttf'. Copy the file into Assets first.
replacebooleanOverwrite an existing TMP Font Asset generated for this font.
tmp_font_assetbooleanAlso generate a TextMeshPro Font Asset next to the font (needed for textEngine tmp).

import_sprite

Import a PNG as a Sprite (Single mode), optionally as a nine-slice with the given borders. Returns the sprite path, the borders applied, whether it is sliced (any border set), its pixels per unit and its size in pixels. Use the path as the sprite argument of create_ui_element or update_ui_element.

ParameterTypeDescription
path *stringPNG file inside the project's Assets folder, e.g. 'Assets/UI/panel.png'. Copy the file into Assets first.
borderNine-slice borders in pixels: [left, bottom, right, top]. Omit to keep the sprite's current borders.
pixels_per_unitintegerSprite Pixels Per Unit.

compare_to_target

Capture the UI at the target size and compare it with the mockup. Returns ssim (structural similarity, 1 = identical, clamped to 0..1) and pixel_diff (mean difference per channel, 0 = identical, 1 = opposite). The mockup is scaled to the capture size when they differ. Use it after each change to see how close the UI is.

ParameterTypeDescription
reference_path *stringAbsolute path of the mockup on disk (PNG or JPG), the same image given to set_target_design.

diff_to_target

Capture the UI at the target size and show where it differs from the mockup. Returns the five worst regions as JSON (x, y, width, height in pixels, plus pixels, mean_error and total_error, each error 0..1) and a heat map image: black where the UI matches the mockup, red to yellow where it differs most. Fix the regions listed first.

ParameterTypeDescription
reference_path *stringAbsolute path of the mockup on disk (PNG or JPG), the same image given to set_target_design.

crop_from_target

Cut a rectangle out of the mockup, save it under Assets/ and import it as a Sprite. The region is in mockup pixels, not in the Unity capture. The file must be inside an Assets folder; the Unity path (Assets/...) is derived from it and imported with import_sprite. Returns the written file, its size, the Unity asset path and the import result. Use the returned sprite path as the sprite argument of create_ui_element or build_ui_tree.

ParameterTypeDescription
output_path *stringAbsolute path of the PNG to write inside the Unity project's Assets folder, e.g. 'D:/Game/Assets/UI/Crops/icon.png'. Its folder must exist.
reference_path *stringAbsolute path of the mockup on disk (PNG or JPG), the same image given to set_target_design.
region *Rectangle to cut out, [x, y, width, height] or {x, y, width, height}, in pixels of the mockup, origin top-left.
borderNine-slice borders in pixels: [left, bottom, right, top]. Omit for a plain sprite.
pixels_per_unitintegerSprite Pixels Per Unit of the imported sprite.

capture_game_view

Render the UI to a PNG (works in Edit Mode) so you can compare it with the target design. Use max_side and region to look at a part of a large screen without sending the whole image. The summary reports the size of the source render and of the returned image.

ParameterTypeDescription
backgroundColour behind the UI when the scene has no main camera, e.g. '#202020'.
heightDefaults to the Canvas Scaler reference height.
max_sideShrink the longer side to this many pixels, keeping the aspect ratio. Use it to save tokens on large captures.
regionCrop the capture to [x, y, width, height] or {x, y, width, height} in pixels of the (possibly shrunk) capture, origin top-left.
widthDefaults to the Canvas Scaler reference width.

check_layout

Check the UI at several screen sizes and report, per size, the elements that overlap a sibling, extend past the screen edge ("outOfBounds") or lie fully off screen ("offScreen"). Read-only: it does not change the scene. Each entry also gives the file of the saved capture. The "other" field of an overlap issue names the element it overlaps.

ParameterTypeDescription
resolutions *array1 to 8 [width, height] pairs, e.g. [[1920, 1080], [1280, 720]]. Each side 16 to 4096 pixels.
return_imagesbooleanAttach the PNG of each resolution. Off by default because the captures are large.

read_console

Read recent Unity Console messages, including compiler errors.

ParameterTypeDescription
clearbooleanClear the buffer after reading.
countinteger
typesFilter by type; omit for all.