Skip to main content
Glama

export_mesh_library

Export Godot scenes as reusable MeshLibrary resources for efficient 3D asset management and scene composition.

Instructions

Export a scene as a MeshLibrary resource

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectPathYesPath to the Godot project directory
scenePathYesPath to the scene file (.tscn) to export
outputPathYesPath where the mesh library (.res) will be saved
meshItemNamesNoOptional: Names of specific mesh items to include (defaults to all)

Implementation Reference

  • The primary handler for the 'export_mesh_library' tool. It normalizes input arguments, validates paths and parameters, prepares the params, calls executeOperation with the 'export_mesh_library' operation on the Godot script, and handles the response or errors.
    private async handleExportMeshLibrary(args: any) {
      // Normalize parameters to camelCase
      args = this.normalizeParameters(args);
      
      if (!args.projectPath || !args.scenePath || !args.outputPath) {
        return this.createErrorResponse(
          'Missing required parameters',
          ['Provide projectPath, scenePath, and outputPath']
        );
      }
    
      if (
        !this.validatePath(args.projectPath) ||
        !this.validatePath(args.scenePath) ||
        !this.validatePath(args.outputPath)
      ) {
        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',
            ]
          );
        }
    
        // 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,
          outputPath: args.outputPath,
        };
    
        // Add optional parameters
        if (args.meshItemNames && Array.isArray(args.meshItemNames)) {
          params.meshItemNames = args.meshItemNames;
        }
    
        // Execute the operation
        const { stdout, stderr } = await this.executeOperation('export_mesh_library', params, args.projectPath);
    
        if (stderr && stderr.includes('Failed to')) {
          return this.createErrorResponse(
            `Failed to export mesh library: ${stderr}`,
            [
              'Check if the scene contains valid 3D meshes',
              'Ensure the output path is valid',
              'Verify the scene file is valid',
            ]
          );
        }
    
        return {
          content: [
            {
              type: 'text',
              text: `MeshLibrary exported successfully to: ${args.outputPath}\n\nOutput: ${stdout}`,
            },
          ],
        };
      } catch (error: any) {
        return this.createErrorResponse(
          `Failed to export mesh library: ${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 for the 'export_mesh_library' tool, defining required parameters (projectPath, scenePath, outputPath) and optional meshItemNames array.
    inputSchema: {
      type: 'object',
      properties: {
        projectPath: {
          type: 'string',
          description: 'Path to the Godot project directory',
        },
        scenePath: {
          type: 'string',
          description: 'Path to the scene file (.tscn) to export',
        },
        outputPath: {
          type: 'string',
          description: 'Path where the mesh library (.res) will be saved',
        },
        meshItemNames: {
          type: 'array',
          items: {
            type: 'string',
          },
          description: 'Optional: Names of specific mesh items to include (defaults to all)',
        },
      },
      required: ['projectPath', 'scenePath', 'outputPath'],
  • src/index.ts:844-872 (registration)
    Tool registration in the list of available tools returned by ListToolsRequestSchema, specifying name, description, and input schema.
    {
      name: 'export_mesh_library',
      description: 'Export a scene as a MeshLibrary resource',
      inputSchema: {
        type: 'object',
        properties: {
          projectPath: {
            type: 'string',
            description: 'Path to the Godot project directory',
          },
          scenePath: {
            type: 'string',
            description: 'Path to the scene file (.tscn) to export',
          },
          outputPath: {
            type: 'string',
            description: 'Path where the mesh library (.res) will be saved',
          },
          meshItemNames: {
            type: 'array',
            items: {
              type: 'string',
            },
            description: 'Optional: Names of specific mesh items to include (defaults to all)',
          },
        },
        required: ['projectPath', 'scenePath', 'outputPath'],
      },
    },
  • src/index.ts:954-955 (registration)
    Registration of the tool handler in the CallToolRequestSchema switch statement, mapping the tool name to its handler method.
    case 'export_mesh_library':
      return await this.handleExportMeshLibrary(request.params.arguments);
  • General helper method used by all scene manipulation tools, including export_mesh_library, to execute specific operations on a Godot operations script (godot_operations.gd). It serializes params as JSON, escapes for shell, and runs Godot headless with the script and operation name.
    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. It states the tool exports a scene but lacks details on permissions, side effects (e.g., file system changes), error handling, or output format. This is insufficient for a tool that likely modifies files, risking misuse by an agent.

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 that directly states the tool's purpose without unnecessary words. It is front-loaded and wastes no space, making it easy to parse quickly.

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 complexity of exporting a scene (likely involving file I/O and resource conversion), no annotations, and no output schema, the description is incomplete. It doesn't cover behavioral aspects like success/failure responses or constraints, leaving gaps that could hinder an agent's ability to use the tool effectively.

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?

The input schema has 100% description coverage, clearly documenting all four parameters. The description adds no additional parameter semantics beyond the schema, such as explaining the relationship between 'scenePath' and 'outputPath' or clarifying 'meshItemNames' usage. Baseline 3 is appropriate since 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 ('Export') and resource ('scene as a MeshLibrary resource'), making the purpose understandable. However, it doesn't differentiate this tool from sibling tools like 'save_scene' or 'create_scene', which might handle similar scene-related operations, leaving room for potential confusion.

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, such as needing a valid Godot project or scene, or specify scenarios where exporting as a MeshLibrary is preferred over other operations like saving or creating scenes, leaving usage context unclear.

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/Zycroft/godot-mcp'

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