Optical Context MCP
Compress large, visually structured OCR-heavy PDFs into retrievable dense packed images for agent workflows.
Read a local PDF from the host and run Mistral OCR (requires MISTRAL_API_KEY).
Recompose OCR text and embedded figures into dense packed PNGs, optionally using adaptive sizing with ML runtime.
Create a retrievable compression job and store artifacts under the system temp directory.
Load a job's saved manifest metadata via job_id.
Fetch one or more packed PNG images from a stored job via job_id, with limit and start_index.
Return up to 30 packed images inline by default (inline_images parameter) and control chars per image (chars_per_image).
Designed for operating manuals, scanned handbooks, catalogs, and slide decks; skip for tiny or clean text-native PDFs.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Optical Context MCPcompress the PDF at ./documents/report.pdf"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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
Related MCP server: VisionSieve MCP
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.
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:
986x1084example 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 optical-context-mcpInstall with the adaptive sizing runtime:
python -m pip install "optical-context-mcp[ml]"Run without installing:
uvx optical-context-mcpMISTRAL_API_KEYis required forcompress_pdfpacked images are always stored locally under the system temp directory
compress_pdfreturns up to30packed images inline by defaultthe adaptive sizing checkpoint is bundled with the package
adaptive sizing activates automatically when
torchandtorchvisionare availableset
OPTICAL_CONTEXT_DISABLE_ADAPTIVE_SIZING=1to force the legacy fixed sizingset
OPTICAL_CONTEXT_ADAPTIVE_MODEL_PATH=/path/to/model.ptto override the bundled checkpoint
For pinned shared setups:
uvx --from optical-context-mcp==0.1.5 optical-context-mcpRun
Default transport is stdio:
optical-context-mcpClaude Code
Register the server in a project:
claude mcp add -s project optical-context -- uvx optical-context-mcpTypical use:
call
compress_pdfinspect the returned manifest
fetch packed images with
get_packed_images
MCP Tools
compress_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 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
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
uv venv --python /opt/homebrew/bin/python3.11 .venv
uv pip install --python .venv/bin/python -e ".[dev]"
.venv/bin/python -m pytestPublishing
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.
Available Tools
3 toolscompress_pdfCompress PdfC
Read a local PDF, run Mistral OCR, recompose it into dense packed PNG images, and create a retrievable compression job.
| Name | Required | Description | Default |
|---|---|---|---|
| pdf_path | Yes | ||
| inline_images | No | ||
| chars_per_image | No |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the full burden. It usefully discloses the OCR dependency (an external Mistral service, implying network/cost implications) and that the output is a retrievable job, but it omits permissions, cost/rate limits, whether existing output is overwritten, and synchronous vs. asynchronous behavior.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
A single front-loaded sentence listing the pipeline in execution order, with no filler. It is slightly dense but every clause conveys a distinct step.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a tool with three undocumented parameters, no annotations, and no output schema, the description should explain the tuning knobs and how the returned job is consumed. It leaves the caller unable to set inline_images/chars_per_image meaningfully or know what the job handle is.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 0%, so the description must compensate for all three parameters, and it does not. pdf_path, inline_images, and chars_per_image are never named or explained; 'dense packed PNG images' only loosely gestures at the packing knobs without mapping to any parameter.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description names a specific multi-step operation (read PDF, OCR, pack PNGs, create job) rather than restating the name 'compress_pdf'. It implicitly distinguishes itself from the retrieval siblings get_job_manifest and get_packed_images by being the creator of the job, though it never explicitly names them.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
There is no explicit when-to-use guidance, no prerequisites (e.g., a running OCR service, local file access assumptions), and no mention of when to prefer the sibling retrieval tools. Usage is only inferable from the pipeline description.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
get_job_manifestGet Job ManifestC
Load the saved manifest for a previously compressed PDF job.
| Name | Required | Description | Default |
|---|---|---|---|
| job_id | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries the full burden. 'Load' implies a read, but it says nothing about behavior if job_id is unknown or expired, whether the manifest persists across sessions, or what permissions are needed.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
A single front-loaded sentence with no filler. It is efficient, though its brevity borders on under-specification rather than tight editing.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
With no annotations, no output schema, and an undocumented parameter, the description should explain what a 'manifest' contains and what failure looks like. It leaves the return shape and error semantics entirely unspecified.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema coverage is 0% and the single job_id property has no description, so the description must compensate. It does add one real semantic constraint — the job must be a previously compressed PDF job — but says nothing about the identifier's format or where the agent obtains it.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
States a specific verb (Load) and resource (saved manifest) scoped to a previously compressed PDF job. An agent can distinguish this read of a prior job's artifact from the sibling compress_pdf write path, though it never names the siblings explicitly.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Only implied usage: the phrase 'previously compressed PDF job' hints that compress_pdf must have run first, but there is no explicit when-to-use, no when-not-to-use, and no mention of the alternative get_packed_images.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
get_packed_imagesGet Packed ImagesC
Return one or more previously generated packed PNG images for a stored job.
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | ||
| job_id | Yes | ||
| start_index | No |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries the full behavioral burden. It implies a read of existing output, but says nothing about what happens if the job_id is unknown, whether the images are returned as URLs, paths, or binary data, or how failure is surfaced.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
A single efficient sentence with the resource and target scope front-loaded. It is not padded, though it is arguably too terse to earn top marks.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
With no annotations, no output schema, and three parameters at 0% description coverage, the definition is under-specified: it does not explain the return shape (one image vs many, and in what form) or how limit/start_index paginate results.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 0% and the description never mentions any of the three parameters. 'One or more' loosely gestures at limit, but limit, start_index, and their defaults/pagination semantics are entirely undocumented in both schema and description.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description states a concrete verb ('Return') and resource ('packed PNG images'), plus the scope constraint that they are previously generated for a stored job. It is clearly distinguishable from compress_pdf and get_job_manifest, though it never names those siblings.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
There is no explicit when-to-use guidance, no prerequisites (e.g. a job must have completed), and no mention of alternatives or when not to call it. The phrase 'for a stored job' only weakly implies the usage context.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
3 tool updates
v0.1.4- First observed
compress_pdf - First observed
get_job_manifest - First observed
get_packed_images
TDQS
Scored across 3 tools
Each tool has a distinct purpose: compress_pdf initiates processing, get_job_manifest retrieves metadata, and get_packed_images fetches image outputs. The verbs and objects clearly differentiate them.
All tools follow a consistent verb_noun pattern (compress_pdf, get_job_manifest, get_packed_images) with snake_case, using standard verbs like 'compress' and 'get'.
With only 3 tools, the set is minimal but covers the core lifecycle. However, it feels thin for a server that performs OCR, compression, and job management; additional tools like listing jobs or deleting outputs might be expected.
The tools cover creating a compression job, retrieving its manifest, and fetching packed images. Notable gaps include no tool to list all jobs, check job status, or delete a job, which limits lifecycle management.
Maintenance
Related MCP Connectors
Image & PDF tools for AI agents: compress, convert, resize, PDF, AI vision, pipeline.
PDF tools for agents: compress to a size, Arabic + English OCR, Office conversion, JSON extraction.
Document conversion and OCR for AI agents: PDF, Office docs, images to text.
Compress PDFs to exact target sizes (82-93% smaller). Tools: compress_pdf, optimize_pdf, inspect_pdf
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceRenders large text blobs as dense PNG image pages via pxpipe, enabling vision models to read content at ~3x token efficiency with a single inline image block.MIT
- AlicenseAqualityAmaintenanceEnables text-first agents to inspect images via focused questions, returning compact, checked evidence packets. Reduces visual context by ~90% while preserving expected fields.1MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to analyze, compress, and verify PDFs while preserving text, vectors, and document structure, with configurable presets and target-size limits.1MIT
- AlicenseAqualityCmaintenanceEnables AI agents to extract, analyze, and manipulate images, PDFs, video, and audio while conserving context through downscaling, truncation, and frame/page caps.22MIT