将Mineru官方PDF解析能力封装到FastMCP服务中,使得支持MCP协议的任何客户端都能轻松调用并实现批量PDF到HTML转换(包括图像资源组织和命名)。
convert_pdfs_with_mineru工具公开,可被主流大型模型代理直接调用https://mineru.net的网络环境MINERU_API_TOKENcd main/mineru_mcp_project
pip install -e .
# PowerShell 示例
$env:MINERU_API_TOKEN = "你的 Mineru Token"
您也可以通过api_token参数显式传递。
run-mineru-mcp
服务默认监听本地http://127.0.0.1:4399/mcp/。
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
pdf_folder | Str | – | PDF文件目录(必填) |
output_folder | Str | – | 转换结果输出目录(必填) |
api_token | str | None | 可选,若未提供,则读取环境变量MINERU_API_TOKEN |
language | str | "ch" | Mineru解析语言参数 |
enable_table Boolean | True | 是否启用表格识别 | |
extra_formats | list[str] | ["html"] | Mineru应包含的附加导出格式列表,必须包括html |
poll_interval | float | 3.0 | 污染任务状态的时间间隔(秒) |
max_wait | float | 1800.0 | 单个批次任务的最大等待时间(秒) |
rename_assets_flag Boolean | True | 是否重命名返回的图像资源并同步更新HTML引用 | |
is_ocr Boolean | True | 上传Mineru时的OCR开关 |
{
"pdf_total": 12,
"uploaded": 12,
"completed": 12,
"output_directory": "D:/Mineru/output",
"details": [
{"file": "sample.pdf", "stage": "upload", "status": "success", "message": "上传成功"},
{"file": "sample.pdf", "stage": "download", "status": "success", "message": "已保存 sample.html"}
]
}
import asyncio
from fastmcp import Client
client = Client("http://127.0.0.1:4399/mcp/")
async def main():
async with client:
result = await client.call_tool(
"convert_pdfs_with_mineru",
{
"pdf_folder": r"D:\\Docs\\pdf",
"output_folder": r"D:\\Docs\\html",
"poll_interval": 5.0,
"max_wait": 3600.0
}
)
print(result.data)
if __name__ == "__main__":
asyncio.run(main())
run-mineru-mcp启动服务convert_pdfs_with_mineruoutput_folder查看生成的HTML和图像资源max_wait,或减少单批文件数量rename_assets_flag设置为True,并确认ZIP文件中存在figure/images等资源文件夹