How to Connect Claude to a Document Generation API
Give Claude the ability to generate invoices, contracts, certificates, and any PDF document. Connect it to DocuQueue via MCP, or call the REST API from a tool definition.
Claude outputs text but cannot emit a binary file by itself. To let Claude generate real documents, connect it to a hosted document generation service. DocuQueue renders templates with Jinja2 and converts them to PDF server-side, so there is no browser to install.
This guide covers both paths — MCP for interactive chats and tool use for production apps — with working code and a decision table.
Which way should you connect Claude to document generation?
There are two real ways to give Claude document generation, and they solve different problems. MCP wires Claude to DocuQueue once, so the tools show up in every conversation. Tool use embeds document generation inside an app you build on the Anthropic API.
| Criterion | MCP Server | Anthropic Tool Use |
|---|---|---|
| Where it runs | Claude Desktop / Claude Code | Your app (server-side Anthropic SDK) |
| Setup | One config entry, restart | Tool definition + loop in code |
| Best for | Interactive chats, ad hoc documents | Production apps, automated pipelines |
| Tools exposed | generate_document, fill_template, list_templates, batch_generate | Whatever tools you define |
| Code to write | None | ~40 lines (tool def + loop) |
TL;DR: If you want Claude itself to make documents while you chat, use MCP. If you are shipping a feature where Claude generates documents for your users, use tool use. The two are not exclusive — prototype over MCP, ship over the API.
How to add DocuQueue as an MCP server in Claude
Add the DocuQueue MCP endpoint to your client config, then restart. MCP (Model Context Protocol) is an open standard from Anthropic that lets a Claude client connect to external tool servers. DocuQueue runs one at https://docuqueue.com/mcp/sse, exposing tools like generate_document, fill_template, and list_templates.
You need a DocuQueue API key (format wp2_...) from your dashboard.
Claude Desktop
Edit claude_desktop_config.json (Settings → Developer → Edit Config) and add an mcpServers entry:
{
"mcpServers": {
"docuqueue": {
"command": "npx",
"args": [
"-y",
"mcp-remote",
"https://docuqueue.com/mcp/sse",
"--header",
"Authorization: Bearer wp2_your_key_here"
]
}
}
}
Restart Claude Desktop. A tools icon appears in the message box. Ask Claude to "create an invoice for Acme Corp, total $1,500" and it calls generate_document. The render runs on DocuQueue's servers, and Claude hands you back a download link.
Claude Code
Claude Code connects to remote MCP servers from the command line:
claude mcp add --transport http docuqueue https://docuqueue.com/mcp/sse \ --header "Authorization: Bearer wp2_your_key_here"
Run claude mcp list to confirm the connection. From then on, any Claude Code session can generate invoices, contracts, certificates, or fill PDF forms — by calling the DocuQueue tools.
How to define a document tool in the Anthropic API
Add a tool to the tools array of your Messages API call, then run the tool-use loop. When Claude calls this tool, your code reads the input, POSTs to DocuQueue, and returns the download URL.
{
"name": "generate_document",
"description": "Generate a document from a template and return a download URL. Use for invoices, contracts, certificates, letters, or any printable document.",
"input_schema": {
"type": "object",
"properties": {
"template_name": {
"type": "string",
"description": "Name of the template: 'Invoice', 'Contract', 'Certificate', 'Letter', 'Gift Voucher'"
},
"data": {
"type": "object",
"description": "Key-value pairs to fill the template fields"
}
},
"required": ["template_name", "data"]
}
}
Full tool-use loop in TypeScript
Loop until Claude stops calling tools, sending each tool_result back. The pattern: call the model with your tools, check stop_reason, and when it is tool_use, execute the tool, append the result, then call the model again.
import Anthropic from "@anthropic-ai/sdk";
const anthropic = new Anthropic();
const DOCUQUEUE_KEY = process.env.DOCUQUEUE_API_KEY!;
const tools: Anthropic.Tool[] = [
{
name: "generate_document",
description: "Generate a document from a template. Returns a download URL.",
input_schema: {
type: "object",
properties: {
template_name: {
type: "string",
description: "Invoice, Contract, Certificate, Letter, or Gift Voucher"
},
data: {
type: "object",
description: "Template field values"
}
},
required: ["template_name", "data"]
}
}
];
async function generateDocument(templateName: string, data: object): Promise<string> {
const res = await fetch("https://docuqueue.com/api/v1/templates/fill", {
method: "POST",
headers: {
"api-key": DOCUQUEUE_KEY,
"Content-Type": "application/json"
},
body: JSON.stringify({ template_name: templateName, data })
});
const json = await res.json();
return json.pdf_url;
}
const messages: Anthropic.MessageParam[] = [
{ role: "user", content: "Create an invoice for Acme Corp, $1,500, due in 30 days." }
];
while (true) {
const response = await anthropic.messages.create({
model: "claude-sonnet-4-20250514",
max_tokens: 8000,
tools,
messages
});
if (response.stop_reason !== "tool_use") {
for (const block of response.content) {
if (block.type === "text") console.log(block.text);
}
break;
}
messages.push({ role: "assistant", content: response.content });
const toolResults: Anthropic.ToolResultBlockParam[] = [];
for (const block of response.content) {
if (block.type === "tool_use" && block.name === "generate_document") {
const { template_name, data } = block.input as any;
const url = await generateDocument(template_name, data);
toolResults.push({
type: "tool_result",
tool_use_id: block.id,
content: `Document ready: ${url}`
});
}
}
messages.push({ role: "user", content: toolResults });
}
What can Claude generate with DocuQueue?
- Invoices — Line items, tax calculations, company branding
- Contracts — NDAs, lease agreements, service contracts with e-signature fields
- Certificates — Completion, achievement, recognition with custom designs
- Letters — Business correspondence, offer letters, formal communications
- Gift Vouchers — Custom values, recipient details, expiry dates
- Batch documents — Generate hundreds of documents from a data source
Which option should you choose?
Pick by where Claude runs and who owns the render.
You want Claude to make documents while you work. Use MCP in Claude Desktop or Claude Code. One config entry, no code, and generate_document is available in every chat.
You are building a product feature where Claude generates documents for users. Use Anthropic tool use. Define generate_document, run the loop on your server, and keep both API keys server-side.
You are not sure yet. Prototype over MCP to feel out how Claude writes the data and what documents your users ask for, then port the same call into a tool definition when you ship.
Start generating documents with Claude
25 free credits. No credit card required. Connect in 2 minutes.
Get your API key →