fast-paddleocr-mcp
Extracts text from images using PaddleOCR and outputs results in markdown format, optimized for fast inference with GPU auto-detection.
README
PaddleOCR-MCP
PaddleOCR MCP (Model Context Protocol) server and CLI tool that extracts text from images and outputs results in markdown format. Optimized for fast inference with GPU auto-detection.
MCP Server Configuration
The MCP (Model Context Protocol) server allows integration with MCP clients like Cursor, Claude Desktop, etc.
Use uvx directly (no installation required, automatically downloads from PyPI):
{
"mcpServers": {
"fast-paddleocr-mcp": {
"command": "uvx",
"args": ["fast-paddleocr-mcp"]
}
}
}
MCP Tool: ocr_image
The server provides a single tool called ocr_image that:
- Input:
image_path(string) - Path to the input image file - Output: Returns the path to the generated markdown file containing OCR results
- Automatic optimizations: All performance optimizations are applied automatically with intelligent fallback
- Default language: Uses 'ch' (Chinese and English) by default for maximum compatibility
Example: When called with image_path: "photo.png", it returns "photo.png.md" containing the recognized text.
Note: The server automatically applies all optimizations (HPI, GPU acceleration, image preprocessing, etc.) and falls back to simpler configurations if needed. No configuration required from the caller.
See MCP_README.md for detailed MCP server documentation.
Usage
Basic Usage
The tool is optimized for speed by default with the following settings:
- Fast mode enabled (disables preprocessing for maximum speed)
- PP-OCRv4 (faster mobile models)
- 640px image size limit (faster processing)
- Auto GPU detection (uses GPU if available, falls back to CPU)
# Output will be saved as <image_name>.png.md
# Uses: fast mode + PP-OCRv4 + 640px + auto GPU detection
uvx --from . paddleocr-md image.png
# Specify custom output path
uvx --from . paddleocr-md image.png -o result.md
# Force CPU mode
uvx --from . paddleocr-md image.png --cpu
# Disable fast mode for better accuracy on rotated text
uvx --from . paddleocr-md image.png --no-fast
# Use PP-OCRv5 for better accuracy (slower)
uvx --from . paddleocr-md image.png --ocr-version PP-OCRv5
Default Optimization Settings
The MCP server is optimized for low latency by default with these settings:
- ✅ Fast mode enabled: Disables textline orientation classification (skips one model)
- ✅ PP-OCRv4: Uses faster mobile models (PP-OCRv4_mobile_det, PP-OCRv4_mobile_rec)
- ✅ High-Performance Inference (HPI): Automatically selects optimal inference backend
- Can reduce latency by 40-73% (e.g., 73.1% reduction on PP-OCRv5_mobile_rec)
- Supports Paddle Inference, OpenVINO, ONNX Runtime, TensorRT
- ✅ Multi-threaded CPU: Uses all available CPU cores for parallel processing
- ✅ MKL-DNN enabled: Intel CPU optimization for faster inference
- ✅ Single image batch:
rec_batch_num=1for lowest latency per image - ✅ Auto GPU detection: Automatically uses GPU if available, falls back to CPU
- GPU device selection: Uses first available GPU (gpu_id=0)
- TensorRT support: Automatically enabled via HPI if TensorRT is installed
- GPU memory: Uses default allocation (can be customized if needed)
- ✅ Automatic image preprocessing: Optimizes images before OCR for better performance
- Automatic downsampling: Resizes large images to maximum 1920px (maintains aspect ratio)
- Reduces processing time for large images significantly
- Uses high-quality LANCZOS resampling to preserve text quality
- Image sharpening: Enhances text edges for improved OCR accuracy
- Uses unsharp mask filter (radius=1, percent=150, threshold=3)
- Additional sharpening enhancement (factor=1.2)
- Makes text characters more distinct and easier to recognize
- Format conversion: Automatically converts RGBA, LA, P modes to RGB with white background
- Temporary file management: Automatically cleans up preprocessed images after OCR
- Automatic downsampling: Resizes large images to maximum 1920px (maintains aspect ratio)
- ✅ Logging disabled: Reduces overhead by disabling verbose logging
GPU Performance:
- When GPU is available, HPI automatically selects TensorRT backend for maximum performance
- TensorRT can provide 2-3x speedup compared to standard GPU inference
- First run with HPI may take longer to build the inference engine, but subsequent runs will be much faster
Requirements:
- PaddleOCR >= 2.7.0 with all latest features supported (HPI, MKL-DNN, etc.)
- No backward compatibility - requires latest PaddleOCR version
- For maximum GPU performance: NVIDIA GPU with CUDA support and TensorRT (optional)
- Sufficient GPU memory (typically 1-2GB for mobile models)
Customization Options
-
--no-fast: Disable fast mode for better accuracy- Enables textline orientation classification
- Better accuracy on rotated text, but slower
-
--cpu: Force CPU mode- Overrides auto GPU detection
- Explicitly use CPU
-
--gpu: Force GPU mode- Will fail if GPU not available
- Use when you want to ensure GPU usage
-
--ocr-version PP-OCRv5: Use better accuracy version- PP-OCRv5 has better accuracy but slower than PP-OCRv4 (default)
- Uses server models
-
--max-size <pixels>: Adjust image processing size- Default: 640px
- Larger values (e.g., 960, 1280) = better accuracy, slower
- Smaller values (e.g., 480) = faster, may reduce accuracy
-
--hpi: High-Performance Inference- Automatically selects best inference backend (Paddle Inference, OpenVINO, ONNX Runtime, TensorRT)
- Requires HPI dependencies:
paddleocr install_hpi_deps cpu/gpu - Best performance but requires additional setup
Examples
# Basic usage (uses all optimizations by default: fast + PP-OCRv4 + 640px + auto GPU)
uvx --from . paddleocr-md photo.jpg
# Process with custom output
uvx --from . paddleocr-md document.png -o extracted_text.md
# Better accuracy (slower) - disable fast mode and use PP-OCRv5
uvx --from . paddleocr-md image.png --no-fast --ocr-version PP-OCRv5 --max-size 960
# Force CPU mode
uvx --from . paddleocr-md image.png --cpu
# Use High-Performance Inference (requires HPI dependencies)
uvx --from . paddleocr-md image.png --hpi
Output Format
The tool generates a markdown file containing:
- Source image path
- List of detected text (one per line)
Example output (test_image.png.md):
# OCR Result
**Source Image:** `test_image.png`
---
- HelloPaddleOcR
- 10000C
Testing
Run tests using pytest:
# Install development dependencies
pip install -e ".[dev]"
# Run all tests
pytest
# Run tests with coverage
pytest --cov=paddleocr_cli --cov-report=html
# Run specific test file
pytest tests/test_mcp_server.py
# Run specific test class or function
pytest tests/test_mcp_server.py::TestGetOCR
pytest tests/test_mcp_server.py::TestGetOCR::test_get_ocr_default_language
The test suite includes:
- OCR instance initialization and caching
- Tool listing and definition
- OCR tool calls with various parameters
- Language parameter handling
- File validation and error handling
- Markdown output generation
- Edge cases and error scenarios
License
MIT
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。