Skip to main content
Glama
holyfata

Mermaid-Grammer-Inspector

check

Validate Mermaid diagram syntax to identify and return error messages for invalid diagrams.

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

  • Core handler function for the 'check' tool. Performs input validation, writes the Mermaid diagram text to a temporary file (input.mmd), and invokes 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}`, }; } };
  • src/index.ts:34-52 (registration)
    Registers the MCP tool named 'check' with its description, input schema (Zod), and execute function that wraps checkMermaid.
    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}`; } }, });
  • Zod schema defining the input parameters for the 'check' tool: a single 'text' string.
    parameters: z.object({ text: z.string(), }),
  • Helper function that performs the actual Mermaid syntax check by executing 'npx mmdc' CLI tool on the input file and processing the result or error.
    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 }); }, ); }); };
  • TypeScript interface defining the return type of parsing functions, used for output schema.
    export interface ParseResult { status: ParseStatus; message?: string; }

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

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