mcp-mermaid-validator
MCP サーバー: Mermaid Validator
Mermaidダイアグラムを検証およびレンダリングするモデルコンテキストプロトコルサーバー。このサーバーにより、LLM は Mermaid ダイアグラムを検証およびレンダリングできるようになります。
使用法
クイックスタート
MCP クライアントが Mermaid Validator を使用するように設定するには、次のように mcp servers ファイルに追加します。
{
"mcpServers": {
"mermaid-validator": {
"command": "npx",
"args": [
"-y",
"@rtuin/mcp-mermaid-validator@latest"
]
}
}
}Related MCP server: Mermaid MCP Server
建築
高レベルアーキテクチャ
このプロジェクトは、次のようなシンプルな TypeScript Node.js アプリケーションとして構成されています。
メインアプリケーション: Mermaid ダイアグラムを検証し、レンダリングされた PNG 出力を返す Node.js サービス
MCP 統合: モデル コンテキスト プロトコル SDK を使用して、MCP 互換クライアントに機能を公開します。
Mermaid CLI統合: Mermaid CLIツールを活用してダイアグラムの検証とレンダリングを実行します。
コード構造
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コンポーネントの機能
MCP サーバー (メイン コンポーネント)
コア機能はsrc/main.tsに実装されています。このコンポーネントは次の処理を行います。
MCPサーバーインスタンスを作成する
Mermaidダイアグラム構文を受け入れる
validateMermaidツールを登録しますMermaid CLI を使用して図を検証およびレンダリングします
検証結果とレンダリングされたPNG(有効な場合)を返します
適切なエラーメッセージでエラーケースを処理する
データフロー
入力: マーメイドダイアグラム構文を文字列として
処理:
図はstdin経由でMermaid CLIに渡されます。
CLIは構文を検証し、有効であればPNGをレンダリングします。
出力とエラーはstdout/stderrからキャプチャされます
出力:
成功: テキスト確認 + PNG を base64 エンコードされた画像としてレンダリング
失敗: 検証失敗の詳細を含むエラーメッセージ
依存関係
外部ライブラリ
@modelcontextprotocol/sdk : モデルコンテキストプロトコルを実装するためのSDK
@mermaid-js/mermaid-cli : Mermaid ダイアグラムを検証およびレンダリングするための CLI ツール
zod : TypeScript のスキーマ検証ライブラリ
開発依存関係
typescript : TypeScript コンパイラ
eslint : リンティングユーティリティ
prettier : コードのフォーマット
API仕様
検証マーメイドツール
目的: マーメイドダイアグラムを検証し、有効な場合はレンダリングされたPNGを返します。
パラメータ:
diagram(文字列): 検証するMermaidダイアグラム構文
戻り値:
成功:
{ 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 統合: このプロジェクトでは、モデル コンテキスト プロトコルを使用して AI ツールのインターフェースを標準化し、互換性のあるクライアントとのシームレスな統合を可能にします。
PNG 出力形式: 実装では、ほとんどの MCP クライアント (特に SVG をサポートしていない Cursor) との互換性を高めるために、デフォルトの出力形式として PNG を使用します。
子プロセス アプローチ: 実装では、Node.js の子プロセスを使用して Mermaid CLI と対話し、次の機能を提供します。
メインアプリケーションとレンダリングプロセスの分離
詳細なエラー情報を取得する機能
レンダリングパイプラインの適切な処理
エラー処理戦略: 実装では、ネストされた try-catch 構造を使用して次の処理を行います。
検証エラー(無効なダイアグラム構文)とシステムエラーを区別する
ユーザーが図を修正できるように詳細なエラー情報を提供する
無効な入力を処理する場合でもサービスが安定していることを確認する
シンプルなプロジェクト構造: このプロジェクトでは、次のような簡単な TypeScript プロジェクト構造を使用します。
メンテナンスと理解が容易
直接的な依存関係管理
簡素化されたビルドプロセス
ビルドと実行
アプリケーションは npm スクリプトを使用してビルドおよび実行できます。
# 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アプリケーションは標準入出力を介して通信する MCP サーバーとして実行されるため、MCP 互換クライアントとの統合に適しています。
リリース
新しいバージョンをリリースするには、次の手順に従います。
npm run buildnpm run bumpnpm run changelognpm publish --access public
Available Tools
1 toolvalidateMermaidC
Validates a Mermaid diagram and returns the rendered image (PNG or SVG) if valid
| Name | Required | Description | Default |
|---|---|---|---|
| diagram | Yes | ||
| format | No | png |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations; description fails to disclose what happens on invalid input (e.g., error messages), side effects, or rate limits. Minimal behavioral context.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Single sentence, no fluff. Efficient for its brevity.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
No output schema; description mentions 'rendered image' but not format details (binary vs base64) or validation success/failure behavior. Lacks completeness for a validation tool.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 0%; tool description does not explain parameters beyond schema fields. 'diagram' and 'format' remain underdocumented.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Clear verb-resource: 'Validates a Mermaid diagram' and specifies output ('rendered image'). Lacks sibling differentiation but no siblings exist.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
No guidance on when to use or when not to, no alternatives mentioned. Implied usage only.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
1 tool update
v0.7.0- Changed
validateMermaid1 field changed- added
Input schema / properties / formatAdded value: +{ + "default": "png", + "enum": [ + "svg", + "png" + ], + "type": "string" +}
1 tool update
v1.0.0- First observed
validateMermaid
TDQS
Scored across 1 tool
With only one tool, there is no possibility for confusion. The tool's purpose is clear and distinct.
A single tool cannot be inconsistent. The name 'validateMermaid' follows a clear verb_noun pattern.
A single validation tool perfectly matches the server's focused purpose. Adding more tools would be unnecessary.
The tool fully covers the domain: it validates Mermaid diagrams and returns the rendered image. No obvious gaps exist.
Maintenance
Related MCP Connectors
Render, verify, describe, and safely edit Mermaid diagrams through MCP.
A Model Context Protocol server for Wix AI tools
Model Context Protocol server for Studex tools, notifications, and profile integrations
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
Related MCP Servers
- AlicenseBqualityCmaintenanceA Model Context Protocol (MCP) server that converts Mermaid diagrams to PNG images.1158 npm235MIT
- AlicenseNot gradedqualityNot gradedmaintenanceA server that implements the Model Context Protocol (MCP), providing an interface for LLM applications to generate mermaid.js visualizations and diagrams.MIT
- FlicenseNot gradedqualityDmaintenanceA powerful Model Context Protocol server that automatically generates Mermaid diagrams from code and provides SVG beautification features.1-
- AlicenseAqualityBmaintenanceA Model Context Protocol server that converts Mermaid diagram code into various image formats (PNG, JPG, SVG, PDF) with theme customization options for AI clients.39MIT