script_create
Generate a new C# script in Unity projects with customizable file names, content, and folder locations using the MCP Server for Unity interface.
Instructions
Create a new C# script in Unity project
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | No | Script content (optional, will use template if not provided) | |
| fileName | Yes | Name of the script file (without .cs extension) | |
| folder | No | Target folder path (default: Assets/Scripts) |
Implementation Reference
- src/tools/unity-mcp-tools.ts:63-84 (registration)Tool registration for 'script_create' including name, description, and input schema definition.{ 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'] } },
- src/tools/unity-mcp-tools.ts:327-338 (handler)Main handler logic in executeTool method that validates arguments and calls the adapter to create the script.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}` }] }; }
- Adapter helper method that performs the HTTP call to Unity server endpoint 'script/create'.async createScript(fileName: string, content?: string, folder?: string): Promise<any> { return this.call('script/create', { fileName, content, folder }); }