optical-read-mcp
MCP server that converts file contents into compact, line-numbered PNG images for vision models to read, reducing token usage by roughly 7x for large files.
README
<div align="center">
optical-read-mcp
Your agent reads files as text. That's expensive. Show it a picture instead.
</div>
Loading a big file into an agent burns thousands of tokens — most of them spent on whitespace and boilerplate the model barely needs at full fidelity. But a model doesn't have to read text. Show it an image of the file and it reads with its vision encoder instead, where a single token is worth roughly ten text tokens.
optical-read-mcp is a small MCP server that
does exactly that. Hand it a path; it hands back a dense, line-numbered picture of
the file; and a high-resolution vision model — Claude Fable 5, Opus 4.8, Sonnet 5,
GPT-5.6 Sol — reads roughly 7× more code per token.
<div align="center"> <img src="docs/density-comparison.png" alt="the same file, as text vs. as a packed image" width="900"> </div>
The trick isn't mine. It's DeepSeek-OCR's contexts optical compression, popularized by Sean Goedecke's write-up. This just points it at the thing agents do all day long: reading files.
The gist
- Read("app/router.py") → ~8,000 tokens of text in your context
+ ReadMassive("app/router.py") → one small PNG the model reads for ~1,100
Same shape as the Read tool you already use — a path, or a list of paths. What comes back is a picture the model treats as the file's actual contents, line numbers and all.
Use it in Claude Code
The repo ships a project .mcp.json, so it's two steps:
uv sync
Open the folder in Claude Code, approve the optical-read server when it asks
(/mcp to check), and you're set. Ask it to read something big and it'll reach for
ReadMassive on its own.
Any other MCP client:
{
"mcpServers": {
"optical-read": {
"command": "uv",
"args": ["run", "optical-read-mcp"]
}
}
}
What the picture looks like
Text is packed edge-to-edge into a square — no wasted margins — and every source
line is written as ¶N│code:
| means | |
|---|---|
red ¶ |
the start of a line |
green N│ |
its line number, so the model can still tell you the bug's on line 214 |
blue → |
four spaces of indentation |
Blank lines are dropped; a jump in the numbers (12 → 15) brings them back. Nothing is lost — the exact source is recoverable, and the test suite checks that on every run. Full spec in docs/FORMAT.md.
[!NOTE] The model looks at the image. It should never OCR it with code — that would just turn the pixels back into the text tokens you were trying to avoid.
One rule makes or breaks this: pages stay square and under 1560px. Vision pipelines quietly downscale anything larger, and that downscale smears a 5px glyph into mush. Keep both sides small and the model reads it crisp and native.
Does it really save 10×?
No, and it won't pretend to. DeepSeek's headline number is measured inside its own OCR encoder. What you actually save depends on how your reading model counts image tokens, so every read reports the real figure:
| reading model | how it sees images | what you save |
|---|---|---|
| Claude Fable 5 · Opus 4.8 · Sonnet 5 | native, up to 2576px | ~7× on real code |
| GPT-5.6 Sol | downscales to a 768px short edge | works, but less |
| DeepSeek-OCR | its own 16× compressor | ~10× (the dream) |
On a small file it's a loss — the image has a fixed overhead a few hundred
tokens can't beat — and the tool says so and points you back to plain Read. This
earns its keep on large files, and on reading a whole pile of them at once.
The three tools
ReadMassive(paths)— the main event. One path or many, cached by mtime, rendered in parallel.ReadMassiveText(text)— same idea for a blob you already have in hand: a giant tool output, pasted logs, a fetched doc.ReadMassiveEstimate(paths)— just the token and cost math, no pixels, for when you'd rather decide before committing the context.
Under the hood
Pure Python: Pillow for the rendering, the
official MCP SDK for the server. A monospace font is bundled, so it renders
identically on macOS, Linux and Windows with nothing to install. The whole thing
is four small files, and the tuning knobs live at the top of render.py.
src/optical_read_mcp/
server.py the MCP tools
render.py text → packed, square, line-numbered PNG ← the interesting bit
tokens.py per-model token & dollar math
fonts.py finding a monospace font, anywhere
uv run --with pytest pytest runs the tests; CONTRIBUTING.md
covers the rest.
Credits
Standing on the shoulders of:
- DeepSeek-OCR — Contexts Optical Compression
- Sean Goedecke — Should LLMs just treat text content as an image?
- George Mandis — speeding up audio to pay OpenAI less, the same idea in a different key
<div align="center">
Built by hyprcat · MIT
</div>
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。