What the MCP server does
The agent talks to the MCP server, the server calls the CastPDF API with your key, and you get a signed link to the finished PDF.
The Model Context Protocol (MCP) is an open standard that lets an agent use outside tools. An MCP server lists its tools, with a name, a description and the input each one takes. The agent’s app (the MCP client) starts the server, shows the tools to the model, and runs one when the model decides it is needed. The CastPDF MCP server is a small Node.js program that offers six tools, and turns each call into an ordinary request to the API.
- Your AI agentClaude, Cursor, VS Code
- MCP server@castpdf/mcp on your machine
- CastPDF APIrenders with your template
- Your PDFa signed link that expires
Nothing new runs on our side: the tools use the same endpoints as your own code, with the same limits and the same plan. The model never sees your API key, and the file never travels through the conversation. A tool returns a private link, and the agent shares that link with you.
Set it up in a few minutes
- Create a test key. In the dashboard, open Connect, then API, and create a key that starts with
cpdf_test_. Test documents are free and carry a watermark. - Add the server to your client. Paste the configuration for your client below, with your key in
CASTPDF_API_KEY. You need Node.js 20 or newer fornpx. - Restart the client. The client starts the server and lists its six tools. In Claude Code,
/mcpshows whether it is connected. - Ask for a document. Try "Which CastPDF templates do I have?", then ask for a test PDF of one of them with your own data.
{
"mcpServers": {
"castpdf": {
"command": "npx",
"args": ["-y", "@castpdf/mcp"],
"env": { "CASTPDF_API_KEY": "cpdf_test_..." }
}
}
}claude mcp add castpdf --env CASTPDF_API_KEY=cpdf_test_... -- npx -y @castpdf/mcp{
"mcpServers": {
"castpdf": {
"command": "npx",
"args": ["-y", "@castpdf/mcp"],
"env": { "CASTPDF_API_KEY": "cpdf_test_..." }
}
}
}{
"inputs": [
{ "type": "promptString", "id": "castpdf-api-key", "description": "CastPDF API key", "password": true }
],
"servers": {
"castpdf": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@castpdf/mcp"],
"env": { "CASTPDF_API_KEY": "${input:castpdf-api-key}" }
}
}
}Claude Desktop reads claude_desktop_config.json (Settings, Developer, Edit Config). Cursor reads ~/.cursor/mcp.json for every project or .cursor/mcp.json for one. VS Code reads .vscode/mcp.json, and its inputs entry asks for the key once instead of keeping it in the file. On Windows, if Claude Desktop cannot find npx, start it through cmd /c. The setup guide covers each client in detail.
The six tools
| Tool | What the agent can do with it |
|---|---|
list_templates | See your saved templates, with their id, name and version |
get_template_fields | Learn the data a template expects, read from its sample data: each field and each list of line items |
create_pdf | Fill a template with data, or render raw HTML, and return a signed download link |
create_e_invoice | Issue a ZUGFeRD or Factur-X PDF, or an XRechnung XML, from a structured invoice |
list_documents | Show your recent documents, newest first, with their status and links |
get_document | Look up one document: its status, the error code if it failed, and a fresh link |
A good agent follows the order the server suggests: it lists your templates, reads the fields of the one you want, and only then calls create_pdf with data in the right shape. That is why it rarely guesses a field name. The e-invoice tool computes the totals and the VAT from the lines, following the EN 16931 rules, so the agent never adds up money itself. More on the formats is in the e-invoicing overview.
What you can ask
- "Which CastPDF templates do I have?"
- "Make a test PDF of the Invoice template for Ada Lovelace: 3 hours of consulting at 120 EUR."
- "Create a ZUGFeRD invoice from Muster GmbH to Kunde AG for 8 hours of consulting at 95 EUR plus 19% VAT, payable in 14 days."
- "Did my last document fail? Why?"
- "Render this HTML table as a landscape A4 PDF."
- YouMake a test invoice for Ada Lovelace, 3 hours of consulting at 120 EUR.
- AgentCalls
list_templatesand finds "Invoice", thenget_template_fieldsto learn its fields. - AgentCalls
create_pdfwith the template id, the data andtest: true. - CastPDFRenders the PDF and returns a signed link that expires.
The agent works with your saved templates and your data. It does not design templates for you: you build those in the dashboard editor, or start from one of the free templates.
Test documents unless you say otherwise
Agents try things. So create_pdf and create_e_invoice send "test": true unless you clearly ask for a live, final document, and their descriptions tell the agent to keep it that way. A test document is watermarked and never counts toward your plan.
- A
cpdf_test_key can never make a live document, whatever the agent sends. - With a live key, a live document still needs your explicit request, such as "make the final invoice".
- Live documents count like any other: one per document, whatever its page count (pricing).
- Every document shows up in your dashboard and in
list_documents, so nothing is made out of sight.
Security
- The key stays with the server. It is read from the environment and sent only to the CastPDF API, never to the model.
- Start with a test key. It cannot make live documents, so a mistake costs nothing.
- Keep keys out of shared files. Never commit a config file that holds a key; VS Code inputs and the Claude Code command keep it out of your project.
- Read the tool calls. Clients show each call and its input. Check the data in a
create_pdfcall the way you would check a form. - Revoke a key in the dashboard when you stop using it. The server then gets
invalid_api_keyand makes nothing.
Download links are signed and expire. Anyone with a link can open that one document until it expires, so share links the way you would share the PDF itself.
Run it over HTTP
Most clients start the server themselves over stdio. For a client that connects over HTTP, or for one shared server, start it with --http. It then serves Streamable HTTP at /mcp and a health check at /health.
CASTPDF_API_KEY=cpdf_test_... npx -y @castpdf/mcp --http --port 3000
# MCP endpoint: http://127.0.0.1:3000/mcp
claude mcp add --transport http castpdf http://127.0.0.1:3000/mcpEvery request to that endpoint uses the server's key, so the HTTP mode is locked down by default. It listens on 127.0.0.1 only, checks the Host header against the localhost names, and refuses browser origins. To listen on another interface you must set CASTPDF_MCP_AUTH_TOKEN, which every request then sends as a bearer token; put a proxy with TLS in front, and list the public host in CASTPDF_MCP_ALLOWED_HOSTS. The server keeps no sessions, so it runs fine behind a load balancer.
MCP server, SDK or plain HTTP?
| Use | When | Start here |
|---|---|---|
| The MCP server | A person asks for documents in a chat, or an agent prepares them as part of a larger task | MCP setup guide |
| An SDK | Your application makes documents on its own, on every order, signup or month end | SDKs for Node.js and Python |
| Plain HTTP | Any other language, or a no-code tool with a web request step | API reference |
All three use the same API key, the same templates and the same plan. A common path is to try a template from the agent first, then move the same request into your code with the Node.js or Python SDK. The quickstart shows the first request without either.