Class ScriptApplyEdits
Structured C# script editing with safer boundaries and comprehensive validation. This tool provides advanced script editing capabilities including method/class operations and anchor-based pattern matching with improved heuristics.
Inherited Members
Namespace: Unity.AI.MCP.Editor.Tools
Assembly: Unity.AI.MCP.Editor.dll
Syntax
public static class ScriptApplyEdits
Fields
Description
Description of the ScriptApplyEdits tool functionality and parameters.
Declaration
public const string Description = "Structured C# edits (methods/classes) with safer boundaries - prefer this over raw text.\n\nBest practices:\n- Prefer anchor_* ops for pattern-based insert/replace near stable markers\n- Use replace_method/delete_method for whole-method changes (keeps signatures balanced)\n- Avoid whole-file regex deletes; validators will guard unbalanced braces\n- For tail insertions, prefer anchor/regex_replace on final brace (class closing)\n- Pass options.validate='standard' for structural checks; 'relaxed' for interior-only edits\n\nCanonical fields (use these exact keys):\n- op: replace_method | insert_method | delete_method | anchor_insert | anchor_delete | anchor_replace\n- className: string (defaults to 'name' if omitted on method/class ops)\n- methodName: string (required for replace_method, delete_method)\n- replacement: string (required for replace_method, insert_method)\n- position: start | end | after | before (insert_method only)\n- afterMethodName / beforeMethodName: string (required when position='after'/'before')\n- anchor: regex string (for anchor_* ops)\n- text: string (for anchor_insert/anchor_replace)\n\nExamples:\n1) Replace a method:\n{\n \"name\": \"SmartReach\",\n \"path\": \"Assets/Scripts/Interaction\",\n \"edits\": [{\n \"op\": \"replace_method\",\n \"className\": \"SmartReach\",\n \"methodName\": \"HasTarget\",\n \"replacement\": \"public bool HasTarget(){ return currentTarget!=null; }\"\n }],\n \"options\": {\"validate\": \"standard\", \"refresh\": \"immediate\"}\n}\n\n2) Insert a method after another:\n{\n \"name\": \"SmartReach\",\n \"path\": \"Assets/Scripts/Interaction\",\n \"edits\": [{\n \"op\": \"insert_method\",\n \"className\": \"SmartReach\",\n \"replacement\": \"public void PrintSeries(){ Debug.Log(seriesName); }\",\n \"position\": \"after\",\n \"afterMethodName\": \"GetCurrentTarget\"\n }]\n}"
Field Value
| Type | Description |
|---|---|
| string |
Methods
GetOutputSchema()
Returns the output schema for this tool.
Declaration
[McpOutputSchema("Unity.ScriptApplyEdits")]
public static object GetOutputSchema()
Returns
| Type | Description |
|---|---|
| object | The JSON schema object describing the tool's output structure. |
HandleCommand(ScriptApplyEditsParams)
Main handler for structured script edits.
Declaration
[McpTool("Unity.ScriptApplyEdits", "Structured C# edits (methods/classes) with safer boundaries - prefer this over raw text.\n\nBest practices:\n- Prefer anchor_* ops for pattern-based insert/replace near stable markers\n- Use replace_method/delete_method for whole-method changes (keeps signatures balanced)\n- Avoid whole-file regex deletes; validators will guard unbalanced braces\n- For tail insertions, prefer anchor/regex_replace on final brace (class closing)\n- Pass options.validate='standard' for structural checks; 'relaxed' for interior-only edits\n\nCanonical fields (use these exact keys):\n- op: replace_method | insert_method | delete_method | anchor_insert | anchor_delete | anchor_replace\n- className: string (defaults to 'name' if omitted on method/class ops)\n- methodName: string (required for replace_method, delete_method)\n- replacement: string (required for replace_method, insert_method)\n- position: start | end | after | before (insert_method only)\n- afterMethodName / beforeMethodName: string (required when position='after'/'before')\n- anchor: regex string (for anchor_* ops)\n- text: string (for anchor_insert/anchor_replace)\n\nExamples:\n1) Replace a method:\n{\n \"name\": \"SmartReach\",\n \"path\": \"Assets/Scripts/Interaction\",\n \"edits\": [{\n \"op\": \"replace_method\",\n \"className\": \"SmartReach\",\n \"methodName\": \"HasTarget\",\n \"replacement\": \"public bool HasTarget(){ return currentTarget!=null; }\"\n }],\n \"options\": {\"validate\": \"standard\", \"refresh\": \"immediate\"}\n}\n\n2) Insert a method after another:\n{\n \"name\": \"SmartReach\",\n \"path\": \"Assets/Scripts/Interaction\",\n \"edits\": [{\n \"op\": \"insert_method\",\n \"className\": \"SmartReach\",\n \"replacement\": \"public void PrintSeries(){ Debug.Log(seriesName); }\",\n \"position\": \"after\",\n \"afterMethodName\": \"GetCurrentTarget\"\n }]\n}", null, null, Groups = new string[] { "core", "scripting" })]
public static object HandleCommand(ScriptApplyEditsParams parameters)
Parameters
| Type | Name | Description |
|---|---|---|
| ScriptApplyEditsParams | parameters | The parameters specifying the script edits to apply. |
Returns
| Type | Description |
|---|---|
| object | A response object containing success status, message, and optional data. |