文档转换工具添加福利群:解决AI开发者的「MCP实战痛点」
github
已正式纳入 Model Context Protocol 服务器 开源项目。🎉
一个使用 pandoc 进行文档格式转换的 Model Context Protocol 服务器。该服务器提供了在不同文档格式之间转换内容的工具,同时保留格式和结构。
请注意,mcp-pandoc 目前处于早期开发阶段。PDF 支持正在开发中,功能和可用工具可能会随着我们继续改进服务器而发生变化和扩展。
致谢:该项目使用 Pandoc Python 包 进行文档转换,构成了该项目的基础。
初次接触 mcp-pandoc? 查看 📖 CHEATSHEET.md 获取:
非常适合快速查阅和快速上手!
更多内容即将推出...
convert-contents
contents (字符串): 要转换的源内容(如果未提供 input_file 则为必需)input_file (字符串): 输入文件的完整路径(如果未提供 contents 则为必需)input_format (字符串): 内容的源格式(默认为 markdown)output_format (字符串): 目标格式(默认为 markdown)output_file (字符串): 输出文件的完整路径(对于 pdf、docx、rst、latex、epub 格式为必需)reference_doc (字符串): 用于样式的参考文档路径(支持 docx 输出格式)defaults_file (字符串): 包含转换选项的 Pandoc 默认文件(YAML)路径filters (数组): 在转换过程中应用的 Pandoc 过滤器路径列表使用默认文件创建可重用的转换模板,保持一致的格式:
# academic-paper.yaml
from: markdown
to: pdf
number-sections: true
toc: true
metadata:
title: "学术论文"
author: "研究团队"

示例用法:"使用默认文件 academic-paper.yaml 将 paper.md 转换为 PDF 并保存为 paper.pdf"
应用自定义过滤器以增强处理:
示例用法:"使用过滤器 ['/path/to/mermaid-filter.py'] 将 docs.md 转换为 HTML 并保存为 docs.html"
💡 有关全面的示例和工作流程,请参见 CHEATSHEET.md
| 从\到 | MD | HTML | TXT | DOCX | RST | LaTeX | EPUB | IPYNB | ODT | |
|---|---|---|---|---|---|---|---|---|---|---|
| Markdown | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| HTML | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| TXT | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| DOCX | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| RST | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| LaTeX | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| EPUB | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| IPYNB | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| ODT | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
该工具使用 pandoc 进行转换,允许从上述格式生成 PDF 文件。然而,不支持从 PDF 转换为其他格式。因此,PDF 应被视为仅输出格式。
| 类别 | 格式 | 要求 |
|---|---|---|
| 基本 | MD, HTML, TXT, IPYNB, ODT | 无 |
| 高级 | DOCX, PDF, RST, LaTeX, EPUB | 必须指定 output_file 路径 |
| 样式化 | 带有参考文档的 DOCX | 自定义模板支持 ⭐ |
注意:对于高级格式:
brew install texlive)注意:请确保完成下面“关键要求”部分中提到的所需包的安装。
要使用已发布的版本
{
"mcpServers": {
"mcp-pandoc": {
"command": "uvx",
"args": ["mcp-pandoc"]
}
}
}

💡 快速开始:参见 CHEATSHEET.md 获取复制粘贴示例和常见工作流程。
必需:安装 pandoc - 核心文档转换引擎
安装:
# macOS
brew install pandoc
# Ubuntu/Debian
sudo apt-get install pandoc
# Windows
# 从以下网址下载安装程序:https://pandoc.org/installing.html

验证:pandoc --version
必需:安装 uv 包(包含 uvx 命令)
安装:
# macOS
brew install uv
# Windows/Linux
pip install uv

验证:uvx --version
在尝试 PDF 转换之前必须安装 TeX Live
安装命令:
# Ubuntu/Debian
sudo apt-get install texlive-xetex
# macOS
brew install texlive
# Windows
# 从以下网址安装 MiKTeX 或 TeX Live:
# https://miktex.org/ 或 https://tug.org/texlive/

✅ 正确用法:
# 将内容转换为 PDF
"将此文本转换为 PDF 并保存为 /path/to/document.pdf"
# 在文件格式之间转换
"将 /path/to/input.md 转换为 PDF 并保存为 /path/to/output.pdf"

"使用template.docx作为参考,将input.md转换为DOCX并保存为output.docx"
"首先创建一个参考文档:pandoc -o custom-reference.docx --print-default-data-file reference.docx",或者如果你已经有一个参考文档,直接使用它 "然后使用自定义样式进行转换:使用/path/to/custom-reference.docx作为参考,将此文本转换为DOCX并保存为/path/to/styled-output.docx"
❌ 错误用法: ```bash # 缺少文件名和扩展名 "将此保存为PDF到/documents/" # 缺少完整路径 "将此转换为PDF" # 缺少扩展名 "保存为/documents/story"
PDF转换失败
文件转换失败
/path/to/document.pdf 而不是 /path/to/格式转换失败
参考文档问题
pandoc -o reference.docx --print-default-data-file reference.docxopen ~/Library/Application\ Support/Claude/claude_desktop_config.json%APPDATA%/Claude/claude_desktop_config.jsona) 仅适用于本地开发及对本仓库的贡献
ℹ️ 将
"mcpServers": {
"mcp-pandoc": {
"command": "uv",
"args": [
"--directory",
"<DIRECTORY>/mcp-pandoc",
"run",
"mcp-pandoc"
]
}
}

b) 已发布服务器配置 - 消费者应使用此配置
"mcpServers": {
"mcp-pandoc": {
"command": "uvx",
"args": [
"mcp-pandoc"
]
}
}

运行以下bash命令,通过Smithery自动为Claude Desktop安装已发布的mcp-pandoc pypi:
npx -y @smithery/cli install mcp-pandoc --client claude
注意:要使用本地配置的mcp-pandoc,请按照上面的"开发/未发布服务器配置"步骤操作。
要运行全面的测试套件并验证所有支持的双向转换,请使用以下命令:
uv run pytest tests/test_conversions.py
这确保了向后兼容性并验证了工具的核心功能。
要准备分发包:
uv sync

uv build
这将在dist/目录中创建源码和wheel分发。
uv publish
注意:你需要通过环境变量或命令行标志设置PyPI凭证:
--token 或 UV_PUBLISH_TOKEN--username/UV_PUBLISH_USERNAME 和 --password/UV_PUBLISH_PASSWORD由于MCP服务器通过stdio运行,调试可能会比较困难。为了获得最佳的调试体验,我们强烈推荐使用MCP Inspector。
你可以通过npm使用以下命令启动MCP Inspector:
npx @modelcontextprotocol/inspector uv --directory /Users/vivekvells/Desktop/code/ai/mcp-pandoc run mcp-pandoc
启动后,Inspector将显示一个URL,你可以在浏览器中访问该URL以开始调试。
我们欢迎对mcp-pandoc的贡献!以下是你如何参与的方式: