apply_text_edits
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: core · Module: services.tools.manage_script
Maturity: stable (support status; independent of enabled state, readiness and permissions).
Description
Apply small text edits to a C# script identified by URI. IMPORTANT: This tool replaces EXACT character positions. Always verify content at target lines/columns BEFORE editing! RECOMMENDED WORKFLOW: 1. First call resources/read with start_line/line_count to verify exact content 2. Count columns carefully (or use find_in_file to locate patterns) 3. Apply your edit with precise coordinates 4. Consider script_apply_edits with anchors for safer pattern-based replacements Notes: - For method/class operations, use script_apply_edits (safer, structured edits) - For pattern-based replacements, consider anchor operations in script_apply_edits - newText is literal: whitespace and line endings are preserved exactly, with no indentation or newline padding - End positions are exclusive; line endings outside the range remain. Include a boundary newline in newText only when the intended result needs an additional one. - options.preview=true prepares a complete read-only proposal with target paths and hashes; older Unity packages reject the safe preview action and require an upgrade - Lines, columns are 1-indexed - Tabs count as 1 column
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
uri | str | yes | URI of the script to edit under Assets/ directory, mcpforunity://path/Assets/... or file://... or Assets/... |
edits | list[dict[str, Any]] | yes | List of edits to apply to the script, i.e. a list of {startLine,startCol,endLine,endCol,newText} (1-indexed!) |
precondition_sha256 | str | None | — | Optional SHA256 of the script to edit, used to prevent concurrent edits |
strict | bool | None | — | Optional strict flag, used to enforce strict mode |
options | dict[str, Any] | None | — | Editor options. verification='auto' (default) adds bounded post-save analysis and compile observations; 'off' defers them. |
unity_instance | str | 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
Preview inserting a file header at the first character of the Harbor fixture's Assets/BerthProbe.cs. The identical start and end positions make this an insertion. Review the returned proposal and source identity before applying edits.
{
"uri": "Assets/BerthProbe.cs",
"edits": [
{
"startLine": 1,
"startCol": 1,
"endLine": 1,
"endCol": 1,
"newText": "// Harbor scenario state probe\n"
}
],
"options": {
"preview": true
}
}