script_create
Create new C# scripts in Unity projects with customizable file names, content, and folder locations to streamline development workflows.
Instructions
Create a new C# script in Unity project
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fileName | Yes | Name of the script file (without .cs extension) | |
| content | No | Script content (optional, will use template if not provided) | |
| folder | No | Target folder path (default: Assets/Scripts) |
Implementation Reference
- src/tools/unity-mcp-tools.ts:327-338 (handler)Handler function for the 'script_create' tool. Validates required 'fileName' parameter and delegates to UnityHttpAdapter.createScript, returning success message with path and GUID.case 'script_create': { if (!args.fileName) { throw new Error('fileName is required'); } const result = await this.adapter.createScript(args.fileName, args.content, args.folder); return { content: [{ type: 'text', text: `Script created successfully:\nPath: ${result.path}\nGUID: ${result.guid}` }] }; }
- src/tools/unity-mcp-tools.ts:66-82 (schema)Input schema defining parameters for script_create: required fileName, optional content and folder.inputSchema: { type: 'object', properties: { fileName: { type: 'string', description: 'Name of the script file (without .cs extension)' }, content: { type: 'string', description: 'Script content (optional, will use template if not provided)' }, folder: { type: 'string', description: 'Target folder path (default: Assets/Scripts)' } }, required: ['fileName']
- src/tools/unity-mcp-tools.ts:63-84 (registration)Tool registration in getTools() array, including name, description, and schema.{ name: 'script_create', description: 'Create a new C# script in Unity project', inputSchema: { type: 'object', properties: { fileName: { type: 'string', description: 'Name of the script file (without .cs extension)' }, content: { type: 'string', description: 'Script content (optional, will use template if not provided)' }, folder: { type: 'string', description: 'Target folder path (default: Assets/Scripts)' } }, required: ['fileName'] } },
- Helper method in adapter that sends HTTP request to Unity server endpoint 'script/create' with parameters.async createScript(fileName: string, content?: string, folder?: string): Promise<any> { return this.call('script/create', { fileName, content, folder }); }