PA

Pandoc MCP Server for Markdown to PDF, DOCX

Convert Markdown, HTML, CSV and more to PDF, DOCX and other formats with the Pandoc MCP server for fast, reliable document conversion.

Quick Install
npx -y @vivekVells/mcp-pandoc

Overview

Pandoc MCP Server is a lightweight HTTP service that uses Pandoc to convert documents between a wide range of formats. It’s designed for developers who need fast, reliable conversions (e.g., Markdown → PDF or DOCX) as part of automated pipelines, web apps, or serverless workflows. The server exposes a simple API for submitting content or files and returns converted outputs ready for download.

Because it delegates conversion work to Pandoc, the server supports most input/output formats Pandoc can handle while adding process safety, optional configuration, and an HTTP interface. This makes it useful for generating reports, exporting blog posts, or integrating document conversion into CI/CD pipelines without bundling Pandoc into every application.

Features

  • HTTP API for on-demand document conversion (POST requests)
  • Support for common Pandoc formats: Markdown, HTML, LaTeX, DOCX, PDF, EPUB, ODT, and more
  • Accepts raw content, file uploads, or URLs as input
  • Configurable Pandoc command-line arguments and templates
  • Streaming binary responses (PDF, DOCX) and meaningful JSON error messages
  • Docker-friendly and environment-configurable options
  • Lightweight process isolation and size limits for safe operation

Installation / Configuration

Clone and run locally:

git clone https://github.com/vivekVells/mcp-pandoc.git
cd mcp-pandoc
# Install dependencies (if Node-based)
npm install

# Build/start (project may use npm scripts)
npm start

Docker (build and run):

# Build an image from the repository
docker build -t mcp-pandoc .

# Run on port 3000
docker run -p 3000:3000 -e PORT=3000 mcp-pandoc

Common environment variables (typical configuration options):

  • PORT — HTTP port the server listens on (default: 3000)
  • PANDOC_PATH — path to the pandoc binary (if not on PATH)
  • TEMPLATE_DIR — folder for Pandoc templates
  • MAX_UPLOAD_MB — maximum allowed upload size
  • WORK_DIR — temporary working directory for conversions

Configuration is usually done via environment variables or a config file in the repo root. Adjust Pandoc arguments (e.g., --pdf-engine=xelatex) through the API call or server configuration to control output rendering.

Available Resources

API endpoints (example signatures — check the repo’s API docs for exact details):

EndpointMethodDescription
/convertPOSTConvert input content or uploaded file to a target format
/healthGETBasic health check returning server status
/formatsGET(Optional) List of supported input/output formats

Typical POST /convert payloads:

  • form-data file upload with fields: file, from, to, args[]
  • JSON body with: content (string), from, to, args (array)

Response types:

  • Binary stream with appropriate Content-Type for formats like PDF or DOCX
  • JSON with status and error details for failures

Repository and additional resources:

  • Source code and examples: https://github.com/vivekVells/mcp-pandoc
  • Pandoc documentation (for available formats and CLI options): https://pandoc.org

Use Cases

  1. Convert Markdown to PDF for automated report generation
  • Client POSTs Markdown content and requests to=pdf.
  • Server runs Pandoc with a chosen PDF engine and returns application/pdf. Example curl:
curl -X POST "http://localhost:3000/convert" \
  -F "[email protected];type=text/markdown" \
  -F "to=pdf" \
  --output report.pdf
  1. Produce DOCX from HTML for downstream editing
  • Convert generated HTML pages into DOCX files so non-technical users can edit documents in Word:
curl -X POST "http://localhost:3000/convert" \
  -F "content=<html>...</html>;type=text/html" \
  -F "to=docx" \
  --output output.docx
  1. Batch processing in CI/CD
  • Use the server in a build pipeline to convert a set of Markdown files into multiple formats (PDF, EPUB). The server can be invoked by scripts or runners and returns artifacts for publishing.
  1. CSV → DOCX/Table reports
  • Convert CSV to a Markdown table (or use a Pandoc filter) and convert that to DOCX/PDF for printable reports. This server offloads that step to a centralized conversion service.

Examples (client snippets)

Node (fetch):

const fs = require('fs');
const fetch = require('node-fetch');

async function toPdf(md) {
  const res = await fetch('http://localhost:3000/convert', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ content: md, from: 'markdown', to: 'pdf' })
  });
  const buffer = await res.buffer();
  fs.writeFileSync('out.pdf', buffer);
}

Python (requests):

import requests
r = requests.post('http://localhost:3000/convert',
                  json={'content': '# Hi', 'from':'markdown','to':'pdf'})
open('out.pdf','wb').write(r.content)

Notes and Best Practices

  • Ensure Pandoc and any required engines (e.g., TeX for PDF) are installed on the host or included in your container image.
  • Limit request sizes and run conversions in temporary directories to prevent resource exhaustion.
  • Use templates and Pandoc args to control styling and engines (e.g., –pdf-engine=xelatex).
  • For production, run behind a reverse proxy, add authentication, and enable HTTPS.

This server is intended to simplify integrating Pandoc conversions into applications and pipelines while providing a stable HTTP API for developers. For exact API details and configuration examples, consult the repository: https://github.com/vivekVells/mcp-pandoc.