Skip to main content
Glama
rtuin

mcp-mermaid-validator

by rtuin

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 アプリケーションとして構成されています。

  1. メインアプリケーション: Mermaid ダイアグラムを検証し、レンダリングされた PNG 出力を返す Node.js サービス

  2. MCP 統合: モデル コンテキスト プロトコル SDK を使用して、MCP 互換クライアントに機能を公開します。

  3. 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に実装されています。このコンポーネントは次の処理を行います。

  1. MCPサーバーインスタンスを作成する

  2. Mermaidダイアグラム構文を受け入れるvalidateMermaidツールを登録します

  3. Mermaid CLI を使用して図を検証およびレンダリングします

  4. 検証結果とレンダリングされたPNG(有効な場合)を返します

  5. 適切なエラーメッセージでエラーケースを処理する

データフロー

  1. 入力: マーメイドダイアグラム構文を文字列として

  2. 処理:

    • 図はstdin経由でMermaid CLIに渡されます。

    • CLIは構文を検証し、有効であればPNGをレンダリングします。

    • 出力とエラーはstdout/stderrからキャプチャされます

  3. 出力:

    • 成功: テキスト確認 + 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)
        }
      ]
    }

技術的な決定

  1. MCP 統合: このプロジェクトでは、モデル コンテキスト プロトコルを使用して AI ツールのインターフェースを標準化し、互換性のあるクライアントとのシームレスな統合を可能にします。

  2. PNG 出力形式: 実装では、ほとんどの MCP クライアント (特に SVG をサポートしていない Cursor) との互換性を高めるために、デフォルトの出力形式として PNG を使用します。

  3. 子プロセス アプローチ: 実装では、Node.js の子プロセスを使用して Mermaid CLI と対話し、次の機能を提供します。

    • メインアプリケーションとレンダリングプロセスの分離

    • 詳細なエラー情報を取得する機能

    • レンダリングパイプラインの適切な処理

  4. エラー処理戦略: 実装では、ネストされた try-catch 構造を使用して次の処理を行います。

    • 検証エラー(無効なダイアグラム構文)とシステムエラーを区別する

    • ユーザーが図を修正できるように詳細なエラー情報を提供する

    • 無効な入力を処理する場合でもサービスが安定していることを確認する

  5. シンプルなプロジェクト構造: このプロジェクトでは、次のような簡単な 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 build

  • npm run bump

  • npm run changelog

  • npm publish --access public

Available Tools

1 tool
validateMermaidC

Validates a Mermaid diagram and returns the rendered image (PNG or SVG) if valid

ParametersJSON Schema
NameRequiredDescriptionDefault
diagramYes
formatNopng

TDQS

C2.7/5.0
Behavior2/5

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.

Conciseness5/5

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.

Completeness2/5

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.

Parameters1/5

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.

Purpose4/5

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.

Usage Guidelines2/5

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. 1 tool updatev0.7.0
    • ChangedvalidateMermaid1 field changed
      • addedInput schema / properties / format
        Added value: +{
        +  "default": "png",
        +  "enum": [
        +    "svg",
        +    "png"
        +  ],
        +  "type": "string"
        +}
  2. 1 tool updatev1.0.0
    • First observedvalidateMermaid

TDQS

B3.4/5.0

Scored across 1 tool

Disambiguation5/5

With only one tool, there is no possibility for confusion. The tool's purpose is clear and distinct.

Naming Consistency5/5

A single tool cannot be inconsistent. The name 'validateMermaid' follows a clear verb_noun pattern.

Tool Count5/5

A single validation tool perfectly matches the server's focused purpose. Adding more tools would be unnecessary.

Completeness5/5

The tool fully covers the domain: it validates Mermaid diagrams and returns the rendered image. No obvious gaps exist.

Maintenance

ActivityInactive
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers