An MCP (Model Context Protocol) server that converts Markdown files containing Mermaid diagrams into PDF documents, and also converts standalone Mermaid diagrams to PNG or PDF. The server uses a hybrid approach: converting Markdown to HTML, rendering Mermaid diagrams as SVG graphics, and then generating outputs using Puppeteer.
- Converts Markdown files with Mermaid diagrams to PDF
- Converts standalone Mermaid diagram code to PNG images
- Converts standalone Mermaid diagram code to PDF files
- Automatically renders Mermaid diagrams as high-quality SVG graphics
- Clean, professional default styling
- Support for custom CSS styling (for Markdown conversion)
- Simple MCP tool interface
npm install
npm run buildAdd this server to your MCP client configuration (e.g., Claude Desktop):
{
"mcpServers": {
"md-mmd-pdf": {
"command": "node",
"args": ["/absolute/path/to/md-mmd-pdf/build/index.js"]
}
}
}Converts a Markdown file with Mermaid diagrams to PDF.
Parameters:
input_path(required): Absolute path to the input Markdown fileoutput_path(optional): Absolute path where the PDF should be saved. If not provided, uses the same name as input with.pdfextensioncustom_css(optional): Additional CSS styles to apply to the PDF
Example:
{
"input_path": "/path/to/document.md",
"output_path": "/path/to/output.pdf"
}Converts a standalone Mermaid diagram code to a PNG image file.
Parameters:
mermaid_code(required): Raw Mermaid diagram code as a stringoutput_path(required): Absolute path where the PNG file should be saved
Example:
{
"mermaid_code": "graph TD\n A[Start] --> B[Process]\n B --> C[End]",
"output_path": "/path/to/diagram.png"
}Converts a standalone Mermaid diagram code to a PDF file.
Parameters:
mermaid_code(required): Raw Mermaid diagram code as a stringoutput_path(required): Absolute path where the PDF file should be saved
Example:
{
"mermaid_code": "sequenceDiagram\n Alice->>Bob: Hello\n Bob->>Alice: Hi!",
"output_path": "/path/to/diagram.pdf"
}- Markdown Parsing: Reads and parses Markdown content using the
markedlibrary - HTML Generation: Converts Markdown to HTML while preserving Mermaid code blocks
- Mermaid Rendering: Injects Mermaid.js library to render diagrams as SVG in the browser
- PDF Export: Uses Puppeteer (headless Chrome) to generate the final PDF with all content rendered
See example.md for a sample document with Mermaid diagrams.
# Install dependencies
npm install
# Build
npm run build
# Watch mode for development
npm run dev
# Run the server
npm start- Node.js 18 or higher
- Sufficient memory for Puppeteer to run headless Chrome
MIT