HTML to PDF from AI agents with MCP
The WeasyPrint MCP server gives agents a render_pdf tool that returns a download link to the PDF. Setup for Claude Code and other MCP clients.
Last updated
Add the MCP server at https://api.pagespool.com/mcp/weasyprint/, and your agent gets
a render_pdf tool. The tool takes HTML and returns a link to the PDF, which
works for 15 minutes:
{"download_url": "...", "pages": N, "size_bytes": N, "expires_in_minutes": 15}.
The agent gives you the link, and you open the PDF in your browser.
Claude Code:
claude mcp add --transport http weasyprint https://api.pagespool.com/mcp/weasyprint/ \
--header "X-API-Key: YOUR_KEY"
Other MCP clients:
{
"mcpServers": {
"weasyprint": {
"type": "http",
"url": "https://api.pagespool.com/mcp/weasyprint/",
"headers": { "X-API-Key": "YOUR_KEY" }
}
}
}
The key is optional, and Authorization: Bearer YOUR_KEY works too. Without
a key, the tool counts against the same limits as the REST API without one.
Each of the other engines has an MCP server of its own, and the
connect page lists them all.
Tool and REST API
The tool accepts up to 256 KB of HTML, the REST API up to 2 MB. For a
larger document, have the agent call
POST /v1/weasyprint/render. The
rendering rules are the same: HTML and CSS, data: URIs, no JavaScript. The
REST API returns the PDF itself, not a link.
Next step
FAQ
- Does the MCP server need an API key?
- No. Without a key, the tool shares the limits of calls without a key with the REST API. With a key, each render costs 1 credit from the same balance as the REST API.
- How much HTML can the MCP tool take?
- Up to 256 KB. For larger documents, use the REST API, which accepts 2 MB.
- How long does the download link work?
- For 15 minutes, and you can open it as often as you like in that time. After that, run the render again. The PDF is kept in memory only and is never written to disk.