CASE STUDY

Optical Context MCP

The same PDF, up to 85 % less context: a published MCP package packs OCR-heavy pages into a few image bundles for vision LLMs – layout, tables and drawings stay intact, and a model decides the packing density itself.

Role
Concept, development and release
Status
Open source on PyPI, 5 releases

STARTING POINT

Problem

Scanned, OCR-heavy PDFs are expensive for vision LLMs: every page takes up context as its own image, and with longer documents the window is full before the model can even start. Plain text extraction is no answer either, because layout, tables and drawings are usually the part that matters.

HOW IT WORKS

Solution & architecture

Benefit

The same document, 15 % of the context

A 22-page paper costs 11,284 tokens as text and still 6,160 as one image per page. As six packed image bundles it is 1,680 – the document fits into a context window it did not fit into before, costs a fraction per request and stays readable as an image, tables and drawings included.

  • 1,680 instead of 11,284 tokens for the same document
  • 6 image bundles instead of 22 single page images
  • Layout, tables and drawings stay intact
Bar chart: the same 22-page document needs 11,284 text tokens, 6,160 tokens as one image per page and 1,680 tokens with optical compression – 85 % less context

Compression

22 pages become six image bundles

A FastMCP server with three tools, which any MCP-capable client can plug in, runs the PDF through Mistral OCR and then packs the pages into image bundles that go to a vision LLM as a whole.

  • 3 tools for any MCP-capable client
  • Mistral OCR instead of plain text extraction
  • Up to 85 % estimated context reduction on a 22-page test document
Real output of the tool: the individual pages of a paper on the left, the packed multi-page image generated from them on the right

Model

A model decides how densely to pack

How densely pages can be packed before they stop being readable depends on the document. That call is not made by a fixed threshold but by a MobileNetV3 I trained on 9,076 reviewed images and evaluated on five independent document holdouts.

  • 9,076 reviewed training images
  • Accuracy 0.700–0.923 across 5 holdouts
  • CI with trusted publishing, five releases so far
Chart of the accuracy span from 0.700 to 0.923 across five independent document holdouts

Limits

Not every page is worth turning into an image

An image costs a flat 280 tokens, no matter how much is on it. So a page only pays off once its text costs more than that. In the test document 20 of 22 pages were above that line; the two exceptions were almost empty pages at the end. The densest page alone saved 1,868 tokens. The server does this arithmetic per page and only packs what pays off.

  • Break-even at 280 text tokens per page
  • from roughly 420 text tokens per page the image reliably pays off
  • measured on one document – not a universal value
Diagram: on a logarithmic axis of text tokens per page, two almost empty pages with 85 and 243 tokens sit below the 280-token cost of an image, pages with 420 and 2,148 tokens above it

ARCHITECTURE

The path through the system

PDF

scanned or OCR-heavy

Mistral OCR

Page recognition

Sizing model

MobileNetV3 sets the packing density

Image bundles

several pages per image

Vision LLM

far less context per document

  • Interface

    FastMCP server with 3 tools for any MCP client

  • Training

    9,076 reviewed images, 5 independent document holdouts

Delivery: CI with trusted publishing to PyPI, 5 releases so far

From PDF to an image bundle for the vision LLM

Results

less context for the same 22-page test document
up to 85 %less context for the same 22-page test document
images for the 22-page test document
6 instead of 22images for the 22-page test document
reviewed training images for the sizing model
9,076reviewed training images for the sizing model
accuracy across 5 independent document holdouts
0.700–0.923accuracy across 5 independent document holdouts

EVIDENCE & SCOPE

What is evidenced — and where the claim ends

These four fields separate my contribution, the project context, the measurement basis and the limits of the results.

My contribution
Concept, development and release of the FastMCP server, OCR and packing pipeline, and MobileNetV3 sizing model. Delivery to PyPI is automated through trusted publishing.
Team & context
The package, source code and research repository are linked publicly, and five releases document publication. The available project data does not state a team size, so none is claimed here.
Measurement basis
The sizing model was trained on 9,076 reviewed images and evaluated on five independent document holdouts. Accuracy ranges from 0.700 to 0.923 by holdout; context reduction was estimated on one 22-page test document.
Limitations
The accuracy range shows that results depend on the document. Up to 85 % context reduction is an estimate from one 22-page test document, not a universal value for every PDF; it does not establish general vision-LLM answer quality.

BUILT WITH

Tech stack

  • Python
  • FastMCP
  • Mistral OCR
  • PyTorch
  • MobileNetV3
  • Pillow
  • GitHub Actions

Does this match what you have in mind?

I build systems that are meant to run in production, not just to demo. If that matches what you have in mind, get in touch.

All case studies