
Mermaid Validator
Validates Mermaid diagram syntax and renders them as SVG images, providing detailed error messages when diagrams are invalid.
Validates and renders Mermaid diagrams as SVG images, providing detailed error messages for invalid syntax to enhance visualization capabilities within conversations.
What it does
- Validate Mermaid diagram syntax
- Render valid diagrams as SVG images
- Generate detailed error messages for invalid syntax
- Process various Mermaid diagram types
Best for
About Mermaid Validator
Mermaid Validator is a community-built MCP server published by rtuin that provides AI assistants with tools and capabilities via the Model Context Protocol. Validate and render Mermaid diagrams as SVG images using Mermaid JS. Get clear error messages to improve your JavaScript It is categorized under developer tools.
How to install
You can install Mermaid Validator in your AI client of choice. Use the install panel on this page to get one-click setup for Cursor, Claude Desktop, VS Code, and other MCP-compatible clients. This server runs locally on your machine via the stdio transport.
License
Mermaid Validator is released under the MIT license. This is a permissive open-source license, meaning you can freely use, modify, and distribute the software.
MCP Server: Mermaid Validator
A Model Context Protocol server that validates and renders Mermaid diagrams. This server enables LLMs to validate and render Mermaid diagrams.
Usage
Quick Start
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"
]
}
}
}
Architecture
High-Level Architecture
This project is structured as a simple TypeScript Node.js application that:
- Main Application: A Node.js service that validates Mermaid diagrams and returns rendered PNG output
- MCP Integration: Uses the Model Context Protocol SDK to expose functionality to MCP-compatible clients
- Mermaid CLI Integration: Leverages the Mermaid CLI tool to perform diagram validation and rendering
Code Structure
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
Component Functionality
MCP Server (Main Component)
The core functionality is implemented in src/main.ts. This component:
- Creates an MCP server instance
- Registers a
validateMermaidtool that accepts Mermaid diagram syntax - Uses the Mermaid CLI to validate and render diagrams
- Returns validation results and rendered PNG (if valid)
- Handles error cases with appropriate error messages
Data Flow
- Input: Mermaid diagram syntax as a string
- Processing:
- The diagram is passed to the Mermaid CLI via stdin
- The CLI validates the syntax and renders a PNG if valid
- Output and errors are captured from stdout/stderr
- Output:
- Success: Text confirmation + rendered PNG as base64-encoded image
- Failure: Error message with details about the validation failure
Dependencies
External Libraries
- @modelcontextprotocol/sdk: SDK for implementing Model Context Protocol
- @mermaid-js/mermaid-cli: CLI tool for validating and rendering Mermaid diagrams
- zod: Schema validation library for TypeScript
Development Dependencies
- typescript: TypeScript compiler
- eslint: Linting utility
- prettier: Code formatting
API Specification
validateMermaid Tool
Purpose: Validates a Mermaid diagram and returns the rendered PNG if valid
Parameters:
diagram(string): The Mermaid diagram syntax to validate
Return Value:
- Success:
{ content: [ { type: "text", text: "Mermaid diagram is valid" }, { type: "image", data: string, // Base64-encoded PNG mimeType: "image/png" } ] } - Failure:
{ content: [ { type: "text", text: "Mermaid diagram is invalid" }, { type: "text", text: string // Error message }, { type: "text", text: string // Detailed error output (if available) } ] }
Technical Decisions
-
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:
- Isolation between the main application and the rendering process
- Ability to capture detailed error information
- Proper handling of the rendering pipeline
-
Error Handling Strategy: The implementation uses a nested try-catch structure to:
- Distinguish between validation errors (invalid diagram syntax) and system errors
- Provide detailed error information to help users fix their diagrams
- Ensure the service remains stable even when processing invalid input
-
Simple Project Structure: The project uses a straightforward TypeScript project structure for:
- Easy maintenance and understanding
- Direct dependency management
- Simplified build process
Build and Execution
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.
Release
To release a new version, the following steps in order:
npm run buildnpm run bumpnpm run changelognpm publish --access public
Troubleshooting
- WSL/Windows stdin: Earlier versions invoked Mermaid CLI with
/dev/stdin, which can fail on WSL withENXIO. This server now uses-for stdin/stdout (-i -/-o -) to be portable across Linux/macOS/WSL/Windows. - Inspector working dir: When launching via the MCP Inspector, ensure the server path resolves (e.g.
npx @modelcontextprotocol/inspector npx -y @rtuin/mcp-mermaid-validator@latestor use an absolute path todist/main.js).
Alternatives
Related Skills
Browse all skillsUI design system toolkit for Senior UI Designer including design token generation, component documentation, responsive design calculations, and developer handoff tools. Use for creating design systems, maintaining visual consistency, and facilitating design-dev collaboration.
Answer questions about the AI SDK and help build AI-powered features. Use when developers: (1) Ask about AI SDK functions like generateText, streamText, ToolLoopAgent, embed, or tools, (2) Want to build AI agents, chatbots, RAG systems, or text generation features, (3) Have questions about AI providers (OpenAI, Anthropic, Google, etc.), streaming, tool calling, structured output, or embeddings, (4) Use React hooks like useChat or useCompletion. Triggers on: "AI SDK", "Vercel AI SDK", "generateText", "streamText", "add AI to my app", "build an agent", "tool calling", "structured output", "useChat".
Create, edit, and export live Excalidraw diagrams using mcp-excalidraw-server (MCP tools + canvas REST API). Use when an agent needs to draw/lay out diagrams, convert Mermaid to Excalidraw, query/update/delete elements, or export/import elements from a running canvas server (EXPRESS_SERVER_URL, default http://localhost:3000).
Master API documentation with OpenAPI 3.1, AI-powered tools, and modern developer experience practices. Create interactive docs, generate SDKs, and build comprehensive developer portals. Use PROACTIVELY for API documentation or developer portal creation.
Use when working with the OpenAI API (Responses API) or OpenAI platform features (tools, streaming, Realtime API, auth, models, rate limits, MCP) and you need authoritative, up-to-date documentation (schemas, examples, limits, edge cases). Prefer the OpenAI Developer Documentation MCP server tools when available; otherwise guide the user to enable `openaiDeveloperDocs`.
Guide for building TypeScript CLIs with Bun. Use when creating command-line tools, adding subcommands to existing CLIs, or building developer tooling. Covers argument parsing, subcommand patterns, output formatting, and distribution.