Mermaid Diagram Validator
STDIOMCP server that validates and renders Mermaid diagrams for LLMs.
MCP server that validates and renders Mermaid diagrams for LLMs.
A Model Context Protocol server that validates and renders Mermaid diagrams. This server enables LLMs to validate and render Mermaid diagrams.
You can configure your MCP client to use the Mermaid Validator by adding it to your mcp servers file:
{ "mcpServers": { "mermaid-validator": { "command": "npx", "args": [ "-y", "@rtuin/mcp-mermaid-validator@latest" ] } } }
This project is structured as a simple TypeScript Node.js application that:
mcp-mermaid-validator/
├── dist/ # Compiled JavaScript output
│ └── main.js # Compiled main application
├── src/ # TypeScript source code
│ └── main.ts # Main application entry point
├── node_modules/ # Dependencies
├── package.json # Project dependencies and scripts
├── package-lock.json # Dependency lock file
├── tsconfig.json # TypeScript configuration
├── eslint.config.js # ESLint configuration
├── .prettierrc # Prettier configuration
└── README.md # Project documentation
The core functionality is implemented in src/main.ts
. This component:
validateMermaid
tool that accepts Mermaid diagram syntaxPurpose: Validates a Mermaid diagram and returns the rendered PNG if valid
Parameters:
diagram
(string): The Mermaid diagram syntax to validateReturn Value:
{ content: [ { type: "text", text: "Mermaid diagram is valid" }, { type: "image", data: string, // Base64-encoded PNG mimeType: "image/png" } ] }
{ content: [ { type: "text", text: "Mermaid diagram is invalid" }, { type: "text", text: string // Error message }, { type: "text", text: string // Detailed error output (if available) } ] }
MCP Integration: The project uses the Model Context Protocol to standardize the interface for AI tools, allowing seamless integration with compatible clients.
PNG Output Format: The implementation uses PNG as the default output format to ensure better compatibility with most MCP clients, particularly Cursor, which doesn't support SVG.
Child Process Approach: The implementation uses Node.js child processes to interact with the Mermaid CLI, which provides:
Error Handling Strategy: The implementation uses a nested try-catch structure to:
Simple Project Structure: The project uses a straightforward TypeScript project structure for:
The application can be built and run using npm scripts:
# Install dependencies npm install # Build the application npm run build # Run locally (for development) npx @modelcontextprotocol/inspector node dist/main.js # Format code npm run format # Lint code npm run lint # Watch for changes (development) npm run watch
The application runs as an MCP server that communicates via standard input/output, making it suitable for integration with MCP-compatible clients.
To release a new version, the following steps in order:
npm run build
npm run bump
npm run changelog
npm publish --access public