文档解析器MCP
一种模型上下文协议(MCP)服务器,使用Docling工具包提供智能文档解析和转换功能。将任何文档(PDF、DOCX、图像、音频等)转换为干净的Markdown,用于AI处理和RAG管道。
特性
- 通用文档支持:PDF、Office文档(DOCX/XLSX/PPTX)、图像、HTML、Markdown、音频文件等
- 多条处理管道:
- 标准:通过先进的布局分析实现快速、高质量的转换
- VLM:用于复杂布局和手写内容的视觉语言模型
- ASR:用于音频转录的自动语音识别
- 智能自动检测:根据文件类型自动选择最佳管道
- 并发处理:内置作业队列,用于处理多个请求
- MCP集成:与Claude Desktop和其他MCP客户端无缝集成
- 清除Markdown输出:高质量的结构化文本,可供人工智能使用
安装
先决条件
- Python 3.9或更高版本
- 建议使用8GB+RAM
快速开始
- 克隆存储库:```bash
git clone
cd document-parser-mcp
2. **创建虚拟环境:**```bash
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- 安装依赖项:```bash
pip install -r requirements.txt
4. **安装带有可选功能的文档:**```bash
# Core Docling
pip install docling
# For Apple Silicon MLX acceleration
pip install docling[mlx]
# Optional OCR engines
pip install easyocr
用法
运行服务器
启动MCP服务器:```bash
python -m document_parser
使用自定义配置:```bash
python -m document_parser --config /path/to/config.yaml
使用调试日志记录:```bash
python -m document_parser --debug
### 配置
服务器通过以下方式配置 `config.yaml`.按键设置:```yaml
server:
name: document-parser-mcp
max_concurrent_jobs: 3
job_timeout_seconds: 600
processing:
default_pipeline: standard
enable_pipeline_auto_detect: true
ocr:
engine: easyocr
languages: [eng]
pdf:
backend: dlparse_v4
table_accuracy_mode: accurate
看 配置指南 查看详细选项。
MCP工具
服务器提供以下MCP工具:
parse_document
将任何文档解析为Markdown。
参数:
source(必填):文档的文件路径或URLpipeline(可选):处理管道-standard,vlm,或asroptions(可选):其他处理选项
例子:```json
{
"name": "parse_document",
"arguments": {
"source": "https://arxiv.org/pdf/2408.09869",
"pipeline": "standard"
}
}
### `parse_document_advanced`
具有详细配置的高级解析。
**参数:**
- `source` (必填):文件路径或URL
- `pipeline` (可选):处理管道
- `ocr_enabled` (可选):启用/禁用OCR
- `table_accuracy_mode` (可选): `fast` 或 `accurate`
- `pdf_backend` (可选):PDF处理后端
- `enable_enrichments` (可选):启用代码/公式丰富
### `get_job_status`
获取处理作业的状态。
**参数:**
- `job_id` (必填):作业标识符
### `list_supported_formats`
列出所有支持的输入格式和管道。
### `get_queue_statistics`
获取当前队列和处理统计信息。
## 与Claude Desktop集成
添加到您的Claude Desktop配置(`~/Library/Application Support/Claude/claude_desktop_config.json` 在macOS上):```json
{
"mcpServers": {
"document-parser": {
"command": "python",
"args": ["-m", "document_parser"],
"cwd": "/path/to/document-parser-mcp"
}
}
}
重新启动Claude Desktop,文档解析器将作为工具可用。
管道选择指南
标准管道(默认)
- 最适合:天生的数字PDF、Office文档、简洁的布局
- 特性:高级布局分析、表格结构恢复、可选OCR
- 演出:快速、内存高效
VLM管道
- 最适合:复杂的布局、手写笔记、屏幕截图、扫描文档
- 特性:视觉语言模型处理,端到端页面理解
- 演出:较慢,MLX在Apple Silicon上加速
ASR管道
- 最适合:音频文件(会议、讲座、访谈)
- 特性:基于耳语的转录
- 演出:CPU/GPU密集型
发展
运行测试```bash
Install development dependencies
pip install -r requirements-dev.txt
Run tests
pytest
Run with coverage
pytest --cov=document_parser
### 代码质量```bash
# Format code
black document_parser tests
# Lint
ruff check document_parser tests
# Type checking
mypy document_parser
项目结构```
document-parser-mcp/
├── document_parser/ # Main package
│ ├── config/ # Configuration system
│ ├── core/ # Core exceptions and types
│ ├── engine/ # Document processing engine
│ ├── mcp/ # MCP server implementation
│ ├── processing/ # Job queue and tracking
│ └── utils/ # Utility functions
├── tests/ # Test suite
├── config.yaml # Default configuration
├── requirements.txt # Production dependencies
└── setup.py # Package configuration
## 性能优化
### 内存管理
- 配置 `max_memory_gb` 对于您的系统
- 集 `max_concurrent_jobs` 基于可用资源
- 处理大文件时会自动清理
### MLX加速(苹果硅)
- 安装时使用 `pip install docling[mlx]`
- 在配置中启用: `enable_mlx_acceleration: true`
- 如果不可用,则自动回退到CPU
## 故障排除
### 常见问题
**“ModuleNotFoundError:没有名为'docling'的模块”**```bash
pip install docling
队列已满错误
- 等待当前作业完成
- 增加
max_concurrent_jobs在配置中
大文件内存错误
- 减少
max_memory_gb在配置中 - 使用
pipeline: standard而不是vlm
OCR不工作```bash
pip install easyocr
Or for tesseract
brew install tesseract # macOS
```
贡献
- 分叉存储库
- 创建要素分支(
git checkout -b feature/amazing-feature) - 进行更改
- 添加新功能的测试
- 运行测试套件
- 提交您的更改(
git commit -m 'Add amazing feature') - 推到分支(
git push origin feature/amazing-feature) - 打开拉取请求
许可证
MIT许可证-请参阅 许可证 文件以获取详细信息。
致谢
- 内置于 Docling -一个出色的文档理解工具包
- 使用 模型上下文协议 用于AI集成
支持
- 问题: GitHub问题
- 文档: 全部文件
