> ## Documentation Index
> Fetch the complete documentation index at: https://pdfbase.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# MCP Server

> Use PDFBase as a tool for AI agents via the Model Context Protocol.

## What is MCP?

The [Model Context Protocol](https://modelcontextprotocol.io) lets AI agents use external tools. PDFBase ships an MCP server that exposes PDF operations as tools agents can call.

## Installation

```bash theme={null}
npm install -g @pdfbase/mcp
```

Or add to your agent's MCP config:

```json theme={null}
{
  "mcpServers": {
    "pdfbase": {
      "command": "npx",
      "args": ["@pdfbase/mcp"],
      "env": {
        "PDFBASE_API_KEY": "pk_live_xxx"
      }
    }
  }
}
```

## Available tools

The MCP server exposes all PDFBase API operations as agent-callable tools.

### Phase 1 — Create

| Tool               | Description                            |
| ------------------ | -------------------------------------- |
| `create_pdf`       | Generate a PDF from HTML or URL        |
| `render_template`  | Render a stored template with data     |
| `list_templates`   | List available templates               |
| `create_template`  | Create a new template                  |
| `delete_template`  | Delete a template                      |
| `create_batch`     | Create a batch job                     |
| `get_batch_status` | Check batch progress and results       |
| `get_pdf`          | Retrieve PDF metadata and download URL |

### Phase 2 — Edit + Convert

| Tool                 | Description                            |
| -------------------- | -------------------------------------- |
| `merge_pdfs`         | Merge multiple PDFs into one           |
| `split_pdf`          | Split a PDF into separate pages        |
| `watermark_pdf`      | Add text or image watermark            |
| `convert_office`     | Convert DOCX/XLSX/PPTX to PDF          |
| `generate_thumbnail` | Generate a PNG thumbnail of a PDF page |

### Phase 3 — Extract

| Tool                 | Description                                            |
| -------------------- | ------------------------------------------------------ |
| `extract_text`       | Extract text content from a PDF                        |
| `extract_ocr`        | OCR a scanned document                                 |
| `extract_tables`     | Extract structured table data                          |
| `extract_structured` | AI-powered extraction (invoice → JSON, receipt → JSON) |

### Tool examples

#### create\_pdf

```json theme={null}
{
  "name": "create_pdf",
  "input": {
    "html": "<h1>Report</h1><p>Generated by AI agent</p>",
    "format": "a4",
    "output": "url"
  }
}
```

#### render\_template

```json theme={null}
{
  "name": "render_template",
  "input": {
    "template": "invoice",
    "data": {
      "number": "INV-001",
      "customer": "Acme Corp",
      "total": "$500.00"
    }
  }
}
```

#### extract\_structured

```json theme={null}
{
  "name": "extract_structured",
  "input": {
    "source": { "pdf_id": "pdf_invoice" },
    "preset": "invoice"
  }
}
```

#### generate\_thumbnail

```json theme={null}
{
  "name": "generate_thumbnail",
  "input": {
    "pdf_id": "pdf_report",
    "page": 1
  }
}
```

## Why MCP for PDFs?

AI agents frequently need to generate documents — invoices, reports, certificates, proposals. Without a tool, agents either:

1. Generate markdown (not a PDF)
2. Write HTML and tell the user to open it (bad UX)
3. Call a complex API with no guidance (error-prone)

The MCP server wraps PDFBase's API into agent-friendly tools with clear schemas, so agents can generate production-quality PDFs as naturally as they write text.

## Agent workflow example

```
User: "Generate invoices for all unpaid orders and email them"

Agent:
1. Queries database for unpaid orders
2. Calls render_template for each order
3. Downloads PDFs from returned URLs
4. Sends emails with PDF attachments
```

The agent doesn't need to know HTML, CSS, or PDF internals. It fills in a template with structured data and gets a URL back.
