Your AI coding agent can read your repo, run your tests, and refactor a module. But ask it to "add a PDF invoice to this app" and it does what you'd do: reaches for Puppeteer, writes code that won't deploy, and hands you a layout it can't actually see or test.
The Model Context Protocol fixes that by giving the agent a real tool to call. Install the Leafwright MCP server and your agent can render PDFs, manage templates, and debug failures from logs — directly, while it works.
Install
One line. STDIO transport, scoped to a single API key:
npx -y @leafwright/mcp
In Claude Code, Cursor, or Codex, add it to your MCP config with your lw_… key:
{
"mcpServers": {
"leafwright": {
"command": "npx",
"args": ["-y", "@leafwright/mcp"],
"env": { "LEAFWRIGHT_API_KEY": "lw_live_xxxxxxxx" }
}
}
}
What the agent can now do
The server exposes the Leafwright API as tools the agent can call on its own:
- Generate a PDF from HTML or a URL
- Render a template with JSON data
- Create and update templates (drafts only — humans still publish)
- Read render jobs and logs to see exactly why a render failed
- Estimate usage cost before running a batch
So a prompt like "generate a PDF invoice for order #1024 and give me the link" becomes a tool call that returns a real, signed URL — not a code suggestion you have to wire up and deploy yourself.
The part that actually matters: it can debug its own output
A code-only agent is flying blind on layout. It writes print CSS, can't see the result, and guesses. With Leafwright it doesn't have to:
- Agent renders the template → the render fails or looks wrong.
- Agent calls get render logs → reads the real failure: a font that 404'd, an asset that timed out, a CSS rule that overflowed the page.
- Agent calls fix-from-logs → gets a corrected template, re-renders, confirms it's clean.
That's a closed feedback loop. The agent fixes the document the same way it fixes code — by reading the error and trying again — instead of handing you something broken.
Safe by design
The MCP server only calls the public Leafwright API. It runs no shell commands from agent input, supports a read-only mode, and uses a single scoped key. AI drafts and revises templates; publishing always requires a human. You get the speed of an agent without handing it a footgun.
Try it
If your agent already lives in your editor, this is the fastest way to give it a capability it's missing:
npx -y @leafwright/mcp