Skip to main content
Glama
betterhyq

Mermaid-Grammer-Inspector

check

Validate Mermaid diagram syntax. Returns empty string for valid diagrams, error message for invalid.

Instructions

Check if the text is a valid mermaid diagram. Returns an empty string if valid, otherwise returns the error message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYes

Implementation Reference

  • src/index.ts:34-52 (registration)
    Registration of the 'check' tool via server.addTool, with its name, description, Zod schema, and execute handler
    server.addTool({
    	name: "check",
    	description:
    		"Check if the text is a valid mermaid diagram. Returns an empty string if valid, otherwise returns the error message.",
    	parameters: z.object({
    		text: z.string(),
    	}),
    	execute: async (args) => {
    		try {
    			const { status, message } = await checkMermaid(args.text);
    			return status === ParseStatus.SUCCESS ? "" : message || "Unknown error";
    		} catch (error) {
    			const errorMessage =
    				error instanceof Error ? error.message : "Unexpected error occurred";
    			console.error("Error in check tool:", errorMessage);
    			return `Internal error: ${errorMessage}`;
    		}
    	},
    });
  • Input schema for the 'check' tool using Zod: accepts a single string parameter 'text'
    parameters: z.object({
    	text: z.string(),
    }),
  • Handler function 'checkMermaid' that validates input, writes text to a temp file, and calls parseMermaid to check syntax
    export const checkMermaid = async (text: string): Promise<ParseResult> => {
    	// Input validation
    	if (typeof text !== "string") {
    		return {
    			status: ParseStatus.FAIL,
    			message: "Input must be a string",
    		};
    	}
    
    	// Check for empty or whitespace-only content
    	if (!text.trim()) {
    		return {
    			status: ParseStatus.FAIL,
    			message: "Input cannot be empty or contain only whitespace",
    		};
    	}
    
    	const inputFilePath = path.join(__dirname, "input.mmd");
    
    	try {
    		fs.writeFileSync(inputFilePath, text, { encoding: "utf-8" });
    		return await parseMermaid();
    	} catch (error) {
    		const errorMessage =
    			error instanceof Error ? error.message : "File write failed";
    		return {
    			status: ParseStatus.FAIL,
    			message: `Unable to write temporary file: ${errorMessage}`,
    		};
    	}
    };
  • Inline execute handler that calls checkMermaid and maps ParseResult to a response string
    execute: async (args) => {
    	try {
    		const { status, message } = await checkMermaid(args.text);
    		return status === ParseStatus.SUCCESS ? "" : message || "Unknown error";
    	} catch (error) {
    		const errorMessage =
    			error instanceof Error ? error.message : "Unexpected error occurred";
    		console.error("Error in check tool:", errorMessage);
    		return `Internal error: ${errorMessage}`;
    	}
    },
  • Helper function 'parseMermaid' that runs the mmdc CLI tool to validate Mermaid syntax
    export const parseMermaid = (
    	inputFile: string = "input.mmd",
    	outputFile: string = "output.svg",
    ): Promise<ParseResult> => {
    	return new Promise((resolve) => {
    		const inputPath = path.join(__dirname, inputFile);
    		const outputPath = path.join(__dirname, outputFile);
    
    		exec(
    			`npx mmdc -i ${inputPath} -o ${outputPath}`,
    			(err, _stdout, stderr) => {
    				if (err) {
    					const errorOutput = stderr || err.message || "";
    					const filteredMessage = filterErrorOutput(errorOutput);
    					resolve({
    						status: ParseStatus.FAIL,
    						message: filteredMessage || err.message || "Unknown error",
    					});
    					return;
    				}
    
    				resolve({ status: ParseStatus.SUCCESS });
    			},
    		);
    	});
    };
Behavior4/5

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

The description discloses the return behavior: empty string for valid, error message for invalid. This is clear and no annotations exist to contradict. It does not mention side effects, but for a read-only check, this is adequate.

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 sentence that efficiently communicates the tool's function and output. Every word contributes meaning, and the key information is front-loaded.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple validation tool with one parameter and no output schema, the description fully covers the purpose, input requirements, and return format. No additional context is necessary.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema only specifies 'text' as a string with no description. The tool description adds that the text should be a mermaid diagram, providing crucial context beyond the schema. This compensates for the 0% schema description coverage.

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 checks if text is a valid mermaid diagram. It uses a specific verb and resource, and while it could be more precise about what constitutes validity, it is sufficient for an AI agent to understand the core purpose.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit when-to-use or when-not-to-use guidance is provided. Since there are no sibling tools, the need for differentiation is minimal, but the description does not offer context on when this tool is appropriate compared to other potential validation approaches.

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/betterhyq/Mermaid-Grammer-Inspector'

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