使用说明
PDF MCP服务器
v0.3.0
允许多模式LLM读取PDF文件的MCP服务器。
特点
-
转换页面图像:将PDF页面渲染为图像并直接传递给LLM
-
一次读取完整PDF:
read_pdf_all一次处理所有页面 -
智能读取:
read_pdf_smart通过自动判断文本/图像页面 -
矢量图形检测:同时显示绘图(图形、图表)数量
-
完全支持布局:两级布局、矢量图、表格等均精确表示
-
智能缓存:修改PDF时自动刷新缓存,提供缓存删除工具
安装
基本安装
cd d:\PythonPractice\pdf-mcp-server
pip install -e .
VS Code设置
settings.json在中添加以下内容:
"mcpServers": {
"pdf-reader": {
"command": "pdf-mcp",
"args": []
}
}
可用工具
read_pdf_smart (建议-有效)
分析页面内容并以最佳方式阅读
- 只有文本的页面→返回文本(快速,节省令牌)
- 图像/绘图所在的页面→渲染为图像
read_pdf_smart(path="d:/path/to/file.pdf")
read_pdf_smart(path="d:/path/to/file.pdf", start_page=1, end_page=5)
read_pdf_all
以图像方式读取整个PDF -将所有页面转换为图像
read_pdf_all(path="d:/path/to/file.pdf")
read_pdf_all(path="d:/path/to/file.pdf", start_page=1, end_page=10) # 범위 지정
read_pdf_page
仅通过图像读取特定页面
read_pdf_page(path="d:/path/to/file.pdf", page_number=1)
read_pdf_info
读取PDF元数据(页数、标题、作者、图像/绘图数量等)
read_pdf_info(path="d:/path/to/file.pdf")
输出示例:
📋 페이지 요약:
[1] 이미지: 0개, 드로잉: 5개 | 텍스트 미리보기...
[2] 이미지: 2개, 드로잉: 0개 | 텍스트 미리보기...
read_pdf_text
仅提取文本(搜索/复制)
read_pdf_text(path="d:/path/to/file.pdf", start_page=1, end_page=5)
render_pdf_page
以特定DPI呈现页面
render_pdf_page(path="d:/path/to/file.pdf", page_number=1, dpi=150)
clear_pdf_cache
删除PDF缓存
clear_pdf_cache(path="d:/path/to/file.pdf") # 실제 삭제
clear_pdf_cache(path="d:/path/to/file.pdf", dry_run=True) # 미리보기만
缓存结构
📁 example.pdf
📁 example_pdf_cache/ ← 자동 생성
├── .cache_meta.json ← PDF 수정 감지용 메타데이터
├── page_001.png ← 페이지 1 이미지
├── page_002.png ← 페이지 2 이미지
└── ...
- PDF文件修改后,缓存将自动更新
clear_pdf_cache可以通过手动删除
LLM使用指南
推荐使用模式
# 효율적으로 전체 읽기 (텍스트/이미지 자동 판단)
read_pdf_smart(path="d:/path/to/paper.pdf")
# 특정 범위만 읽기
read_pdf_smart(path="d:/path/to/paper.pdf", start_page=5, end_page=10)
# 전부 이미지로 읽기 (레이아웃 중요할 때)
read_pdf_all(path="d:/path/to/paper.pdf")
# 특정 페이지만 읽기
read_pdf_page(path="d:/path/to/paper.pdf", page_number=3)
-
read_pdf_smart:在节省代币的同时准确查看图形/图表 -
read_pdf_all:以图像形式查看所有页面(布局完整) -
转换为图像。
view_file无需呼叫即可显示
版本历史记录
v0.3.0
- 代码重构和优化
- DEPRECATED代码清理(删除不必要的Marker相关代码)
- 应用Context Manager模式(
with通过语句改善资源管理) - 魔力编号常量化(提高代码可读性)
- PEP8风格规范化
- 大约225行代码清理,提高了可维护性
- 性能或功能不变(代码质量改进版本)
v0.2.1
read_pdf_marker禁用:深度学习模型加载时间过长,缺乏实用性- 通过消除marker-pdf依赖性减少安装大小
v0.2.0版本
(在v0.2.1中禁用)read_pdf_marker:添加基于Marker深度学习的PDF格式副本clear_pdf_cache:添加缓存删除工具- 自动刷新缓存:修改PDF时缓存无效
- 改进了资源泄漏防范
v0.1.0
- 最初版本
read_pdf_smart,read_pdf_all,read_pdf_page等基本功能
