Auto-compress PDFs and screenshots to Markdown before they hit Claude Code's context — 5-10x fewer tokens
Project description
mdshrink
Auto-compress PDFs and screenshots to Markdown before they hit Claude Code's context. 5-10x fewer tokens, fully local, one-line install.
What is mdshrink?
mdshrink is an MCP server that automatically converts PDFs and screenshots to compact Markdown before they hit Claude Code's context window. It preserves semantic content while reducing token usage by 5-10x.
Why?
When you attach a PDF or screenshot in Claude Code:
- A typical 20-page PDF consumes 25k-40k tokens
- A single screenshot consumes 1.5k-3k tokens per image
Most of those tokens are visual redundancy - fonts, layout, whitespace - that the model doesn't need. mdshrink extracts the semantic content and discards the bloat.
Installation
pip install mdshrink-mcp
claude mcp add mdshrink -- mdshrink
Restart Claude Code. That's it.
Usage
Once installed, Claude Code will automatically call mdshrink tools before reading PDF or image files:
compress_pdf- Converts PDFs to compact Markdowncompress_image- OCR extracts text from screenshotsget_compressed- Cache lookup (fast check)
Each conversion reports:
original_tokens- Estimated tokens for native filecompressed_tokens- Actual tokens in Markdownratio- Compression ratio (e.g., "5.2x")
What It Compresses Well
| Type | Compression | Notes |
|---|---|---|
| Text-native PDFs | 5-10x | API specs, RFCs, papers, contracts |
| Screenshots of text | 3-5x | Code, error messages, docs, terminal |
| Scanned docs | Varies | Requires OCR (future) |
What It Doesn't Compress
- Scanned/image-only PDFs (v1.1+)
- Tables with complex merged cells
- Equations and charts
- Photos where visual IS the content
- Diagrams (v1.2+ with VLM)
Troubleshooting
Tool not triggering?
/mcp
Should show:
✔ Found 1 MCP server
• mdshrink: connected (3 tools)
If not, reinstall:
claude mcp remove mdshrink
claude mcp add mdshrink -- mdshrink
Permission errors on Windows
Run PowerShell as Administrator, then:
pip install --force-reinstall mdshrink-mcp
Cache location
- Linux/macOS:
~/.cache/mdshrink/ - Windows:
%LOCALAPPDATA%\mdshrink\
Disable caching: MDSHRINK_NO_CACHE=1
Clear cache:
from mdshrink_mcp import cache
cache.clear_cache()
Uninstall
claude mcp remove mdshrink
pip uninstall mdshrink-mcp
License
MIT - See LICENSE for details.
Credits
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mdshrink_mcp-0.1.0.tar.gz.
File metadata
- Download URL: mdshrink_mcp-0.1.0.tar.gz
- Upload date:
- Size: 10.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da86c96a41a252f6e3926d9d52e7d249eff88f9e30231d63bc9169320605e08e
|
|
| MD5 |
02666df9df62195c1c2ee96f8887381d
|
|
| BLAKE2b-256 |
6933ee3758f057bfd5b5da6a3c3567c5e3d9502d97fb54afe8b54df89b35845d
|
File details
Details for the file mdshrink_mcp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mdshrink_mcp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd7a38d8bba722bc2ff21856c55e6ebd53621590cfa1c95f27d1cc984fc9e03a
|
|
| MD5 |
1208d920791d3fbd6b11ff96ff7e94a2
|
|
| BLAKE2b-256 |
ca9e71adaddcf79dc8969c9f12a5207227f7d942e65847e2d005b39fc1ab5a75
|