This server turns long, visually dense PDFs into compressed image sets that preserve layout and structure. It wraps Mistral OCR behind three MCP tools: compress_pdf reads a local file and runs extraction plus recomposition, get_job_manifest returns metadata about the packed output, and get_packed_images fetches the resulting PNGs in batches. It bundles an adaptive sizing model that attempts to estimate figure dimensions intelligently, falling back to fixed sizing when the ML runtime is absent. Reach for it when you're working with operating manuals, scanned handbooks, or technical documents where visual grouping matters more than clean text extraction. Artifacts live in the system temp directory and jobs are identified by UUID for follow-up retrieval.
Compress OCR-heavy PDFs into dense packed images so agents can work with long visual documents.
Optical Context MCP is built for one specific job: turning large, visually structured PDFs into a smaller set of retrievable packed images for agent workflows.
It reads a local PDF, runs OCR with Mistral, recomposes the extracted text and figures into dense PNGs, and exposes those artifacts over MCP for batch retrieval.
Use it for:
Skip it for:
The image below shows a real local validation run on a public research paper with dense text, figures, charts, and page-level visual structure. The packed image on the right consolidates the seven source pages shown on the left.
Example local run facts from the generated manifest:
986x1084536,697 bytesThis example shows the intended workflow: take a long, visually structured PDF and compress it into a smaller set of retrievable packed images that still preserve the visual structure of the source.
python -m pip install optical-context-mcp
Install with the adaptive sizing runtime:
python -m pip install "optical-context-mcp[ml]"
Run without installing:
uvx optical-context-mcp
MISTRAL_API_KEY is required for compress_pdfcompress_pdf returns up to 30 packed images inline by defaulttorch and torchvision are availableOPTICAL_CONTEXT_DISABLE_ADAPTIVE_SIZING=1 to force the legacy fixed sizingOPTICAL_CONTEXT_ADAPTIVE_MODEL_PATH=/path/to/model.pt to override the bundled checkpointFor pinned shared setups:
uvx --from optical-context-mcp==0.1.4 optical-context-mcp
Default transport is stdio:
optical-context-mcp
Register the server in a project:
claude mcp add -s project optical-context -- uvx optical-context-mcp
Typical use:
compress_pdfget_packed_imagescompress_pdf: run OCR plus recomposition and create a stored jobget_job_manifest: load metadata for an existing jobget_packed_images: fetch one or more packed PNGs from an existing jobflowchart LR
A["Local PDF"] --> B["Mistral OCR"]
B --> C["Page markdown + embedded images"]
C --> D["Recomposition engine"]
D --> E["Dense packed PNG images"]
E --> F["Stored job artifacts"]
F --> G["Agent fetches manifest or image batches over MCP"]
For many vision-capable agents, that is a better intermediate format than a plain OCR dump.
uv venv --python /opt/homebrew/bin/python3.11 .venv
uv pip install --python .venv/bin/python -e ".[dev]"
.venv/bin/python -m pytest