Skip to main content

ui_source

Auto-generated from the Python tool registry. Do not hand-edit outside <!-- examples:start --><!-- examples:end --> blocks — the generator (tools/generate_docs_reference.py) will overwrite them.

Group: ui  ·  Module: services.registry.capability_adapter

Maturity: stable (support status; independent of enabled state, readiness and permissions).

Description​

Create, read or edit UXML/USS assets, link stylesheets or preview source patches.

Parameters​

NameTypeRequiredDescription
actionLiteral['create', 'read', 'update', 'delete', 'link_stylesheet', 'list', 'patch_source']yesFeature action to perform.
pathstr | None—Assets-relative path (e.g., 'Assets/UI/MainMenu.uxml' or 'Assets/UI/Styles.uss'). For render_ui: optional UXML path to render directly without a scene GameObject.
contentsstr | None—File content (UXML or USS markup). Plain text - encoding handled automatically.
source_selectorstr | None—patch_source: unique UXML #name, or exact simple USS type/.class/#name rule.
source_changesdict[str, str] | None—patch_source: 1..32 existing UXML text/tooltip/class attributes or USS declarations; values <=4096 characters. No insertion/removal or template ownership.
previewbool—patch_source: true (default) returns SHA256 and exact value edits without writing. False persists source and reimports; live view refresh is separate.
expected_source_hashstr | None—patch_source apply requires source_hash from preview. Detects changed source before write. UTF8 files <=1 MiB; preserves BOM, surrounding bytes and .meta.
verify_targetstr | None—Optional exact live document target for create/update/link_stylesheet/patch_source writes. Resolved before saving; adds bounded current diagnostics without forcing layout or capture. Source-to-live application remains pending until normal UI updates.
component_typeLiteral['auto', 'ui_document', 'panel_renderer'] | None—UI component for attach/detach, get_visual_tree, modify_visual_element and render_ui. Default auto preserves an existing UIDocument, otherwise resolves PanelRenderer; new attachments prefer PanelRenderer when available and fall back to UIDocument. Explicit panel_renderer selection requires the Editor's native PanelRenderer API.
stylesheetstr | None—Path to USS stylesheet to link (e.g., 'Assets/UI/Styles.uss'). For link_stylesheet.
filter_typestr | None—Filter UI assets by type: 'uxml', 'uss', 'PanelSettings', or omit for all. For list.
page_sizeint | None—Number of results per page: 1-1000 (default 50). For list.
page_numberint | None—Page number, 1-based (default 1). For list.
inventory_revisionstr | None—list: reuse the returned inventory_revision with the same scope/filter to reject pages after asset changes, expiry or eviction. Omit for the latest cached inventory; oversized inventories remain complete but uncached.
unity_instancestr | int | None—Target Unity instance for this call: Name@hash or hash prefix; an integer selects only that exact port over stdio and is rejected over HTTP. Read mcpforunity://instances for available targets. Omit to use the legacy active selection or the sole available instance.

Returns​

A dict containing the Unity response. The exact shape depends on the action.

Examples​

Find the first 20 UXML documents before choosing a file to inspect or edit.

MCP arguments
{
"action": "list",
"filter_type": "uxml",
"page_size": 20,
"page_number": 1
}