Optical Context MCP

io.github.ChrBoebel由 GitHub 账号 ChrBoebel 发布v0.1.5更新于 Oct 24, 2026

Compress OCR-heavy PDFs into dense packed images so agents can work with long visual documents.

已验证STDIO仅桌面文件与存储媒体与设计

概览

AI 生成的概览

将 OCR 密集型 PDF 压缩为密集打包的 PNG 图像,让助手能处理长篇视觉化文档。

可以做什么
压缩本地 PDF:调用 Mistral OCR 并重组内容,生成存储的密集打包 PNG 任务,可选自适应图片尺寸。查看任务:读取已有任务的清单元数据。获取图像:从任务中分批取回一张或多张打包 PNG。
适用场景
适合长篇、视觉结构复杂、OCR 密集的 PDF,例如操作手册、扫描手册、产品目录或幻灯片,让具备视觉能力的智能体使用更紧凑的图像格式。小型 PDF、纯文本 PDF 或需要精确还原页面的场景不宜使用。
运行要求
作为本地 stdio 进程在桌面运行,从 PyPI 安装(pip 或 uvx),需要 Python 运行时。compress_pdf 需要环境变量 MISTRAL_API_KEY 中的 Mistral API 密钥。可选 ML 依赖(torch、torchvision)启用自适应尺寸;产物写入系统临时目录。
安装前请注意
会将 PDF 内容发送给第三方 Mistral OCR,需注意文档保密性,OCR 调用可能产生费用。需要 MISTRAL_API_KEY 密钥。会向本地临时目录写入任务产物和打包图像。仅接受本地文件路径,不支持远程上传。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Optical Context MCP,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

[Optical Context MCP logo]

Optical Context MCP

Compress OCR-heavy PDFs into dense packed images so agents can work with long visual documents.

[PyPI version] [Python 3.11+] [FastMCP] [CI] [MIT License]

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.

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
  • optionally sizes embedded figures with a bundled technical-document model
  • stores a manifest and temp 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

bash
python -m pip install optical-context-mcp

Install with the adaptive sizing runtime:

bash
python -m pip install "optical-context-mcp[ml]"

Run without installing:

bash
uvx optical-context-mcp
  • MISTRAL_API_KEY is required for compress_pdf
  • packed images are always stored locally under the system temp directory
  • compress_pdf returns up to 30 packed images inline by default
  • the adaptive sizing checkpoint is bundled with the package
  • adaptive sizing activates automatically when torch and torchvision are available
  • set OPTICAL_CONTEXT_DISABLE_ADAPTIVE_SIZING=1 to force the legacy fixed sizing
  • set OPTICAL_CONTEXT_ADAPTIVE_MODEL_PATH=/path/to/model.pt to override the bundled checkpoint

For pinned shared setups:

bash
uvx --from optical-context-mcp==0.1.5 optical-context-mcp

Run

Default transport is stdio:

bash
optical-context-mcp

Claude Code

Register the server in a project:

bash
claude mcp add -s project optical-context -- uvx 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

mermaid
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
  • stores artifacts in the local system temp directory by default
  • optimized for compression and retrieval, not final polished markdown generation
  • quality depends on OCR quality and the visual density of the source document
  • adaptive sizing falls back safely to fixed medium image sizing when the ML runtime is absent

Roadmap

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

Feedback

Tried Optical Context in a document workflow? You can voluntarily share what worked and what got in the way using the feedback form. Include your package version, MCP client and a brief description of the document type. Do not attach private PDFs or API keys. Feedback is public on GitHub.

See the changelog for changes between published versions.

Development

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

Publishing

Keep pyproject.toml and both versions in server.json synchronized. Run the Publish PyPI workflow on the reviewed release commit. It checks the wheel, runs tests against the installed distribution, publishes to PyPI, then publishes the same version to the MCP Registry. Both use GitHub OIDC; no local publishing token is required. If only the registry job fails, rerun that failed job rather than republishing the immutable PyPI version. When a workflow correction requires a new run, select registry_only to retry registry publication without uploading the existing PyPI version again.

Create the matching GitHub release from that same commit and attach the workflow's python-distributions artifact.

来源:README.md,提交 b1eccee

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

2
  1. v0.1.5最新Sep 30, 2026
  2. v0.1.4Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分