基于 PyMuPDF4LLM 和 Tiktoken 的 PDF 解析与分块 MCP 服务器
Project description
PyMuPDF4LLM Enhanced MCP
基于 PyMuPDF4LLM 和 Tiktoken 的 PDF 解析与分块 MCP 服务器。
功能特性
- 🔍 PDF 转 Markdown 格式
- 📊 基于 Token 的智能分块(使用 Tiktoken o200k_base)
- 💾 SHA256 哈希缓存机制
- 🔄 可配置的块重叠
- 📡 完整 MCP 协议支持
Claude Code 配置
claude mcp add -s local pymupdf4llm-enhanced pymupdf4llm-enhanced-mcp
使用方法
parse_pdf - 解析 PDF
将 PDF 转换为 Markdown 并分块。
parse_pdf(
file_path="/path/to/document.pdf",
chunk_size_tokens=2000,
chunk_overlap_tokens=200
)
# 返回: {"chunks_count": 15, "cached": false}
read_chunk - 读取分块
从缓存读取指定分块。
read_chunk(
file_path="/path/to/document.pdf",
chunk_index=0
)
# 返回: {"chunk_index": 0, "content": "...", "file_path": "..."}
工作原理
- 计算 PDF 文件的 SHA256 哈希值
- 转换为 Markdown 并按 Token 数分块
- 缓存到
.pymupdf4llm-enhanced-mcp/目录 - 文件变更时自动重建缓存
使用场景
- 大型文档分析:处理长篇论文、技术手册
- RAG 系统:为检索增强生成准备文档块
- 批量处理:高效处理多个相同文档的查询
最佳实践
- 块大小:根据 LLM 上下文窗口设置(1000-3000 tokens)
- 重叠率:建议 10-15% 保持上下文连贯性
- 缓存管理:定期清理旧缓存释放空间
常见问题
Q: 缓存占用过大
A: 删除 .pymupdf4llm-enhanced-mcp/ 目录
Q: PDF 返回空内容 A: 检查 PDF 是否损坏或需要 OCR
相关链接
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
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 pymupdf4llm_enhanced_mcp-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pymupdf4llm_enhanced_mcp-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e4a2397fdbb5a7b38c53f3182dc3929316d90afce4c57bdc14b9d3a03837748
|
|
| MD5 |
3f397733408660b20f5f06d35a7a3bdf
|
|
| BLAKE2b-256 |
6616832346e74fb8f66a7fc857719d5ba4e04904ac929461823e5cceabf3e8ae
|