Skip to main content
Glama

create_scene

Generate a new Godot scene file by specifying the project path, scene path, and root node type to streamline game development workflows with the Godot MCP server.

Instructions

Create a new Godot scene file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectPathYesPath to the Godot project directory
rootNodeTypeNoType of the root node (e.g., Node2D, Node3D)Node2D
scenePathYesPath where the scene file will be saved (relative to project)

Implementation Reference

  • src/index.ts:761-782 (registration)
    Tool registration in the list of available tools for ListToolsRequestSchema, including name, description, and input schema.
    name: 'create_scene', description: 'Create a new Godot scene file', inputSchema: { type: 'object', properties: { projectPath: { type: 'string', description: 'Path to the Godot project directory', }, scenePath: { type: 'string', description: 'Path where the scene file will be saved (relative to project)', }, rootNodeType: { type: 'string', description: 'Type of the root node (e.g., Node2D, Node3D)', default: 'Node2D', }, }, required: ['projectPath', 'scenePath'], }, },
  • src/index.ts:948-949 (registration)
    Registration of the tool handler in the CallToolRequestSchema switch statement.
    case 'create_scene': return await this.handleCreateScene(request.params.arguments);
  • The main handler function for the 'create_scene' tool. Validates input parameters, checks project validity, prepares parameters, executes the Godot operation via executeOperation('create_scene'), and handles the response or errors.
    private async handleCreateScene(args: any) { // Normalize parameters to camelCase args = this.normalizeParameters(args); if (!args.projectPath || !args.scenePath) { return this.createErrorResponse( 'Project path and scene path are required', ['Provide valid paths for both the project and the scene'] ); } if (!this.validatePath(args.projectPath) || !this.validatePath(args.scenePath)) { return this.createErrorResponse( 'Invalid path', ['Provide valid paths without ".." or other potentially unsafe characters'] ); } try { // Check if the project directory exists and contains a project.godot file const projectFile = join(args.projectPath, 'project.godot'); if (!existsSync(projectFile)) { return this.createErrorResponse( `Not a valid Godot project: ${args.projectPath}`, [ 'Ensure the path points to a directory containing a project.godot file', 'Use list_projects to find valid Godot projects', ] ); } // Prepare parameters for the operation (already in camelCase) const params = { scenePath: args.scenePath, rootNodeType: args.rootNodeType || 'Node2D', }; // Execute the operation const { stdout, stderr } = await this.executeOperation('create_scene', params, args.projectPath); if (stderr && stderr.includes('Failed to')) { return this.createErrorResponse( `Failed to create scene: ${stderr}`, [ 'Check if the root node type is valid', 'Ensure you have write permissions to the scene path', 'Verify the scene path is valid', ] ); } return { content: [ { type: 'text', text: `Scene created successfully at: ${args.scenePath}\n\nOutput: ${stdout}`, }, ], }; } catch (error: any) { return this.createErrorResponse( `Failed to create scene: ${error?.message || 'Unknown error'}`, [ 'Ensure Godot is installed correctly', 'Check if the GODOT_PATH environment variable is set correctly', 'Verify the project path is accessible', ] ); } }
  • Helper method that executes Godot operations by spawning Godot with the operations script (godot_operations.gd) and passing the operation name and JSON parameters. This is where the actual 'create_scene' logic in Godot GDscript is invoked.
    private async executeOperation( operation: string, params: OperationParams, projectPath: string ): Promise<{ stdout: string; stderr: string }> { this.logDebug(`Executing operation: ${operation} in project: ${projectPath}`); this.logDebug(`Original operation params: ${JSON.stringify(params)}`); // Convert camelCase parameters to snake_case for Godot script const snakeCaseParams = this.convertCamelToSnakeCase(params); this.logDebug(`Converted snake_case params: ${JSON.stringify(snakeCaseParams)}`); // Ensure godotPath is set if (!this.godotPath) { await this.detectGodotPath(); if (!this.godotPath) { throw new Error('Could not find a valid Godot executable path'); } } try { // Serialize the snake_case parameters to a valid JSON string const paramsJson = JSON.stringify(snakeCaseParams); // Escape single quotes in the JSON string to prevent command injection const escapedParams = paramsJson.replace(/'/g, "'\\''"); // On Windows, cmd.exe does not strip single quotes, so we use // double quotes and escape them to ensure the JSON is parsed // correctly by Godot. const isWindows = process.platform === 'win32'; const quotedParams = isWindows ? `\"${paramsJson.replace(/\"/g, '\\"')}\"` : `'${escapedParams}'`; // Add debug arguments if debug mode is enabled const debugArgs = GODOT_DEBUG_MODE ? ['--debug-godot'] : []; // Construct the command with the operation and JSON parameters const cmd = [ `"${this.godotPath}"`, '--headless', '--path', `"${projectPath}"`, '--script', `"${this.operationsScriptPath}"`, operation, quotedParams, // Pass the JSON string as a single argument ...debugArgs, ].join(' '); this.logDebug(`Command: ${cmd}`); const { stdout, stderr } = await execAsync(cmd); return { stdout, stderr }; } catch (error: unknown) { // If execAsync throws, it still contains stdout/stderr if (error instanceof Error && 'stdout' in error && 'stderr' in error) { const execError = error as Error & { stdout: string; stderr: string }; return { stdout: execError.stdout, stderr: execError.stderr, }; } throw error; } }
  • Sets the path to the GDscript file (godot_operations.gd) that contains the actual implementation logic for operations including 'create_scene'.
    this.operationsScriptPath = join(__dirname, 'scripts', 'godot_operations.gd');

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Coding-Solo/godot-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server