Markdown to PDF MCP server

Converts Markdown to PDF using Puppeteer, offering syntax highlighting, custom styling, and watermarking capabilities for document generation.
Back to servers
Setup instructions
Provider
Ian Shen
Release date
Dec 23, 2024
Language
TypeScript
Stats
8 stars

The Markdown2PDF MCP Server converts Markdown documents to PDF files with support for syntax highlighting, custom styling, and watermarking. It provides a straightforward way to generate professional PDFs from your Markdown content using Chrome's rendering engine.

Installation

# Clone the repository
git clone https://github.com/2b3pro/markdown2pdf-mcp.git

# Navigate to the project directory
cd markdown2pdf-mcp

# Install dependencies
npm install

# Build the project
npm run build

Usage

Starting the Server

To start the MCP server, run:

npm start

Using the MCP Tool

The server provides a single tool called create_pdf_from_markdown with the following parameters:

Required parameters:

  • markdown: The Markdown content to convert to PDF

Optional parameters:

  • outputFilename: Filename for the PDF (e.g., "output.pdf")
  • paperFormat: Paper size - 'letter' (default), 'a4', 'a3', 'a5', 'legal', 'tabloid'
  • paperOrientation: 'portrait' (default) or 'landscape'
  • paperBorder: '2cm' (default), accepts decimal values with CSS units (e.g., '1.5cm', '2.5mm', '0.5in', '10.5px')
  • watermark: Optional watermark text (max 15 characters, uppercase)

Example with All Options

await use_mcp_tool({
  server_name: "markdown2pdf",
  tool_name: "create_pdf_from_markdown",
  arguments: {
    markdown: "# Hello World\n\nThis is a test document.",
    outputFilename: "output.pdf",
    paperFormat: "a4",
    paperOrientation: "landscape",
    paperBorder: "1.5cm",
    watermark: "DRAFT",
  },
});

Minimal Example

await use_mcp_tool({
  server_name: "markdown2pdf",
  tool_name: "create_pdf_from_markdown",
  arguments: {
    markdown: "# Hello World\n\nThis is a test document.",
    outputFilename: "output.pdf",
  },
});

Configuration

Customizing the Output Directory

You can configure where PDF files are saved by setting the output directory in your MCP settings file:

{
  "mcpServers": {
    "markdown2pdf": {
      "command": "node",
      "args": ["path/to/markdown2pdf-mcp/build/index.js"],
      "env": {
        "M2P_OUTPUT_DIR": "/path/to/output/directory"
      }
    }
  }
}

If not configured, files will save to your $HOME directory.

The tool automatically handles file name conflicts by appending incremental numbers (e.g., output.pdf, output-1.pdf, output-2.pdf).

Supported Markdown Features

The server supports most standard Markdown elements:

  • Headers (all levels)
  • Text formatting (bold, italic, strikethrough)
  • Lists (ordered and unordered)
  • Code blocks with syntax highlighting
  • Tables
  • Blockquotes
  • Links
  • Images (both local files and external URLs)
  • Task lists

Unsupported Elements

The following elements are not supported:

  • LaTeX math equations (e.g., $x^2$ or $$\sum_{i=1}^n x_i$$)
  • Complex mathematical formulas or scientific notation

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "markdown2pdf" '{"command":"node","args":["path/to/markdown2pdf-mcp/build/index.js"],"env":{"M2P_OUTPUT_DIR":"/path/to/output/directory"}}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "markdown2pdf": {
            "command": "node",
            "args": [
                "path/to/markdown2pdf-mcp/build/index.js"
            ],
            "env": {
                "M2P_OUTPUT_DIR": "/path/to/output/directory"
            }
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "markdown2pdf": {
            "command": "node",
            "args": [
                "path/to/markdown2pdf-mcp/build/index.js"
            ],
            "env": {
                "M2P_OUTPUT_DIR": "/path/to/output/directory"
            }
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later