简体中文 | English
此 MCP 服务器提供了多种文件转换工具,用于转换各种文档和图像格式。该项目使用了 模型上下文协议(MCP),旨在为需要文件转换功能的AI代理提供服务。
克隆仓库
git clone https://github.com/wowyuarm/file-converter-mcp.git
cd file-converter-mcp
创建虚拟环境(可选但推荐)
python -m venv venv
source venv/bin/activate # 在基于 Unix 的系统上
venv\Scripts\activate # 在 Windows 上
安装依赖
使用 pip 安装所需包:
pip install mcp docx2pdf pdf2docx pillow pandas pdfkit markdown
或者,如果你正在使用 uv:
uv add "mcp[cli]" docx2pdf pdf2docx pillow pandas pdfkit markdown
注意:某些转换库可能有额外的系统依赖项。请参阅它们的文档以获取详细信息。
要测试服务器,请运行:
mcp dev file_converter_server.py
可选地,你可以通过以下命令在 Claude Desktop 上安装服务器:
mcp install file_converter_server.py --name "File Converter"
MCP 服务器暴露了以下工具:
命令:docx2pdf
input_file: path/to/document.docx
file_content_base64: [Base64 编码字符串]
命令:pdf2docx
input_file: path/to/document.pdf
file_content_base64: [Base64 编码字符串]
命令:convert_image
input_file: path/to/image.png
output_format: jpg
file_content_base64: [Base64 编码字符串]
input_format: png
output_format: jpg
命令:excel2csv
命令:html2pdf
命令:convert_file
input_file: path/to/file.docx
input_format: docx
output_format: pdf
file_content_base64: [Base64 编码字符串]
input_format: docx
output_format: pdf
这些是为了向后兼容而维护的。所有主要工具现在都直接支持基于内容的输入。
命令:convert_content
命令:docx2pdf_content
命令:pdf2docx_content
命令:markdown2pdf_content
服务器包括强大的文件路径处理功能,它:
所有转换工具现在支持两种输入方式:
基于路径的转换(传统方法)
@文件转换器
docx2pdf
input_file: file.docx
基于内容的转换(即使路径查找失败也能工作)
@文件转换器
docx2pdf
file_content_base64: [Base64 编码字符串]
这种双模式方法提供了最大的灵活性和可靠性:
当与 Claude 一起使用时,如果文件上传无法找到:
尝试使用带有前缀路径的原始文件名:
@文件转换器
docx2pdf
input_file: /tmp/file.docx
如果这不起作用,直接从 Claude 获取文件内容:
@文件转换器
docx2pdf
file_content_base64: [从 Claude 获取的 Base64 内容]
{"success": false, "error": "错误消息"}{"success": true, "data": "Base64 编码的文件内容"}欢迎贡献!如果您想贡献,请遵循 CONTRIBUTING.md 中的指南(中文版:贡献指南,英文版:Contributing Guidelines)。
本项目根据 MIT 许可证发布 - 详情见 LICENSE 文件。
访问 GitHub 仓库:https://github.com/wowyuarm/file-converter-mcp
此项目可用作模型上下文协议(MCP)服务器,为 AI 代理提供文件转换工具。
安装依赖项:
python -m pip install -e .
启动 MCP 服务器:
python start_mcp_server.py
配置您的 MCP 客户端(例如 Claude Desktop、Cursor),使用以下配置:
推荐配置(cursor-mcp.config.json):
{
"mcpServers": {
"file-converter": {
"command": "python",
"args": ["file_converter_server.py"],
"cwd": "."
}
}
}
替代配置(mcp.config.json):
{
"mcpServers": {
"file-converter": {
"command": "python",
"args": ["file_converter_server.py"],
"cwd": "."
}
}
}
cursor-mcp.config.json 以获得最简单的配置MCP 服务器提供了以下工具:
docx2pdf: 将 Word 文档转换为 PDFpdf2docx: 将 PDF 转换为 Word 文档convert_image: 在图像格式之间进行转换(如 PNG、JPG、WEBP 等)excel2csv: 将 Excel 文件转换为 CSVhtml2pdf: 将 HTML/Markdown 转换为 PDFconvert_file: 在支持的格式之间进行通用文件转换convert_content: 从 Base64 内容转换文件一旦配置好,您可以在您的 AI 代理中使用这些工具:
将这个 Word 文档转换为 PDF: [上传文件]
将这个图像从 PNG 转换为 JPG: [上传文件]
将这个 Excel 文件转换为 CSV: [上传文件]