Skip to main content
Glama

validate_template

Check NoJS HTML templates for syntax errors, unknown directives, and adherence to best practices to ensure proper functionality.

Instructions

Validate a NoJS HTML template for syntax errors, unknown directives, and best practices

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
htmlYesThe HTML template to validate

Implementation Reference

  • The handler function that validates the NoJS template for syntax, common errors, and best practices.
    async ({ html }) => {
        const errors: string[] = [];
        const warnings: string[] = [];
        const knownDirectives = getDirectiveNames();
    
        // Extract all attributes from HTML
        const attrRegex = /\s([a-z][a-z0-9\-:]*?)(?:=|[\s>])/gi;
        const attrs = new Set<string>();
        let match: RegExpExecArray | null;
        while ((match = attrRegex.exec(html)) !== null) {
            attrs.add(match[1].toLowerCase());
        }
    
        // Check for potential NoJS directive typos
        const possibleTypos: Record<string, string> = {
            bnd: "bind",
            bing: "bind",
            binde: "bind",
            "bind-htm": "bind-html",
            iff: "if",
            els: "else",
            "else-iff": "else-if",
            shw: "show",
            hid: "hide",
            ech: "each",
            forech: "foreach",
            modle: "model",
            stat: "state",
            stor: "store",
            rout: "route",
            "route-vew": "route-view",
            validat: "validate",
            animat: "animate",
            "on-click": "on:click",
            "on-submit": "on:submit",
            "on-input": "on:input",
        };
    
        for (const attr of attrs) {
            if (possibleTypos[attr]) {
                errors.push(
                    `Unknown attribute "${attr}" — did you mean "${possibleTypos[attr]}"?`
                );
            }
        }
    
        // Check for each without "in" keyword
        const eachRegex = /each="([^"]+)"/g;
        while ((match = eachRegex.exec(html)) !== null) {
            if (!match[1].includes(" in ")) {
                errors.push(
                    `Invalid "each" syntax: "${match[1]}" — expected format: "item in items"`
                );
            }
        }
    
        // Check foreach without from
        if (html.includes("foreach=") && !html.includes("from=")) {
            errors.push(
                `"foreach" directive requires a "from" attribute to specify the source array`
            );
        }
    
        // Check for deprecated syntax
        if (html.includes('mode="hash"') || html.includes("mode=\"history\"")) {
            warnings.push(
                `Deprecated: router "mode" option. Use "useHash: true" instead of "mode: 'hash'"`
            );
        }
    
        // Check model on non-input elements
        const modelOnDivRegex =
            /<(div|span|p|h[1-6]|section|article|main|header|footer)\s[^>]*model=/gi;
        while ((match = modelOnDivRegex.exec(html)) !== null) {
            warnings.push(
                `"model" directive on <${match[1]}> — "model" is designed for form inputs (<input>, <select>, <textarea>)`
            );
        }
    
        // Check bind-html without sanitization warning
        if (html.includes("bind-html=")) {
            warnings.push(
                `"bind-html" renders raw HTML. Ensure the content is sanitized to prevent XSS.`
            );
        }
    
        // Check for on: events without correct syntax
        const onRegex = /on:([a-z]+)\.([a-z.]+)/gi;
        const validModifiers = new Set([
            "prevent",
            "stop",
            "once",
            "self",
            "enter",
            "escape",
            "tab",
            "space",
            "up",
            "down",
            "left",
            "right",
            "ctrl",
            "alt",
            "shift",
            "meta",
        ]);
        while ((match = onRegex.exec(html)) !== null) {
            const mods = match[2].split(".");
            for (const mod of mods) {
                if (!validModifiers.has(mod)) {
                    warnings.push(
                        `Unknown event modifier ".${mod}" on "on:${match[1]}" — valid modifiers: ${[...validModifiers].join(", ")}`
                    );
                }
            }
        }
    
        const valid = errors.length === 0;
    
        let summary = valid
            ? "✅ Template is valid."
            : `❌ Found ${errors.length} error(s).`;
        if (warnings.length > 0) {
            summary += ` ${warnings.length} warning(s).`;
        }
    
        return {
            content: [
                {
                    type: "text" as const,
                    text: JSON.stringify({ valid, errors, warnings, summary }, null, 2),
                },
            ],
        };
    }
  • Tool registration for validate_template in src/tools/index.ts
    server.tool(
        "validate_template",
        "Validate a NoJS HTML template for syntax errors, unknown directives, and best practices",
        { html: z.string().describe("The HTML template to validate") },
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 what the tool validates (syntax errors, unknown directives, best practices) but doesn't describe the output format, error reporting details, or any behavioral traits like performance implications or validation scope. This leaves significant gaps in understanding how the tool behaves in practice.

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 front-loads the core purpose without any wasted words. It directly states what the tool does, making it easy to parse and understand quickly. Every part of the sentence earns its place by specifying the action, target, and validation aspects.

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 lack of annotations and output schema, the description is incomplete for a validation tool. It doesn't explain what the output looks like (e.g., error list, success status), how results are structured, or any behavioral nuances. For a tool that likely returns validation results, this omission makes it inadequate for the agent to fully understand the tool's context and 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?

The input schema has 100% description coverage, with the single parameter 'html' clearly documented as 'The HTML template to validate'. The description doesn't add any meaning beyond this, such as formatting examples or constraints. Since the schema does the heavy lifting, the baseline score of 3 is appropriate, as the description doesn't compensate but also doesn't detract.

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: validating a NoJS HTML template for syntax errors, unknown directives, and best practices. It specifies the verb 'validate' and the resource 'NoJS HTML template', making it easy to understand what the tool does. However, it doesn't explicitly differentiate from sibling tools like 'explain_directive' or 'list_directives', which prevents 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. It doesn't mention prerequisites, when not to use it, or how it relates to sibling tools like 'explain_directive' (which might explain errors) or 'list_directives' (which might list valid directives). This lack of context leaves the agent without clear usage instructions.

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/ErickXavier/nojs-mcp'

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