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. Accepts pages as int (single page), str (range like '1-5,8,10-12'), list, or None. Returns list[TextContent | ImageContent]
grep Search for exact substring in PDF pages. Case-insensitive by default, or regex. Returns matches with page number, text, and surrounding context.

Architecture

Application Layer (server.py — MCP tools, thin routing)
    ↓ get_toc/get_pages
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 persistence, path management, parse_page_range

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

  • Dual format: each page caches both content (images as base64 strings) and ocr_content (OCR text or images)

  • Force OCR: PDF-level flag — renders page as image and OCRs it; if VLM not configured, falls back to returning the rendered image

  • 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.2.3.tar.gz (8.9 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.2.3-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: carrot_mcp_pdf-0.2.3.tar.gz
  • Upload date:
  • Size: 8.9 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.2.3.tar.gz
Algorithm Hash digest
SHA256 730704d372c34c5cad948651e923550942eaf62264d6cd8424fe87176cbf3a98
MD5 27911a863638621a3fa74cbf2bc3fe62
BLAKE2b-256 51e08e4fb4e7ca119c70c2c3782deb44cf87456e1ff640308d8a64a4d3d9a9fe

See more details on using hashes here.

File details

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

File metadata

  • Download URL: carrot_mcp_pdf-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 11.5 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.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 17f781af71611c4d008432272abec739042200f52ce1ce1ce709a4da675e494c
MD5 9ccfad3613daaf7e85f034e54457ff75
BLAKE2b-256 fdb9301ceb8c5b9e3ca666a1362383ef8195cd7ca73bd1f4eb233e6bb0bed4dd

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