AM

andrewginns/mermaid-mcp-server

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

11 stars 2 forks 质量 56 趋势 18

Python MCP Server abstracting the official mermaid-cli for ease of use

概览

A Model Context Protocol (MCP) server for validating Mermaid diagrams. Implements a minimal Python wrapper over https://github.com/mermaid-js/mermaid-cli for simpler out of the box use. Python MCP server for validating Mermaid diagrams and (optionally) rendering them as PNG images. It uses the Mermaid CLI tool to perform the validation and rendering. The server provides LLMs with structured validation results including: - (is_valid: true/false) indicating whether the Mermaid diagram syntax is correct - explaining exactly what went wrong if validation fails (e.g., syntax errors, unsupported diagram types, malformed nodes) - of successfully rendered diagrams for visual verification This enables LLMs to programmatically validate Mermaid diagram syntax, understand specific errors to provide helpful corrections, and optionally receive visual confirmation of the rendered output. Also provides a simple Pydantic-AI MCP Client to invoke the MCP server using a Gemini model for testing.

README

以下为原文 README 节选,完整内容请查看原文。

Mermaid MCP Server

A Model Context Protocol (MCP) server for validating Mermaid diagrams.

Implements a minimal Python wrapper over https://github.com/mermaid-js/mermaid-cli for simpler out of the box use.

Overview

Python MCP server for validating Mermaid diagrams and (optionally) rendering them as PNG images. It uses the Mermaid CLI tool to perform the validation and rendering.

The server provides LLMs with structured validation results including:

  • Boolean validation status (is_valid: true/false) indicating whether the Mermaid diagram syntax is correct
  • Detailed error messages explaining exactly what went wrong if validation fails (e.g., syntax errors, unsupported diagram types, malformed nodes)
  • Optional base64-encoded PNG images of successfully rendered diagrams for visual verification

This enables LLMs to programmatically validate Mermaid diagram syntax, understand specific errors to provide helpful corrections, and optionally receive visual confirmation of the rendered output.

Also provides a simple Pydantic-AI MCP Client to invoke the MCP server using a Gemini model for testing.

Prerequisites

Important: This MCP server requires Node.js to be installed on your system, even if you’re only using the server component (not the client). The server internally calls npx @mermaid-js/mermaid-cli as a subprocess to perform diagram validation and rendering.

Required Dependencies

  • Node.js with npm (required for all usage)
  • Mermaid CLI: Install with npm install -g @mermaid-js/mermaid-cli
  • Python with uv (for running the MCP server)

Quick Dependency Setup

# Install Mermaid CLI globally
npm install -g @mermaid-js/mermaid-cli

# Verify installation
npx @mermaid-js/mermaid-cli --version

Quickstart

To use this server with an MCP client (like Claude Desktop), add the following configuration to your MCP settings:

Note: Make sure you have Node.js and Mermaid CLI installed (see Prerequisites above) before configuring the MCP server.

Configuration Format

  1. Clone this repository

  2. Add this to your MCP client configuration file (e.g., claude_desktop_config.json):

{
  "mcpServers": {
    "mermaid-validator": {
      "command": "uv",
      "args": ["run", "/path/to/mermaid_mcp_server.py"],
    }
  }
}

Configuration Options

  • command: Use uv to run the server
  • args: Run the server script with uv run
  • cwd: Set to the absolute path of your cloned repository
  • env: Environment variables for the server
    • MCP_TRANSPORT: Set to "stdio" for standard input/output communication

Example Extended Configuration

{
  "mcpServers": {
    "mermaid-validator": {
      "command": "uv", 
      "args": ["run", "/path/to/mermaid_mcp_server.py"],
      "env": {
        "MCP_TRANSPORT": "stdio",
      }
    }
  }
}

Abstractions Over Mermaid-CLI

在 GitHub 查看完整 README

安装

npx @mermaid-js/mermaid-cli --version
新手?先看 mcpskill.org 教程 →

配置

{ "mcpServers": { "mermaid-validator": { "command": "uv", "args": ["run", "/path/to/mermaid_mcp_server.py"], } } }