AI agents can now generate PDFs directly, no code, no API calls, no manual work. You describe what you want in plain English, and the agent handles everything: writing the HTML template, filling in data, and rendering a pixel-perfect PDF.
This is possible thanks to MCP (Model Context Protocol), the open standard that lets AI tools connect to external services. PDF4.dev ships with a built-in MCP server, making it the first PDF API that AI agents can use natively.
What is MCP?
MCP is an open protocol created by Anthropic that lets AI assistants call external tools. Think of it as "plugins for AI", but standardized across all clients.
When you connect an MCP server to your AI tool, the agent gains new capabilities. In the case of PDF4.dev, your agent can:
- Generate PDFs from templates or raw HTML
- Create and manage templates with Handlebars variables
- Check generation logs for debugging and monitoring
The agent decides which tools to call based on your natural language request. You never need to write API calls yourself.
Setup: 3 minutes
Step 1: Get an API key
Create a free account at pdf4.dev, then generate an API key in Settings.
Step 2: Connect the MCP server
Add PDF4.dev to your AI client's MCP configuration. The setup is slightly different for each client:
Claude Desktop
Add to ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"pdf4dev": {
"url": "https://pdf4.dev/api/mcp",
"headers": {
"Authorization": "Bearer p4_live_xxx"
}
}
}
}Cursor
Add to .cursor/mcp.json in your project root:
{
"mcpServers": {
"pdf4dev": {
"url": "https://pdf4.dev/api/mcp",
"headers": {
"Authorization": "Bearer p4_live_xxx"
}
}
}
}VS Code (Copilot)
Add to .vscode/settings.json:
{
"mcp": {
"servers": {
"pdf4dev": {
"url": "https://pdf4.dev/api/mcp",
"headers": {
"Authorization": "Bearer p4_live_xxx"
}
}
}
}
}Windsurf
Add to ~/.codeium/windsurf/mcp_config.json:
{
"mcpServers": {
"pdf4dev": {
"url": "https://pdf4.dev/api/mcp",
"headers": {
"Authorization": "Bearer p4_live_xxx"
}
}
}
}ChatGPT
Go to Settings → Connected apps → Add MCP server, enter the URL https://pdf4.dev/api/mcp, and add the header Authorization: Bearer p4_live_xxx
Step 3: Start generating
That's it. Your AI agent now has access to 7 PDF tools. The API key is passed as a parameter to each tool call, no OAuth flow, no token management.
The 7 MCP tools
| Tool | What it does |
|---|---|
render_pdf | Generate a PDF from a template or raw HTML with Handlebars {{variables}} |
list_templates | List all your saved templates |
get_template | Get full template details including HTML source |
create_template | Create a new HTML template |
update_template | Modify an existing template |
delete_template | Remove a template |
list_logs | View your PDF generation history |
Real-world examples
Generate an invoice
"Generate an invoice PDF for Acme Corp. Invoice #INV-042, date March 8 2026, item: Annual subscription, amount: $4,500."
The agent calls render_pdf with your invoice template and the data you provided. In seconds, you get a downloadable PDF.
Create a template from scratch
"Create a certificate template with fields for recipient name, course title, completion date, and instructor name. Use a clean, modern design with a blue accent color."
The agent writes the full HTML/CSS, then calls create_template to save it. You can then use this template for all future certificates.
Batch generation
"Generate certificates for these 5 people: Alice Johnson (React Fundamentals), Bob Smith (Advanced TypeScript), Carol Lee (System Design), David Kim (Cloud Architecture), Eve Chen (Data Engineering). All completed on March 1, 2026."
The agent calls render_pdf five times with different data, producing five distinct PDFs.
Debug a failed generation
"Show me my last 10 PDF generations. Were there any failures?"
The agent calls list_logs and presents a formatted summary with status, timing, and error details for any failures.
Iterate on design
"The invoice template looks good, but add a QR code placeholder and move the total to the bottom right. Also increase the font size of the company name."
The agent calls get_template to read the current HTML, modifies it, and calls update_template. No manual coding needed.
Why MCP beats traditional API integration
| Aspect | Traditional API | MCP |
|---|---|---|
| Setup time | Hours (read docs, write code, handle errors) | 3 minutes (paste config, start talking) |
| Learning curve | Learn API endpoints, auth, request format | Zero, use natural language |
| Error handling | You write retry logic, validation | Agent handles retries and edge cases |
| Iteration speed | Edit code → test → debug → repeat | "Make the header bigger" → done |
| Template design | HTML/CSS knowledge required | Describe what you want |
MCP doesn't replace the REST API, it adds a natural language layer on top. For production pipelines, you'll still want direct API calls. But for template design, one-off generations, and prototyping, MCP is dramatically faster.
Technical details
PDF4.dev's MCP server uses Streamable HTTP transport (the latest MCP standard). Key details:
- Endpoint:
https://pdf4.dev/api/mcp - Auth: API key passed as a parameter to each tool call (no OAuth)
- PDF format: Returned as base64-encoded string with metadata (size, duration)
- Templates: Full Handlebars support with
{{variables}} - Page formats: A4, Letter, A4 Landscape, Letter Landscape, Square, or custom dimensions
Getting started
- Create a free account
- Generate an API key
- Add the MCP config to your AI client
- Try: "Generate a simple invoice PDF for $100"
The full integration guide with all client configs and tool documentation is at pdf4.dev/ai-integration.
If you prefer direct API calls, check out the interactive API docs or the OpenAPI spec.
Free tools mentioned:
Start generating PDFs
Build PDF templates with a visual editor. Render them via API from any language in ~300ms.