Skip to main content
Glama
rahulgarg123

OpenSCAD MCP Server

by rahulgarg123

render_openscad

Convert OpenSCAD 3D modeling code into PNG images using headless rendering. Specify code, output path, and optional camera parameters to generate visualizations without a graphical interface.

Instructions

Render OpenSCAD code to PNG using OpenSCAD in headless mode

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesThe OpenSCAD code to render
output_pathYesPath where the rendered PNG image should be saved
cameraNoCamera parameters: translate_x,y,z,rot_x,y,z,dist or eye_x,y,z,center_x,y,z

Implementation Reference

  • Main handler for the 'render_openscad' tool call. Validates input arguments, invokes the rendering logic, formats the response including success status and output file path.
    private async handleRenderOpenSCAD(args: any): Promise<{ content: Array<{ type: string; text?: string; data?: string; mimeType?: string }> }> {
      try {
        const { code, output_path, camera } = args;
    
        if (!code || typeof code !== 'string') {
          throw new Error('OpenSCAD code is required and must be a string');
        }
    
        if (!output_path || typeof output_path !== 'string') {
          throw new Error('Output path is required and must be a string');
        }
    
        const result = await this.renderOpenSCAD(code, output_path, camera);
    
        // Return text response with file path information
        let responseText = `OpenSCAD rendering ${result.success ? 'completed successfully' : 'failed'}\n\nOutput:\n${result.stdout}${result.stderr ? '\n\nErrors/Warnings:\n' + result.stderr : ''}`;
    
        if (result.success) {
          responseText += `\n\nRendered image saved to: ${output_path}`;
        }
    
        if (result.error) {
          responseText += `\n\nError: ${result.error}`;
        }
    
        return {
          content: [{
            type: 'text',
            text: responseText
          }]
        };
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `Error rendering OpenSCAD: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
        };
      }
    }
  • Core rendering function that executes OpenSCAD binary with provided code, handles temporary files, camera params, and returns rendering result.
    private async renderOpenSCAD(code: string, outputPath: string, camera?: string): Promise<OpenSCADResult> {
      const tempDir = tmpdir();
      const timestamp = Date.now();
      const inputFile = join(tempDir, `openscad_input_${timestamp}.scad`);
    
      try {
        // Write OpenSCAD code to temporary file
        await fs.writeFile(inputFile, code, 'utf8');
    
        // Build command arguments: input file, --render flag, output file
        const args = [inputFile, '--render', '--autocenter', '--viewall','--imgsize=640,480','--backend=manifold', '-o', outputPath];
    
        // Add camera parameters if provided
        if (camera) {
          args.push('--camera', camera);
        }
    
        // Execute OpenSCAD with 10 minute timeout
        const { stdout, stderr } = await execFileAsync(OPENSCAD_BINARY, args, {
          timeout: 600000, // 10 minutes
        });
    
        // Check if output file was created successfully
        const outputExists = await fs.access(outputPath).then(() => true).catch(() => false);
    
        // Clean up temporary input file only
        await this.cleanupFiles([inputFile]);
    
        return {
          stdout: stdout || '',
          stderr: stderr || '',
          success: outputExists,
        };
    
      } catch (error) {
        // Clean up temporary input file even on error
        await this.cleanupFiles([inputFile]);
    
        return {
          stdout: '',
          stderr: '',
          success: false,
          error: error instanceof Error ? error.message : String(error),
        };
      }
    }
  • Input schema defining parameters for the render_openscad tool: code (required string), output_path (required string), camera (optional string).
    inputSchema: {
      type: 'object',
      properties: {
        code: {
          type: 'string',
          description: 'The OpenSCAD code to render',
        },
        output_path: {
          type: 'string',
          description: 'Path where the rendered PNG image should be saved',
        },
        camera: {
          type: 'string',
          description: 'Camera parameters: translate_x,y,z,rot_x,y,z,dist or eye_x,y,z,center_x,y,z',
        },
      },
      required: ['code', 'output_path'],
    },
  • src/index.ts:46-73 (registration)
    Registration of the render_openscad tool in the ListToolsRequestSchema handler, including name, description, and input schema.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          {
            name: 'render_openscad',
            description: 'Render OpenSCAD code to PNG using OpenSCAD in headless mode',
            inputSchema: {
              type: 'object',
              properties: {
                code: {
                  type: 'string',
                  description: 'The OpenSCAD code to render',
                },
                output_path: {
                  type: 'string',
                  description: 'Path where the rendered PNG image should be saved',
                },
                camera: {
                  type: 'string',
                  description: 'Camera parameters: translate_x,y,z,rot_x,y,z,dist or eye_x,y,z,center_x,y,z',
                },
              },
              required: ['code', 'output_path'],
            },
          },
        ],
      };
    });
  • src/index.ts:75-81 (registration)
    Dispatch registration in CallToolRequestSchema handler that routes 'render_openscad' calls to the handleRenderOpenSCAD method.
    this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
      if (request.params.name === 'render_openscad') {
        return await this.handleRenderOpenSCAD(request.params.arguments || {});
      }
      
      throw new Error(`Unknown tool: ${request.params.name}`);
    });
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions 'headless mode', which implies no GUI, but doesn't cover critical aspects like performance (e.g., rendering time, resource usage), error handling, file system interactions, or dependencies. For a tool that generates files and executes code, this is a significant gap in transparency.

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's front-loaded with the core action and includes relevant technical details (headless mode). Every part of the sentence contributes meaning, making it highly concise and well-structured.

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 rendering code to an image file, the lack of annotations, and no output schema, the description is incomplete. It doesn't explain what happens on success (e.g., file creation details) or failure, nor does it cover behavioral traits like side effects or limitations. For a tool with 3 parameters and no structured safety hints, more context is needed.

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 already documents all three parameters (code, output_path, camera) with clear descriptions. The description adds no additional parameter semantics beyond what's in the schema, such as format details or examples. 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 verb ('Render') and resource ('OpenSCAD code to PNG'), specifying the action and output format. It also mentions the execution mode ('using OpenSCAD in headless mode'), which adds useful context. However, with no sibling tools, it doesn't need to differentiate from alternatives, so it doesn't reach the highest score.

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, prerequisites, or constraints. It lacks any context about typical use cases, limitations, or comparisons to other rendering methods. This leaves the agent with minimal usage direction beyond the basic function.

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/rahulgarg123/openscad-mcp'

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