Skip to main content
Glama

save_scene

Save modifications to Godot scene files, enabling version control and scene variant creation within projects.

Instructions

Save changes to a scene file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectPathYesPath to the Godot project directory
scenePathYesPath to the scene file (relative to project)
newPathNoOptional: New path to save the scene to (for creating variants)

Implementation Reference

  • Handler function for the 'save_scene' tool. Validates inputs (projectPath, scenePath, optional newPath), checks project and scene existence, prepares parameters, executes the Godot operation via executeOperation('save_scene'), handles errors and returns success message with output.
    private async handleSaveScene(args: any) {
      // Normalize parameters to camelCase
      args = this.normalizeParameters(args);
      
      if (!args.projectPath || !args.scenePath) {
        return this.createErrorResponse(
          'Missing required parameters',
          ['Provide projectPath and scenePath']
        );
      }
    
      if (!this.validatePath(args.projectPath) || !this.validatePath(args.scenePath)) {
        return this.createErrorResponse(
          'Invalid path',
          ['Provide valid paths without ".." or other potentially unsafe characters']
        );
      }
    
      // If newPath is provided, validate it
      if (args.newPath && !this.validatePath(args.newPath)) {
        return this.createErrorResponse(
          'Invalid new path',
          ['Provide a valid new path 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',
            ]
          );
        }
    
        // Check if the scene file exists
        const scenePath = join(args.projectPath, args.scenePath);
        if (!existsSync(scenePath)) {
          return this.createErrorResponse(
            `Scene file does not exist: ${args.scenePath}`,
            [
              'Ensure the scene path is correct',
              'Use create_scene to create a new scene first',
            ]
          );
        }
    
        // Prepare parameters for the operation (already in camelCase)
        const params: any = {
          scenePath: args.scenePath,
        };
    
        // Add optional parameters
        if (args.newPath) {
          params.newPath = args.newPath;
        }
    
        // Execute the operation
        const { stdout, stderr } = await this.executeOperation('save_scene', params, args.projectPath);
    
        if (stderr && stderr.includes('Failed to')) {
          return this.createErrorResponse(
            `Failed to save scene: ${stderr}`,
            [
              'Check if the scene file is valid',
              'Ensure you have write permissions to the output path',
              'Verify the scene can be properly packed',
            ]
          );
        }
    
        const savePath = args.newPath || args.scenePath;
        return {
          content: [
            {
              type: 'text',
              text: `Scene saved successfully to: ${savePath}\n\nOutput: ${stdout}`,
            },
          ],
        };
      } catch (error: any) {
        return this.createErrorResponse(
          `Failed to save 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',
          ]
        );
      }
    }
  • Input schema definition for the 'save_scene' tool, specifying required projectPath and scenePath, optional newPath.
    type: 'object',
    properties: {
      projectPath: {
        type: 'string',
        description: 'Path to the Godot project directory',
      },
      scenePath: {
        type: 'string',
        description: 'Path to the scene file (relative to project)',
      },
      newPath: {
        type: 'string',
        description: 'Optional: New path to save the scene to (for creating variants)',
      },
    },
    required: ['projectPath', 'scenePath'],
  • src/index.ts:956-957 (registration)
    Registration of the 'save_scene' handler in the CallToolRequestSchema switch statement.
    case 'save_scene':
      return await this.handleSaveScene(request.params.arguments);
  • src/index.ts:874-894 (registration)
    Tool registration in the ListToolsRequestSchema response, including name, description, and input schema.
      name: 'save_scene',
      description: 'Save changes to a scene file',
      inputSchema: {
        type: 'object',
        properties: {
          projectPath: {
            type: 'string',
            description: 'Path to the Godot project directory',
          },
          scenePath: {
            type: 'string',
            description: 'Path to the scene file (relative to project)',
          },
          newPath: {
            type: 'string',
            description: 'Optional: New path to save the scene to (for creating variants)',
          },
        },
        required: ['projectPath', 'scenePath'],
      },
    },
  • Helper function that executes Godot operations by spawning Godot with the operations script (godot_operations.gd) and the specific operation name ('save_scene') along with JSON parameters. This is the bridge to the actual Godot-side implementation.
    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;
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. 'Save changes' implies a write operation, but it doesn't specify whether this overwrites existing files, requires specific permissions, has side effects (e.g., locking files), or handles errors. For a mutation tool with zero annotation coverage, this leaves critical behavioral traits undocumented.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero wasted words. It's front-loaded with the core action ('Save changes'), making it immediately scannable. Every word earns its place by conveying essential purpose without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (mutation operation with 3 parameters) and lack of annotations and output schema, the description is incomplete. It doesn't address behavioral risks, return values, or error conditions. For a write tool in a development environment, more context is needed to ensure safe and correct usage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all three parameters (projectPath, scenePath, newPath). The description adds no additional parameter semantics beyond what's in the schema, such as explaining the relationship between scenePath and newPath for variants. Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Save changes') and resource ('to a scene file'), making the tool's purpose immediately understandable. It distinguishes from siblings like 'create_scene' (new creation) and 'export_mesh_library' (different resource type). However, it doesn't explicitly differentiate from all potential save operations in the sibling set.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing an existing scene), exclusions, or relationships with siblings like 'create_scene' for new scenes or 'update_project_uids' for other modifications. The agent must infer usage from the name alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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