Skip to main content

FastMCP server for compressing large OCR-heavy PDFs into dense packed images for agent workflows.

Project description

Optical Context MCP logo

Optical Context MCP

FastMCP server for compressing large, OCR-heavy PDFs into dense packed images for agent workflows.

Python 3.11+ FastMCP CI MIT License

Optical Context MCP is built for one specific problem: giving agents a practical way to work with large, visually structured PDFs without sending every page individually to a vision model.

It reads a local PDF, runs OCR with Mistral, recomposes the extracted text and figures into a much smaller set of packed images, and exposes those artifacts over MCP for batch retrieval.

What It Does

  • reads a local PDF from the MCP host machine
  • extracts page markdown and embedded images with Mistral OCR
  • packs that content into dense PNGs that preserve visual grouping
  • stores a manifest and job artifacts for follow-up retrieval
  • lets an agent pull only the packed images it needs

Where It Fits

Use it for:

  • operating manuals
  • scanned handbooks
  • product catalogs
  • PDF slide decks
  • visually structured OCR-heavy documents

Skip it for:

  • tiny PDFs
  • clean text-native PDFs where normal extraction is enough
  • workflows that require exact page-faithful rendering
  • cases where OCR cost is not justified

Example Result

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.

Side-by-side comparison of original pages and the generated packed output

Example local run facts from the generated manifest:

  • source paper pages: 22
  • previewed source page range: 15 to 21
  • extracted images: 30
  • packed output images: 6
  • example packed image size: 986x1084
  • example packed image file size: 536,697 bytes

This 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.

Install

python -m pip install "git+https://github.com/ChrBoebel/optical-context-mcp.git@v0.1.2"

Run directly from GitHub with uvx:

uvx --from git+https://github.com/ChrBoebel/optical-context-mcp@v0.1.2 optical-context-mcp
  • MISTRAL_API_KEY is required for compress_pdf

Run

Default transport is stdio:

optical-context-mcp

Claude Code

Register the server in a project:

claude mcp add -s project optical-context -- uvx --from git+https://github.com/ChrBoebel/optical-context-mcp@v0.1.2 optical-context-mcp

Typical use:

  1. call compress_pdf
  2. inspect the returned manifest
  3. fetch packed images with get_packed_images

MCP Tools

  • compress_pdf: run OCR plus recomposition and create a stored job
  • get_job_manifest: load metadata for an existing job
  • get_packed_images: fetch one or more packed PNGs from an existing job

How It Works

flowchart 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"]

Why Packed Images Instead Of Just OCR Text

  • section grouping
  • table-like layout
  • captions near figures
  • visual adjacency between text and embedded graphics

For many vision-capable agents, that is a better intermediate format than a plain OCR dump.

Current Scope

  • depends on Mistral OCR
  • currently handles local file paths, not remote uploads
  • optimized for compression and retrieval, not final polished markdown generation
  • quality depends on OCR quality and the visual density of the source document

Roadmap

  • make the OCR layer provider-agnostic so different OCR backends can be swapped behind the same MCP workflow

Development

uv venv --python /opt/homebrew/bin/python3.11 .venv
uv pip install --python .venv/bin/python -e ".[dev]"
.venv/bin/python -m pytest

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

optical_context_mcp-0.1.2.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

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

optical_context_mcp-0.1.2-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file optical_context_mcp-0.1.2.tar.gz.

File metadata

  • Download URL: optical_context_mcp-0.1.2.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for optical_context_mcp-0.1.2.tar.gz
Algorithm Hash digest
SHA256 db069f90a2d04199a435bf6ccd71924de369e2d45fc0780e5667934b4940e152
MD5 61ffb628e99768c02d1f61a976bb3dca
BLAKE2b-256 cba0368140d4a0ab73d7f45de8aced67d2d03d2c58f124732d57d177fd1dbcc2

See more details on using hashes here.

Provenance

The following attestation bundles were made for optical_context_mcp-0.1.2.tar.gz:

Publisher: publish-pypi.yml on ChrBoebel/optical-context-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file optical_context_mcp-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for optical_context_mcp-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ccfb91f6c186581bad076d8b34a402607441948b99c3c876117b32652a1fd489
MD5 c375913f29ae5b985f3568e6cdab6be4
BLAKE2b-256 bde6a61d12918f475a6f400f6423d5a043d0aa1199d40bd044a6550b2230a375

See more details on using hashes here.

Provenance

The following attestation bundles were made for optical_context_mcp-0.1.2-py3-none-any.whl:

Publisher: publish-pypi.yml on ChrBoebel/optical-context-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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