# Agent Doc Convert

> "Turn this HTML / CSV / JSON / PDF into the format my agent can use, and pull the tables out as JSON."

- Status: MCP package (hosted access coming soon)

## The question it answers

"Turn this HTML / CSV / JSON / PDF into the format my agent can use, and pull the tables out as JSON."

## Use it when

- You need quick, repeatable conversions with no LLM in the loop.
- You need tables out of HTML (as JSON, CSV and Markdown) or out of a text-based PDF.

## Do not use it when

- You need Pandoc-grade HTML conversion. This is a simple heuristic converter.
- The PDF is a scan (no OCR), or you need more than the first 50 pages.
- Your HTML is very large or untrusted. **Known issue in this version:** some HTML conversions slow down sharply as input grows (about 6 seconds for 560 KB of table markup; the 5 MB cap allows far worse). Keep HTML under about 500 KB.
- You need nested tables, rowspan or colspan handled well.

## Example call

There is no public HTTP route yet, so no curl example. Locally:
```bash
npx tsx src/cli.ts csv_to_json --file fixtures/sample.csv
```
MCP: `convert_document {"op":"csv_to_json","input":"name,price,in_stock\nWidget,9.99,true\nGadget,\"12,50\",false"}`. For PDFs, send base64 in `input` (`pdf_encoding` defaults to `base64`).

## Example response (trimmed; from the package's own sample)

```json
{
  "tool": "agent-doc-convert",
  "version": "0.2.0",
  "op": "csv_to_json",
  "inputBytes": 58,
  "outputBytes": 154,
  "output": "[\n  { \"name\": \"Widget\", \"price\": \"9.99\", \"in_stock\": \"true\" },\n  { \"name\": \"Gadget\", \"price\": \"12,50\", \"in_stock\": \"false\" }\n]",
  "rowCount": 2,
  "cached": false,
  "billing": { "sku": "doc_csv_to_json", "plannedPriceUsd": 0.005, "x402Enabled": false }
}
```
The converted text is always in `output` (a string, even for JSON results). Table ops and PDF ops add `tables` / `tableCount` / `pdf`. CSV values are always strings.

## Data sources and licence

None. Only what you send. No network calls.

## Freshness and caching

Results are cached on disk by operation and input hash, with no expiry. The same input always gives the same output, and cached results are marked `cached: true`.

## Honest limits

- Input max 5,000,000 bytes per item.
- PDF: first 50 pages, text layer only, headings guessed from font size, tables guessed from whitespace.
- `json_to_csv` does not guard against spreadsheet formula injection (cells starting with `=`).
- HTML to Markdown covers headings 1-3, links, bold, italic, lists, code and tables; other markup is dropped.
