# MCP server (/docs/guides/mcp)

> Connect Claude, Cursor, VS Code, n8n and other MCP clients to Druckling so AI agents can render documents and build templates with your API key.

Druckling hosts a [Model Context Protocol](https://modelcontextprotocol.io) server, so AI agents can work with your templates and documents directly. An agent can look up a template's data contract, render a PDF and hand you the link, or build a new template from a starter, preview it with Typst and publish it, using the same validated edit operations as the editor.

There's nothing to install or run: point your MCP client at the endpoint and authenticate with an API key.

## Endpoint [#endpoint]

```txt
https://druckling-nine.vercel.app/api/mcp
```

- **Transport:** Streamable HTTP.
- **Authentication:** a Druckling API key, as `Authorization: Bearer dr_test_…` or in an `x-api-key` header. The server doesn't offer OAuth sign-in; clients that can't send a header can connect through `mcp-remote` (see [Claude Desktop](#set-up-your-client)).
- **Per request:** every request is authenticated with the key it carries, so revoking a key in **Developers › API keys** cuts the agent off right away.

**Settings › AI tools (MCP)** in the dashboard shows the endpoint and ready-to-paste snippets for the clients below.

## Choose an API key [#choose-an-api-key]

The key decides what the agent can do. Tools the key isn't allowed to use aren't listed at all, so the agent never plans around them.

| Key | Tools |
| --- | --- |
| **Render only** | `render_document`, `get_document`, `list_documents` |
| **Full access** | All of the above, plus `list_templates`, `get_template`, `template_reference`, `create_template`, `get_template_draft`, `edit_template`, `preview_template`, `publish_template` |

Start with a **test key** (`dr_test_…`): test renders are free and don't count toward your quota. Switch to a live key when the agent's output looks right. Create keys in **Developers › API keys**; see [Authentication](/docs/authentication) and [Test mode](/docs/concepts/test-mode).

A render-only key can't list or read templates, so tell the agent which template slug to use and what data it takes.

<Callout type="warn" title="Templates are shared between modes">

Test mode separates documents and usage, not templates. A full-access test key can edit and publish the same templates your live renders use. Give an agent a render-only key unless you want it to change templates.

</Callout>

## Set up your client [#set-up-your-client]

Replace `dr_test_…` with your own key.

<Tabs items={["Claude Code", "Claude Desktop", "Cursor", "VS Code", "n8n", "Other clients"]}>
<Tab value="Claude Code">

Run this in a terminal. Add `--scope user` to use it in every project.

```bash
claude mcp add --transport http druckling https://druckling-nine.vercel.app/api/mcp --header "Authorization: Bearer dr_test_…"
```

To share the server with your team, commit a `.mcp.json` instead. Each person sets `DRUCKLING_API_KEY` in their environment:

```json title=".mcp.json"
{
  "mcpServers": {
    "druckling": {
      "type": "http",
      "url": "https://druckling-nine.vercel.app/api/mcp",
      "headers": { "Authorization": "Bearer ${DRUCKLING_API_KEY}" }
    }
  }
}
```

</Tab>
<Tab value="Claude Desktop">

**Custom connector.** In Claude (desktop or claude.ai), open **Settings › Connectors › Add custom connector**, paste the endpoint, choose **No sign-in** and add the request header `authorization` with the value `Bearer dr_test_…`. Request headers on custom connectors aren't available to every Claude organization yet.

**Without request headers**, add the server to `claude_desktop_config.json` through [`mcp-remote`](https://www.npmjs.com/package/mcp-remote), which needs Node.js, then restart Claude Desktop:

```json title="claude_desktop_config.json"
{
  "mcpServers": {
    "druckling": {
      "command": "npx",
      "args": ["-y", "mcp-remote", "https://druckling-nine.vercel.app/api/mcp", "--header", "Authorization:${AUTH_HEADER}"],
      "env": { "AUTH_HEADER": "Bearer dr_test_…" }
    }
  }
}
```

Keep `Authorization:${AUTH_HEADER}` without spaces: it works around an argument bug on Windows.

</Tab>
<Tab value="Cursor">

Add the server to `~/.cursor/mcp.json` (all projects) or `.cursor/mcp.json` (this project):

```json title="~/.cursor/mcp.json"
{
  "mcpServers": {
    "druckling": {
      "url": "https://druckling-nine.vercel.app/api/mcp",
      "headers": { "Authorization": "Bearer ${env:DRUCKLING_API_KEY}" }
    }
  }
}
```

`${env:DRUCKLING_API_KEY}` keeps the key out of the file. You can also paste the key in its place.

</Tab>
<Tab value="VS Code">

Add the server to `.vscode/mcp.json`. With an input, VS Code asks for the key the first time the server starts instead of storing it in the file:

```json title=".vscode/mcp.json"
{
  "inputs": [
    { "type": "promptString", "id": "druckling-api-key", "description": "Druckling API key", "password": true }
  ],
  "servers": {
    "druckling": {
      "type": "http",
      "url": "https://druckling-nine.vercel.app/api/mcp",
      "headers": { "Authorization": "Bearer ${input:druckling-api-key}" }
    }
  }
}
```

</Tab>
<Tab value="n8n">

On an **AI Agent** node, add the **MCP Client Tool** and fill in:

| Field | Value |
| --- | --- |
| Endpoint | `https://druckling-nine.vercel.app/api/mcp` |
| Server Transport | HTTP Streamable |
| Authentication | Bearer Auth, with the key as the token (or Header Auth: `x-api-key` = `dr_test_…`) |
| Tools to Include | All, or Selected, e.g. only `render_document` |

Outside an agent, the **MCP Client** node calls one tool directly with the same settings. For workflows that don't involve an agent, the [Druckling n8n node](/docs/guides/n8n) is usually simpler.

</Tab>
<Tab value="Other clients">

Any MCP client that supports Streamable HTTP and custom headers works with two settings:

- **URL:** `https://druckling-nine.vercel.app/api/mcp`
- **Header:** `Authorization: Bearer dr_test_…` (or `x-api-key: dr_test_…`)

For a client that only runs local (stdio) servers, run the server through `mcp-remote` as shown for Claude Desktop:

```bash
npx -y mcp-remote https://druckling-nine.vercel.app/api/mcp --header "Authorization:${AUTH_HEADER}"
```

with `AUTH_HEADER` set to `Bearer dr_test_…` in the client's environment for the server.

</Tab>
</Tabs>

## Tools [#tools]

The server exposes tools only, no resources or prompts. When a client connects, the server also sends instructions that tell the agent the key's mode and access level and the workflow below.

| Tool | What it does | Inputs | Key |
| --- | --- | --- | --- |
| `render_document` | Renders a published template and returns the document id, status, page count and a time-limited signed download URL. E-invoice templates produce their Factur-X PDF or XRechnung or Peppol XML. | `template`, `data`; optional `version`, `filename`, `format` (`pdf`, `png`, `xml`), `async`, `language` | Render only |
| `get_document` | Gets a document: status, pages, a fresh signed URL, the error with its field if it failed, and its timeline. | `id` | Render only |
| `list_documents` | Lists recent documents of the key's mode, newest first. | optional `status`, `template`, `limit` (1–100, default 20), `cursor` | Render only |
| `list_templates` | Lists templates with slug, name, status, latest version, required fields and languages. | optional `search`, `status` (`draft`, `published`) | Full access |
| `get_template` | Gets a template's data contract: JSON Schema, required fields, complete `sample_data`, languages and published versions. | `template`; optional `version` | Full access |
| `template_reference` | Explains template strings, filters, variables, every block type and the edit operation formats. | none | Full access |
| `create_template` | Creates a draft, blank or from a starter such as `invoice-standard` or `packing-slip`. | `name`; optional `starter` | Full access |
| `get_template_draft` | Reads the editable draft: the document JSON with block ids, its `draft_revision`, validation issues and an outline. | `template` | Full access |
| `edit_template` | Applies edit operations to the draft, in order and atomically: one invalid op rejects the whole call. | `template`, `base_revision`, `ops` (1–200) | Full access |
| `preview_template` | Compiles the draft with Typst without saving anything: page count, the pages each block lands on, errors and warnings per block. | `template`; optional `data`, `language` | Full access |
| `publish_template` | Publishes the draft as a new immutable version, after checking for validation errors and a clean Typst render. | `template`, `base_revision`; optional `note` | Full access |

Tools that only read are annotated as read-only, and `publish_template` as destructive, so clients that support annotations can auto-approve reads and ask before publishing.

### How agents use them [#how-agents-use-them]

- **Render a document:** `list_templates` → `get_template` → `render_document` with `data` that matches the schema. For large documents, `render_document` with `async: true`, then `get_document` until the status is `rendered` or `failed`.
- **Build or change a template:** `template_reference` once → `create_template` → `get_template_draft` → `edit_template` → `preview_template` → `publish_template` → `render_document`.

Drafts never affect renders until they're published. Every `edit_template` and `publish_template` call passes the `draft_revision` it last read as `base_revision`; if someone changed the draft in the meantime, the call fails with `stale_revision` and the agent re-reads the draft.

Failed calls come back as tool errors the agent can act on: the message, the error `code` and `field`, every offending field (for example each schema mismatch or broken e-invoice rule), and a hint for the next step. See [Errors](/docs/concepts/errors) for the codes.

## Example prompts [#example-prompts]

- "Which templates do I have, and what data does invoice-standard need?"
- "Render invoice-standard for Northwind Ltd., 12 Pier St, Leeds: invoice INV-2042, due November 22, 12 hours of design system audit at 180 and one brand workshop at 640, plus 8% tax. Send me the link."
- "Render the invoice again in German."
- "Which documents failed today, and why?"
- "Create a packing slip from the packing-slip starter with our return address in the footer. Preview it with 40 items to check the page breaks, then publish it."

## Limits [#limits]

- **60 seconds per request.** A synchronous `render_document` or a `preview_template` has to finish within that time; render large documents with `async: true`.
- **Rate limit.** Every MCP request, including the client's `initialize` and `tools/list`, is authenticated with the key and counts toward its rate limit of 120 requests a minute, shared with `/v1`.
- **Quota.** Live renders count toward your plan's monthly documents; test renders don't. See [Plans and limits](/docs/concepts/plans-and-limits).

Tool calls appear in **Developers › Logs** next to your API requests, with method `MCP`, the endpoint `/api/mcp/<tool>` and an HTTP-style status (for example `422` for a payload that doesn't match the schema).

## Security [#security]

- **Use a test key while trying it out**, and a **render-only key** for agents that only need to render: they can't see or change templates.
- **Keep keys out of committed files** with environment variables or input prompts, as in the snippets above.
- **Signed URLs are links anyone can open** until they expire. They end up in the agent's conversation, so treat transcripts accordingly. See [Documents](/docs/concepts/documents).
- **Your MCP client's AI provider sees the tool calls**, including the payload data you render. Druckling's EU-only, zero-retention inference applies to Druck, the AI assistant built into Druckling, not to the client you connect.
- **Revoke a key** in **Developers › API keys** to cut an agent off. The next request fails with `401`.

## Next steps [#next-steps]

<Cards>
  <Card title="Variables" href="/docs/concepts/variables">
    How a template's JSON Schema and sample data are derived.
  </Card>
  <Card title="n8n" href="/docs/guides/n8n">
    Render documents in workflows with the Druckling node.
  </Card>
  <Card title="Create a document" href="/docs/api-reference/documents/create">
    The API request behind render_document.
  </Card>
</Cards>
