latex-pdf-mcp-server

apolosan/latex-pdf-mcp-server

3.2

If you are the rightful owner of latex-pdf-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

The LaTeX PDF MCP Server is a robust solution for compiling LaTeX templates into PDF files, optimized for integration with n8n workflows.

LaTeX PDF MCP Server

MCP (Model Context Protocol) server for compiling LaTeX templates to PDF files, designed for seamless integration with n8n workflows.

Features

  • Complete LaTeX Distribution - TeXLive Full with 6000+ packages
  • Universal Document Support - Books, presentations, posters, magazines, spreadsheets, banners
  • Advanced Graphics - TikZ/PGF diagrams, plots, circuits, chemical structures
  • Professional Typography - Multiple font collections and international language support
  • Dynamic Templates - Parameter substitution with LaTeX special character escaping
  • Multiple Compilers - pdflatex, xelatex, lualatex with automatic selection
  • Scientific Publishing - Mathematical formulas, bibliographies, complex tables
  • Business Documents - Reports, invoices, presentations with corporate branding
  • Educational Materials - Slides, handouts, exams, academic papers
  • Marketing Materials - Flyers, banners, brochures, catalogs
  • Docker Optimized - 5GB container with pre-compiled formats for fast startup
  • n8n Integration - Seamless workflow integration via REST API

Quick Start

Development

# Install dependencies
npm install

# Start development server
npm run dev

# Test compilation
curl -X POST http://localhost:3000/api/compile \
  -H "Content-Type: application/json" \
  -d '{
    "template": "\\documentclass{article}\\begin{document}Hello {{name}}!\\end{document}",
    "parameters": {"name": "World"}
  }'

Production (Docker)

# Build and run
npm run build
docker-compose up -d

# Health check
curl http://localhost:3000/api/health

API Endpoints

POST /api/compile

Compile LaTeX template to PDF.

Request:

{
  "template": "\\documentclass{article}\\begin{document}Hello {{name}}!\\end{document}",
  "parameters": {
    "name": "World"
  },
  "compiler": "pdflatex",
  "filename": "output.pdf"
}

Response:

{
  "success": true,
  "filename": "output.pdf",
  "size": 12345,
  "data": "base64-encoded-pdf-content",
  "contentType": "application/pdf"
}

GET /api/health

Check server and LaTeX availability.

Response:

{
  "status": "ok",
  "version": "1.0.0",
  "latex": {
    "available": true,
    "compilers": ["pdflatex", "xelatex", "lualatex"]
  },
  "uptime": 3600
}

n8n Integration

  1. Add HTTP Request node to your workflow
  2. Configure:
    • Method: POST
    • URL: http://your-server:3000/api/compile
    • Body: JSON with template and parameters
  3. Add Save Binary Data node to handle PDF output

Example n8n Workflow

{
  "nodes": [
    {
      "name": "LaTeX Compiler",
      "type": "n8n-nodes-base.httpRequest",
      "parameters": {
        "url": "http://latex-server:3000/api/compile",
        "method": "POST",
        "jsonParameters": true,
        "options": {},
        "bodyParametersJson": {
          "template": "\\documentclass{article}\\begin{document}Invoice for {{customerName}}\\end{document}",
          "parameters": {
            "customerName": "{{$json.customer}}"
          }
        }
      }
    }
  ]
}

Template Syntax

Use {{variableName}} syntax for dynamic content:

\documentclass{article}
\begin{document}

\title{{{title}}}
\author{{{author}}}
\date{{{date}}}

\maketitle

{{content}}

\end{document}

Development Scripts

  • npm run dev - Start development server with hot reload
  • npm run build - Build TypeScript to JavaScript
  • npm run start - Start production server
  • npm run test - Run tests
  • npm run lint - Lint code

Docker Commands

  • npm run docker:build - Build Docker image
  • npm run docker:run - Run container
  • docker-compose up -d - Start with compose
  • docker-compose --profile dev up - Start development mode

Environment Variables

  • PORT - Server port (default: 3000)
  • NODE_ENV - Environment (development/production)

Requirements

  • Node.js 18+
  • LaTeX distribution (TeXLive recommended)
  • Docker (for containerized deployment)

License

MIT