Generate PDFs from Cursor and Claude Code with the Api2Pdf MCP Server: A Hands-On Guide
Summary. This guide walks through the hosted Api2Pdf Model Context Protocol (MCP) server at https://mcp.api2pdf.com/mcp: what MCP is, how to add the server to Cursor, Claude Code and VS Code, what each of the 11 tools does, and three real prompts you can paste into an agent session today: an invoice PDF from HTML, a multi-PDF merge, and PDF-to-Markdown extraction.
You need an Api2Pdf API key from portal.api2pdf.com. The same key works for the REST API and the MCP server. Billing is identical to the REST API. Generated files are hosted for 24 hours.
If you want the announcement and FAQ, see Api2Pdf now has an MCP server. This post is the hands-on path from empty config to working tool calls.
What is MCP, in one paragraph?
The Model Context Protocol is an open standard for giving AI models tools. A client (Cursor, Claude Code, VS Code, Windsurf, or an agent you wrote with the MCP SDK) connects to an MCP server over Streamable HTTP, asks which tools are available, and calls them when the model decides to. The model reads each tool's description and JSON schema, so a well-described tool needs no separate docs. The Api2Pdf MCP server is a thin, stateless adapter in front of https://v2.api2pdf.com: when an agent calls html_to_pdf, the Worker makes one POST /chrome/pdf/html with your API key and returns the result. It stores no keys and no session state.
Add the Api2Pdf MCP server
Send your API key as an Authorization header (preferred). Bearer YOUR-KEY and a ?apikey= query fallback also work. Prefer the header so keys do not land in access logs.
Cursor
Add this to ~/.cursor/mcp.json for all projects, or to .cursor/mcp.json in a repo for that project only:
{
"mcpServers": {
"api2pdf": {
"url": "https://mcp.api2pdf.com/mcp",
"headers": {
"Authorization": "YOUR-API2PDF-API-KEY"
}
}
}
}
Reload MCP servers in Cursor. You should see all 11 Api2Pdf tools in the tool list.
Claude Code
claude mcp add --transport http api2pdf https://mcp.api2pdf.com/mcp \
--header "Authorization: YOUR-API2PDF-API-KEY"
Confirm with claude mcp list. Start a session and ask Claude to call check_balance.
VS Code
Add this to .vscode/mcp.json:
{
"servers": {
"api2pdf": {
"type": "http",
"url": "https://mcp.api2pdf.com/mcp",
"headers": {
"Authorization": "YOUR-API2PDF-API-KEY"
}
}
}
}
Note the VS Code shape uses servers (not mcpServers) and requires "type": "http".
Smoke-test from a shell
Before wiring an IDE, you can call the server directly:
curl -s -X POST https://mcp.api2pdf.com/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-H 'Authorization: YOUR-API2PDF-API-KEY' \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"check_balance","arguments":{}}}'
tools/list never requires a key. check_balance is free and confirms auth.
The 11 tools, briefly
Every file-producing tool returns a hosted URL (valid 24 hours) plus structured fields: fileUrl, responseId, mbOut, cost (USD), and seconds. File bytes are never returned into the model context; agents pass links.
| Tool | What it does | REST endpoint |
|---|---|---|
html_to_pdf | Render raw HTML to PDF with Headless Chrome. Landscape, margins, paper size, header/footer templates, page ranges, scale, print CSS. | POST /chrome/pdf/html |
url_to_pdf | Render a live page to PDF. Supports waitFor, waitForSelector, and extraHTTPHeaders for pages behind auth. | POST /chrome/pdf/url |
markdown_to_pdf | Render Markdown to PDF (converted to HTML, printed with Chrome). | POST /chrome/pdf/markdown |
url_to_image | Screenshot a page as PNG. Full page by default; viewport configurable. | POST /chrome/image/url |
html_to_image | Screenshot raw HTML as PNG. | POST /chrome/image/html |
office_to_pdf | Convert Word, Excel, PowerPoint, OpenDocument, RTF, TXT, or images to PDF via LibreOffice. Takes a source file URL. | POST /libreoffice/any-to-pdf |
merge_pdfs | Combine 2 to 50 PDFs by URL, in order. Accepts URLs returned by other Api2Pdf tools. | POST /pdfsharp/merge |
extract_pdf_pages | Copy a page range into a new PDF. Zero-indexed, half-open; negative indexes count from the end. | POST /pdfsharp/extract-pages |
watermark_pdf | Stamp text such as DRAFT or CONFIDENTIAL on every page. Font size, hex color, opacity, rotation. | POST /pdfsharp/watermark |
pdf_to_markdown | Extract a PDF's text as Markdown (OpenDataLoader), keeping headings, lists and tables where structure allows. | POST /opendataloader/markdown |
check_balance | Remaining prepaid balance (USD). Free. | GET /balance |
The tools chain. An agent can call url_to_pdf three times, pass those URLs to merge_pdfs, pass the result to watermark_pdf, and hand you the final link. Each step is one billed REST call.
Not in the MCP (yet), still on the REST API: password protection, bookmarks, compression, thumbnails, HTML to DOCX/XLSX, zip, barcodes, wkhtmltopdf, and the broader MarkItDown file-to-Markdown endpoint (POST /markitdown) for Office and other formats. The MCP's pdf_to_markdown covers PDF→Markdown via OpenDataLoader.
Example 1: Generate an invoice PDF from HTML
Paste a prompt like this into Cursor or Claude Code after the server is connected:
Generate an invoice PDF with the Api2Pdf html_to_pdf tool.
Use this HTML (inline CSS, no relative URLs):
<!DOCTYPE html>
<html><head><meta charset="utf-8">
<style>
body { font-family: system-ui, sans-serif; color: #111; margin: 40px; }
h1 { font-size: 22px; margin: 0 0 8px; }
.meta { color: #555; margin-bottom: 24px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 0; border-bottom: 1px solid #e5e7eb; }
.total { font-weight: 700; font-size: 18px; margin-top: 16px; }
</style></head><body>
<h1>Invoice #1042</h1>
<div class="meta">Acme Robotics, due Oct 30, 2026</div>
<table>
<tr><th>Item</th><th>Qty</th><th>Amount</th></tr>
<tr><td>API usage, September</td><td>1</td><td>$120.00</td></tr>
<tr><td>Priority support</td><td>1</td><td>$40.00</td></tr>
</table>
<div class="total">Total due: $160.00</div>
</body></html>
Call html_to_pdf with:
- fileName: "invoice-1042.pdf"
- printBackground: true
- displayHeaderFooter: true
- footerTemplate: a small centered footer with pageNumber / totalPages
- marginBottom: "0.7in"
Return the fileUrl and cost.
What the agent should do: make one html_to_pdf call with your HTML and options. You get back a hosted fileUrl and the cost in USD. Two tips from the tool schema: relative image and font URLs do not resolve, so use absolute URLs or inline assets; and Chrome renders header and footer templates very small by default, so set an explicit font-size in footerTemplate, for example <div style="font-size:9px;width:100%;text-align:center"><span class="pageNumber"></span> / <span class="totalPages"></span></div>.
Example 2: Merge several PDFs
Useful when an agent has already generated (or you already host) multiple PDFs and you want one combined file:
Using the Api2Pdf MCP tools:
1. Call url_to_pdf on https://www.api2pdf.com/pricing with
fileName "pricing.pdf" and waitFor "networkidle0".
2. Call markdown_to_pdf with a short one-page cover:
"# Q3 Packet\n\nGenerated from Cursor via Api2Pdf MCP."
fileName: "cover.pdf"
3. Call merge_pdfs with urls: [cover URL, pricing URL], fileName "q3-packet.pdf".
4. Optionally call watermark_pdf on the merge result with text "INTERNAL",
color "#FF0000", opacity 0.12, rotation -45.
Give me each intermediate URL and the final fileUrl.
merge_pdfs accepts URLs returned by other Api2Pdf tools, so the agent does not download or re-upload bytes. Order in the urls array is the page order in the output.
Example 3: Convert a PDF to Markdown (OpenDataLoader)
When you need PDF text in a form an LLM can read (for summaries, RAG chunks or diffs), use pdf_to_markdown. Behind the scenes it calls POST /opendataloader/markdown.
Take the invoice PDF URL from Example 1 (or any public PDF URL).
1. Call pdf_to_markdown with that url and fileName "invoice-1042.md".
2. Fetch the returned .md URL and give me the line items and total
as a Markdown table.
One distinction matters: the MCP pdf_to_markdown tool is OpenDataLoader, and it takes PDFs. For Word, PowerPoint, Excel and other formats, use the REST MarkItDown API (POST /markitdown) until a dedicated MCP tool lands.
Practical tips
- Auth errors come back as tool results, not transport failures, so the model can read them and retry. Invalid keys return the API's own message; bad watermark colors get a validation error asking for six hex digits.
- SPAs and late JS: on
url_to_pdf/url_to_image, setwaitFortonetworkidle0or passwaitForSelector. Usedelay(ms) for charts that paint after load. - Page ranges on extract: half-open and zero-indexed. Pages 1–3 →
start=0,end=3. Drop the last page →end=-1. - Cost: each tool call is one REST request on your key.
check_balanceandtools/listare free. There is no separate MCP plan. - Consumer chat apps (claude.ai, ChatGPT) need OAuth; this release is API-key only, so use developer tools and custom agents today.
What's next
Connect the server, run check_balance, then paste Example 1. If you already have HTML templates for invoices or reports, your agent can fill them and call html_to_pdf without you writing a single HTTP client.
Docs and related posts:



