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.
# 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
To start the MCP server, run:
npm start
The server provides a single tool called create_pdf_from_markdown
with the following parameters:
Required parameters:
markdown
: The Markdown content to convert to PDFOptional 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)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",
},
});
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",
},
});
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).
The server supports most standard Markdown elements:
The following elements are not supported:
$x^2$
or $$\sum_{i=1}^n x_i$$
)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.
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.
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"
}
}
}
}
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.
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.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.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