Skip to main content

Carrot MCP PDF Server

Project description

carrot-mcp-pdf

Carrot MCP PDF Server — convert PDFs to structured markdown with optional OCR.

Installation

uv sync --all-packages

Usage

# Run as MCP server
uv run carrot-mcp-pdf

# Or via main CLI
uv run carrot-mcp pdf

# Or as Python module
uv run python -m carrot_mcp_pdf

Tools

Tool Description
version Get server version info
get_toc Get table of contents with page ranges
get_pages Convert specific pages to markdown (supports multimodal/OCR/force_ocr)
create_task Start background full PDF conversion (multimodal/force_ocr option)
get_status Check progress of background conversion task

Architecture

Application Layer (server.py — MCP tools, thin routing)
    ↓ get_toc/get_pages/create_task
Conversion Layer (converter.py — pymupdf4llm → markdown + images)
    ↓ force_ocr=True
OCR Layer (ocr.py — litellm vision API)
    ↓ multimodal=False
Cache Layer (cache.py — JSON: %APPDATA%/carrot-mcp/pdf/<md5>.json)
  • server.py — MCP tool definitions only, delegates to converter/cache

  • converter.py — PDF conversion, image processing, content parsing, VLM config

  • ocr.py — Vision model OCR via litellm (single responsibility)

  • cache.py — Cache/task persistence, path management, parse_page_range

  • Cache: %APPDATA%/carrot-mcp/pdf/<md5>.json

  • Dual format: each page caches both content (raw image bytes) and ocr_content (OCR text)

  • Force OCR: PDF-level flag — renders page as image and OCRs it; for scanned PDFs or garbled text

  • Background tasks: separate <hash>_tasks.json with progress tracking

  • Image return: images returned as MCP ImageContent attachments (no base64 truncation)

Environment Variables

Variable Default Description
CARROT_MCP_MODEL Vision model name for OCR (must be configured if using OCR)
CARROT_MCP_APIKEY API key for the vision model (must be configured if using OCR)
CARROT_MCP_PROXY HTTP proxy URL for API calls
CARROT_MCP_FORCE_MULTIMODAL true = always return images as MCP ImageContent attachments; false = always run OCR. When not set, uses tool parameter. If VLM not configured (no model/apikey), falls back to attachments with warning.

Development

# Run tests
uv run pytest tests/pdf/ -v

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

carrot_mcp_pdf-0.1.4.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

carrot_mcp_pdf-0.1.4-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file carrot_mcp_pdf-0.1.4.tar.gz.

File metadata

  • Download URL: carrot_mcp_pdf-0.1.4.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for carrot_mcp_pdf-0.1.4.tar.gz
Algorithm Hash digest
SHA256 5872bb7d1797875ebab04e2cd9453978b2239b1969937b7d6c0fffac1081a1f9
MD5 e2f25980b9c78996d2a91452cdbb24fc
BLAKE2b-256 924f9d9a84fa1421199ab7511b44903afbf50c31e94b961a9b1dc1b4caae2830

See more details on using hashes here.

File details

Details for the file carrot_mcp_pdf-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: carrot_mcp_pdf-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for carrot_mcp_pdf-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5e0911d7a88b25459640a4dff4b3b370478abf313eb0957450319c20737113c2
MD5 07455e4225989659e90f90eb335ae84e
BLAKE2b-256 b4f3f6bf46ccdb5bccb0c3f36f402bd4884c93c04ea8b6ad11d7c309e38b50c7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page