Labsco
sham-devs logo

MCP-MD-PDF: Markdown to Word/PDF Converter

β˜… 1

from sham-devs

A simple, reliable Model Context Protocol (MCP) server that converts Markdown files into professional Word (.docx) and PDF documents β€” with full support for .dotx templates.

πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedFreeAdvanced setup

MCP-MD-PDF: Markdown to Word/PDF Converter

PyPI version Python Versions Tests License: MIT

A simple, reliable Model Context Protocol (MCP) server that converts Markdown files into professional Word (.docx) and PDF documents β€” with full support for .dotx templates.


Background

This tool was born from a practical need. We often write documentation, guides, and technical notes in Markdown β€” it’s fast, lightweight, and easy to version. But when it’s time to deliver these files to clients or present them professionally, we usually want them to match our project or company style: clean layout, consistent fonts, branded cover page, and polished formatting.

So instead of doing that manually every time, we built a simple flow:

Convert Markdown β†’ Word (.docx using a .dotx template) β†’ PDF

By using Word templates, we could apply our own design once and keep every document consistent. That’s where this small project came from β€” a quick way to turn Markdown into beautiful, ready-to-share documents that look like they belong to your organization.


Features

  • πŸš€ Fast Conversion – From Markdown to Word or PDF in seconds
  • 🎨 Template Support – Apply .dotx templates for consistent, branded styling
  • πŸ“¦ Batch Processing – Convert multiple files at once
  • πŸ”§ Flexible Output – Choose between .docx, .pdf, or both
  • πŸ€– AI-Ready – Built to integrate smoothly with Claude and other MCP-compatible AI tools

MCP Tools

1. convert_markdown

Convert a single Markdown file to Word or PDF.

Parameters:

  • markdown_path (str) – Path to the .md file
  • output_path (str) – Output base path (no extension)
  • output_format (str) – "docx", "pdf", or "both" (default: "docx")
  • template_path (str, optional) – Path to .dotx template

Examples:

# Create Word document
convert_markdown("README.md", "output", "docx")

# Create PDF with template
convert_markdown("doc.md", "result", "pdf", "template.dotx")

# Create both formats
convert_markdown("guide.md", "final", "both", "company.dotx")

2. convert_markdown_batch

Convert multiple Markdown files at once.

Parameters:

  • markdown_files (list[str]) – List of .md files
  • output_dir (str) – Output directory
  • output_format (str) – "docx", "pdf", or "both"
  • template_path (str, optional) – Shared .dotx template

Example:

convert_markdown_batch(
  ["doc1.md", "doc2.md", "doc3.md"],
  "output",
  "both",
  "template.dotx"
)

3. list_supported_formats

List supported formats and their capabilities.


Supported Markdown Features

FeatureSupportedNotes
Headings (H1–H6)βœ…# through ######, with template fallback
Bold / Italicβœ…Markdown standard syntax
Inline codeβœ…Monospaced with gray background
Code blocksβœ…Professional styling with background and borders
Bullet & Numbered listsβœ…Nested up to 3 levels
Tablesβœ…With header styling and inline formatting
Blockquotesβœ…Italic text with left border and background shading
Horizontal rulesβœ…---
Unicode & Emojiβœ…Full UTF-8 support

For detailed feature coverage analysis, see docs/MARKDOWN_COVERAGE.md


Template Support

Use a .dotx Word template to define your document style:

  • Custom headings, fonts, and colors
  • Page margins and layout
  • Headers and footers
  • Branding and logo placement
  • Table of contents formatting

If no template is provided, a clean default design is used.


Platform Notes

  • DOCX Conversion: Works on all platforms (Windows, macOS, Linux) - no additional software required
  • PDF Conversion: Cross-platform with automatic platform detection:
    • Windows: Uses Microsoft Word (if installed) or LibreOffice
    • macOS/Linux: Uses LibreOffice in headless mode

Why LibreOffice for PDF? LibreOffice preserves ALL DOCX formatting when converting to PDF:

  • βœ… Colors, backgrounds, and borders
  • βœ… Professional code block styling (#F5F5F5 backgrounds)
  • βœ… Blockquote borders (blue left border)
  • βœ… Table headers with colored backgrounds
  • βœ… Template styles from .dotx files
  • βœ… Fonts, spacing, and layout

Development

# Clone the repository
git clone https://github.com/sham-devs/mcp-md-pdf.git
cd mcp-md-pdf

# Install with dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run tests with coverage
pytest --cov=src/md_pdf_mcp --cov-report=html

# Format code
black src/ tests/
ruff check src/ tests/

Testing

Covers:

  • Markdown β†’ Word conversion
  • Template application
  • MCP server tools
  • Unicode, emoji, and edge cases

Structure:

tests/
β”œβ”€β”€ conftest.py
β”œβ”€β”€ test_converter.py
β”œβ”€β”€ test_server.py
└── README.md

Examples

# Run the MCP server directly
python -m md_pdf_mcp.server

Or inspect via:

npx @modelcontextprotocol/inspector python -m md_pdf_mcp.server

Example usage:

User: Convert my README.md to Word format
β†’ Created: README.docx

User: Create a PDF with our company template
β†’ Created: guide.pdf

User: Convert all docs to both formats
β†’ Batch Conversion Complete (5 succeeded, 0 failed)

License

MIT License – see LICENSE file.


Contributing

Pull requests are welcome. If you have ideas for improving conversions, templates, or new formats, we’d love to see them.


Credits

Built with ❀️ using the FastMCP framework β€” created to make Markdown documents look like real reports, not just text on GitHub.