Skip to main content
Glama

compile_mjml

Convert MJML markup to responsive HTML for email templates with options to beautify, minify, validate, and customize output.

Instructions

Compile MJML to HTML with various options

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputYesMJML content or file path
beautifyNoBeautify the output HTML
minifyNoMinify the output HTML
validationLevelNoValidation levelsoft
filePathNoTreat input as file path
keepCommentsNoKeep comments in output
fontsNoCustom fonts configuration
outputPathNoSave compiled HTML to file path

Implementation Reference

  • Main execution logic for compile_mjml tool: parses args with schema, reads input file if needed, compiles MJML to HTML using mjml library with options, handles output saving, logs results and warnings, returns structured response.
    async handleCompileMjml(args) {
      const parsed = CompileMjmlSchema.parse(args);
      log.info('Compiling MJML', { template: parsed.template });
    
      const mjmlContent = await this.readInput(parsed.input, parsed.filePath);
    
      const mjmlOptions = {
        beautify: parsed.beautify,
        minify: parsed.minify,
        validationLevel: parsed.validationLevel,
        keepComments: parsed.keepComments,
        fonts: parsed.fonts || {},
      };
    
      const result = mjml(mjmlContent, mjmlOptions);
    
      if (result.errors.length > 0) {
        log.warn('MJML compilation completed with errors', result.errors);
      } else {
        log.info('MJML compilation successful');
      }
    
      const saveResult = await this.saveOutput(result.html, parsed.outputPath);
    
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify({
              success: true,
              html: result.html,
              errors: result.errors,
              warnings: result.warnings,
              mjmlOptions,
              saved: saveResult,
            }, null, 2),
          },
        ],
      };
    }
  • Zod validation schema defining input parameters for the compile_mjml tool, including MJML input, formatting options, validation level, file handling flags, and output path.
    const CompileMjmlSchema = z.object({
      input: z.string().describe('MJML content or file path'),
      beautify: z.boolean().optional().default(true).describe('Beautify the output HTML'),
      minify: z.boolean().optional().default(false).describe('Minify the output HTML'),
      validationLevel: z.enum(['skip', 'soft', 'strict']).optional().default('soft').describe('Validation level'),
      filePath: z.boolean().optional().default(false).describe('Treat input as file path'),
      keepComments: z.boolean().optional().default(false).describe('Keep comments in output'),
      fonts: z.record(z.string()).optional().describe('Custom fonts configuration'),
      outputPath: z.string().optional().describe('Save compiled HTML to file path'),
    });
  • index.js:137-184 (registration)
    Tool registration in ListToolsRequestHandler: defines name 'compile_mjml', description, and detailed inputSchema matching the Zod schema for MCP protocol compliance.
    {
      name: 'compile_mjml',
      description: 'Compile MJML to HTML with various options',
      inputSchema: {
        type: 'object',
        properties: {
          input: {
            type: 'string',
            description: 'MJML content or file path',
          },
          beautify: {
            type: 'boolean',
            description: 'Beautify the output HTML',
            default: true,
          },
          minify: {
            type: 'boolean',
            description: 'Minify the output HTML',
            default: false,
          },
          validationLevel: {
            type: 'string',
            enum: ['skip', 'soft', 'strict'],
            description: 'Validation level',
            default: 'soft',
          },
          filePath: {
            type: 'boolean',
            description: 'Treat input as file path',
            default: false,
          },
          keepComments: {
            type: 'boolean',
            description: 'Keep comments in output',
            default: false,
          },
          fonts: {
            type: 'object',
            description: 'Custom fonts configuration',
          },
          outputPath: {
            type: 'string',
            description: 'Save compiled HTML to file path',
          },
        },
        required: ['input'],
      },
    },
  • Helper method used by handler to read MJML input from string or file path, with error handling for file access.
    async readInput(input, isFilePath) {
      if (isFilePath) {
        try {
          const fullPath = resolve(input);
          await access(fullPath);
          const content = await readFile(fullPath, 'utf-8');
          log.debug(`Read file: ${fullPath}`);
          return content;
        } catch (error) {
          throw new McpError(
            ErrorCode.InvalidRequest,
            `Failed to read MJML file: ${error.message}`
          );
        }
      }
      return input;
    }
  • Helper method used by handler to optionally save compiled HTML to output file path, returns save status.
    async saveOutput(content, outputPath) {
      if (outputPath) {
        try {
          const fullPath = resolve(outputPath);
          await writeFile(fullPath, content, 'utf-8');
          log.info(`Output saved to: ${fullPath}`);
          return { saved: true, path: fullPath };
        } catch (error) {
          throw new McpError(
            ErrorCode.InternalError,
            `Failed to save output: ${error.message}`
          );
        }
      }
      return { saved: false };
    }
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 action ('Compile') but doesn't describe what happens during compilation (e.g., error handling, performance implications, or output format). It mentions 'various options' but doesn't explain their behavioral impact beyond what the schema covers.

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

Conciseness4/5

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

The description is a single, efficient sentence that front-loads the core purpose. However, it could be more structured by explicitly listing key options or use cases, but it avoids redundancy and wastes no words.

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 (8 parameters, nested objects) and lack of annotations or output schema, the description is insufficient. It doesn't explain the compilation process, error handling, or what the output looks like (e.g., HTML string or file). For a tool with rich parameters and no structured output info, 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 fully documents all 8 parameters. The description adds no additional meaning beyond implying 'various options' exist, which doesn't enhance understanding of individual parameters. The baseline score of 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 verb ('Compile') and resource ('MJML to HTML'), specifying the core transformation. It distinguishes from siblings like 'validate_mjml' (validation) and 'generate_template' (template creation) by focusing on compilation. However, it doesn't explicitly differentiate from 'get_component_info' in terms of resource scope.

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 like 'validate_mjml' for validation or 'generate_template' for template generation. It mentions 'various options' but doesn't specify contexts or prerequisites for choosing this tool over others.

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/shaunie2fly/mjml_mcp'

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