# Generate PDF table of contents: web app, CLI and MCP

## What it does
Creates a structured, clickable table of contents (TOC) for a PDF file. The tool analyses headings in the document, validates the hierarchy with a language model, and adds PDF bookmarks (and an optional TOC page) without modifying the original content.

## Inputs and limits
* Input format: PDF files only. Other formats are not supported.  
* CLI options: `--max-layers` (integer, default 3) limits the heading depth that is included; `--summarize-all-levels` (boolean, default true) controls whether every level is summarised.  
* The web page lets you choose how many heading levels (e.g., H1–H3) should appear in the TOC.  
* The service runs the AI processing in the cloud; the PDF file is not retained after the generated PDF is downloaded.

## Web app
The page “AI PDF TOC Generator – Online Tool for Clickable Table of Contents” asks you to upload a PDF file, select the desired heading levels, and then click **Generate My TOC**. After processing, you can download the updated PDF, which contains an added navigation outline (bookmarks) and a TOC page at the beginning.

## Command line (CLI)
The `Documentize.TableOfContents` plugin builds a TOC for a PDF placed in a task‑specific input folder and writes the result to the matching output folder. Use the `--max-layers` flag to control heading depth.  
```bash
# Linux / macOS (needs the .NET 10 runtime and documentize.lic next to the DLL)
export PLUGIN_INPUT_DIR=./work/input
export PLUGIN_OUTPUT_DIR=./work/output
mkdir -p "$PLUGIN_INPUT_DIR/job1"
cp sample.pdf "$PLUGIN_INPUT_DIR/job1/"
dotnet Documentize.TableOfContents.dll --task-id job1 --max-layers 1
ls "$PLUGIN_OUTPUT_DIR/job1"
```

```powershell
# Windows PowerShell
$env:PLUGIN_INPUT_DIR  = "$PWD\work\input"
$env:PLUGIN_OUTPUT_DIR = "$PWD\work\output"
New-Item -ItemType Directory -Force "$env:PLUGIN_INPUT_DIR\job1" | Out-Null
Copy-Item sample.pdf "$env:PLUGIN_INPUT_DIR\job1\"
dotnet Documentize.TableOfContents.dll --task-id job1 --max-layers 1
Get-ChildItem "$env:PLUGIN_OUTPUT_DIR\job1"
```

## MCP
The hosted MCP tool `GenerateTableOfContents` creates a TOC for a PDF reachable at a public URL. Provide the `fileUrl` parameter with the PDF link, and the service returns a PDF that includes the generated bookmarks.  
Client configuration (the key comes from your Documentize account):

```json
{
  "mcpServers": {
    "documentize": {
      "url": "https://api.documentize.app/mcp",
      "headers": {
        "Authorization": "Bearer dmk_YOUR_KEY_HERE"
      }
    }
  }
}
```

Tool call (`tools/call`). The tool returns a task id; poll `get_task_status` until it reports 200, then download the file from `uploadFileName`:

```json
{
  "name": "generate_table_of_contents",
  "arguments": {
    "fileUrl": "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
  }
}
```

## Verified

Every code sample on this page was run on 2026-11-03 and its result was checked:

- CLI with content check for TOC phrase (CLI plugin): passed in 13 s
- Generate TOC via MCP with content check (hosted MCP server): passed in 19 s
