Skip to main content
Glama

generate_matlab_code

Generate MATLAB code from natural language descriptions to automate script creation and execution tasks.

Instructions

Generate MATLAB code from a natural language description

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
descriptionYesNatural language description of what the code should do
saveScriptNoWhether to save the generated MATLAB script
scriptPathNoCustom path to save the MATLAB script (optional)

Implementation Reference

  • MCP tool handler for 'generate_matlab_code': extracts parameters, calls generateCode helper, formats response with code block, optionally saves script to file.
    case 'generate_matlab_code': {
      const description = String(request.params.arguments?.description || '');
      const saveScript = Boolean(request.params.arguments?.saveScript || false);
      const scriptPath = request.params.arguments?.scriptPath as string | undefined;
      
      if (!description) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Description is required'
        );
      }
      
      try {
        const generatedCode = this.matlabHandler.generateCode(description);
        
        let responseText = `Generated MATLAB code for: "${description}"\n\n\`\`\`matlab\n${generatedCode}\n\`\`\``;
        
        // Save the generated code if requested
        if (saveScript) {
          const targetPath = scriptPath || path.join(process.cwd(), `matlab_generated_${Date.now()}.m`);
          fs.writeFileSync(targetPath, generatedCode);
          responseText += `\n\nGenerated MATLAB script saved to: ${targetPath}`;
        }
        
        return {
          content: [
            {
              type: 'text',
              text: responseText,
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `Error generating MATLAB code: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
          isError: true,
        };
      }
    }
  • Core implementation of code generation: returns a placeholder MATLAB function template based on the input description. Notes it should use LLM in real impl.
      generateCode(description: string): string {
        // This is a placeholder. In a real implementation, this would use an LLM or other method
        // to generate MATLAB code from the description.
        // For now, we'll return a simple template based on the description.
        
        return `% MATLAB code generated from description: ${description}
    % Generated on: ${new Date().toISOString()}
    
    % Your code here:
    % This is a placeholder implementation.
    % In a real system, this would be generated based on the description.
    
    function result = generatedFunction()
        % Based on description: ${description}
        disp('Executing function based on description: ${description}');
        
        % Placeholder implementation
        result = 'Function executed successfully';
    end
    
    % Call the function
    generatedFunction()`;
      }
  • src/index.ts:313-335 (registration)
    Tool registration in listTools handler: defines name, description, and input schema including optional save options.
      {
        name: 'generate_matlab_code',
        description: 'Generate MATLAB code from a natural language description',
        inputSchema: {
          type: 'object',
          properties: {
            description: {
              type: 'string',
              description: 'Natural language description of what the code should do',
            },
            saveScript: {
              type: 'boolean',
              description: 'Whether to save the generated MATLAB script',
            },
            scriptPath: {
              type: 'string',
              description: 'Custom path to save the MATLAB script (optional)',
            },
          },
          required: ['description'],
        },
      },
    ],
  • Input schema for generate_matlab_code tool: requires description, optional saveScript and scriptPath.
    inputSchema: {
      type: 'object',
      properties: {
        description: {
          type: 'string',
          description: 'Natural language description of what the code should do',
        },
        saveScript: {
          type: 'boolean',
          description: 'Whether to save the generated MATLAB script',
        },
        scriptPath: {
          type: 'string',
          description: 'Custom path to save the MATLAB script (optional)',
        },
      },
      required: ['description'],
    },
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 states what the tool does but lacks critical behavioral details: it doesn't mention whether the generated code is saved by default, what format or quality the output is in, any limitations (e.g., complexity, length), or error handling. For a code generation tool with zero annotation coverage, this is a significant gap.

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, clear sentence with zero waste. It's front-loaded with the core purpose and appropriately sized for a straightforward tool. Every word earns its place, making it highly efficient.

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 code generation (a non-trivial task), lack of annotations, and no output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., code string, file path, errors), any constraints on the input description, or how the saveScript and scriptPath parameters interact. The agent is left with significant gaps in understanding the tool's behavior and output.

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 (description, saveScript, scriptPath) with clear descriptions. The tool description adds no parameter-specific information beyond what's in the schema. According to the rules, with high schema coverage (>80%), the baseline is 3 even with no param info in the description.

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 tool's purpose: 'Generate MATLAB code from a natural language description.' It specifies the verb ('generate'), resource ('MATLAB code'), and input source ('natural language description'). However, it doesn't explicitly differentiate from its sibling tool 'execute_matlab_code' (which runs code vs. generating it), so it falls short of a perfect 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. There's no mention of the sibling tool 'execute_matlab_code' or any other context for choosing between generating code and executing it. The agent must infer usage from the tool name alone, which is insufficient.

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/WilliamCloudQi/matlab-mcp-server'

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