script_apply_diff
Apply unified diffs to C# scripts in Unity projects, supporting previews via dry-run mode. Integrates with the MCP Server for efficient script updates and version control.
Instructions
Apply a unified diff to a C# script
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| diff | Yes | Unified diff content to apply | |
| options | No | Optional diff application settings | |
| path | Yes | Path to the script file |
Implementation Reference
- src/tools/unity-mcp-tools.ts:366-377 (handler)Handler for the 'script_apply_diff' MCP tool. Validates input arguments and delegates to UnityHttpAdapter.applyDiff, then formats the response.case 'script_apply_diff': { if (!args.path || !args.diff) { throw new Error('path and diff are required'); } const result = await this.adapter.applyDiff(args.path, args.diff, args.options); return { content: [{ type: 'text', text: `Diff applied successfully:\nPath: ${result.path}\nLines added: ${result.linesAdded}\nLines removed: ${result.linesRemoved}` }] }; }
- src/tools/unity-mcp-tools.ts:113-140 (registration)Tool registration in getTools() array, defining name, description, and input schema for 'script_apply_diff'.{ name: 'script_apply_diff', description: 'Apply a unified diff to a C# script', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to the script file' }, diff: { type: 'string', description: 'Unified diff content to apply' }, options: { type: 'object', description: 'Optional diff application settings', properties: { dryRun: { type: 'boolean', description: 'Preview changes without applying (default: false)' } } } }, required: ['path', 'diff'] } },
- Supporting method in UnityHttpAdapter that makes an HTTP call to the Unity server endpoint '/script/applyDiff' to perform the diff application.async applyDiff(path: string, diff: string, options?: any): Promise<any> { return this.call('script/applyDiff', { path, diff, options });