Class ApplyTextEdits
Handles applying small text edits to C# scripts identified by URI.
Inherited Members
Namespace: Unity.AI.MCP.Editor.Tools
Assembly: Unity.AI.MCP.Editor.dll
Syntax
public static class ApplyTextEdits
Fields
Description
Human-readable description of the Unity.ApplyTextEdits tool functionality and usage guidelines.
Declaration
public const string Description = "Apply small text edits to a C# script identified by URI.\n\n⚠️ IMPORTANT: This tool replaces EXACT character positions. Always verify content at target lines/columns BEFORE editing!\nCommon mistakes:\n- Assuming what's on a line without checking\n- Using wrong line numbers (they're 1-indexed)\n- Miscounting column positions (also 1-indexed, tabs count as 1)\n\nRECOMMENDED WORKFLOW:\n1) First call resources/read with start_line/line_count to verify exact content\n2) Count columns carefully (or use Unity.FindInFile to locate patterns)\n3) Apply your edit with precise coordinates\n4) Consider Unity.ScriptApplyEdits with anchors for safer pattern-based replacements\n\nArgs:\n- uri: unity://path/Assets/... or file://... or Assets/...\n- edits: list of {startLine,startCol,endLine,endCol,newText} (1-indexed!)\n- precondition_sha256: SHA of current file (prevents concurrent edit conflicts)\n\nNotes:\n- Path must resolve under Assets/\n- For method/class operations, use Unity.ScriptApplyEdits (safer, structured edits)\n- For pattern-based replacements, consider anchor operations in Unity.ScriptApplyEdits"
Field Value
| Type | Description |
|---|---|
| string |
Methods
GetOutputSchema()
Returns the output schema for this tool.
Declaration
[McpOutputSchema("Unity.ApplyTextEdits")]
public static object GetOutputSchema()
Returns
| Type | Description |
|---|---|
| object | An object describing the structure of the tool's output including success status, message, and data fields |
HandleCommand(ApplyTextEditsParams)
Main handler for applying text edits.
Declaration
[McpTool("Unity.ApplyTextEdits", "Apply small text edits to a C# script identified by URI.\n\n⚠️ IMPORTANT: This tool replaces EXACT character positions. Always verify content at target lines/columns BEFORE editing!\nCommon mistakes:\n- Assuming what's on a line without checking\n- Using wrong line numbers (they're 1-indexed)\n- Miscounting column positions (also 1-indexed, tabs count as 1)\n\nRECOMMENDED WORKFLOW:\n1) First call resources/read with start_line/line_count to verify exact content\n2) Count columns carefully (or use Unity.FindInFile to locate patterns)\n3) Apply your edit with precise coordinates\n4) Consider Unity.ScriptApplyEdits with anchors for safer pattern-based replacements\n\nArgs:\n- uri: unity://path/Assets/... or file://... or Assets/...\n- edits: list of {startLine,startCol,endLine,endCol,newText} (1-indexed!)\n- precondition_sha256: SHA of current file (prevents concurrent edit conflicts)\n\nNotes:\n- Path must resolve under Assets/\n- For method/class operations, use Unity.ScriptApplyEdits (safer, structured edits)\n- For pattern-based replacements, consider anchor operations in Unity.ScriptApplyEdits", null, null, Groups = new string[] { "core", "scripting" })]
public static object HandleCommand(ApplyTextEditsParams parameters)
Parameters
| Type | Name | Description |
|---|---|---|
| ApplyTextEditsParams | parameters | Parameters containing the URI, edits array, optional precondition SHA, and options |
Returns
| Type | Description |
|---|---|
| object | A response object indicating success or failure with detailed results including normalized edits and any warnings |