Document Convert MCP
Enables document format conversion between Word, Markdown, PDF, HTML, and plain text, supporting batch operations and format validation via the AI MCP protocol.
README
📄 Document Convert MCP
🚀 基于 AI MCP 协议的智能文档转换工具,支持 Word、Markdown、PDF、HTML 等多种格式互转
✨ 特性
- 📝 Markdown 转换 - 支持 Markdown 与其他格式的双向转换
- 📄 Word 文档处理 - 完美支持 .docx 和 .doc 格式
- 🌐 HTML 转换 - 智能处理 HTML 标签和样式
- 📋 PDF 转换 - 高质量 PDF 生成和解析
- 🔧 纯文本转换 - 智能格式识别和转换
- 🖼️ 图片处理 - 自动提取和转换文档中的图片
- 📦 TypeScript 支持 - 完整的类型定义
- 🔄 批量转换 - 支持多文档批量处理
- ⚡ 高性能引擎 - 优化的转换算法
📦 安装
npm install @pickstar-2002/document-covert-mcp@latest
🚀 快速开始
作为 MCP 服务器使用(推荐)
在您的 AI IDE 中配置 MCP 服务器:
npx @pickstar-2002/document-covert-mcp@latest
在 Cursor 中使用
在 Cursor 的设置中添加 MCP 服务器配置:
{
"mcpServers": {
"document-convert": {
"command": "npx",
"args": ["@pickstar-2002/document-covert-mcp@latest"]
}
}
}
在 WindSurf 中使用
在 WindSurf 的 MCP 配置中添加:
{
"servers": {
"document-convert": {
"command": "npx",
"args": ["@pickstar-2002/document-covert-mcp@latest"]
}
}
}
编程接口
import { DocumentConverter } from '@pickstar-2002/document-covert-mcp';
const converter = new DocumentConverter();
// 转换 Word 文档到 Markdown
await converter.convertDocument('document.docx', 'output.md', 'md');
// 转换 HTML 到 PDF
await converter.convertDocument('page.html', 'output.pdf', 'pdf');
// 批量转换
await converter.batchConvert(
['doc1.docx', 'doc2.pdf'],
'./output/',
'md'
);
🛠️ MCP 工具
本工具提供以下 MCP 工具:
convert_document
转换单个文档格式
{
"tool": "convert_document",
"arguments": {
"inputPath": "./document.docx",
"outputPath": "./document.md",
"outputFormat": "md",
"options": {
"preserveFormatting": true,
"quality": "high",
"includeImages": true
}
}
}
batch_convert_documents
批量转换多个文档
{
"tool": "batch_convert_documents",
"arguments": {
"inputPaths": ["./doc1.docx", "./doc2.pdf"],
"outputDirectory": "./converted/",
"outputFormat": "md",
"options": {
"preserveFormatting": true,
"quality": "medium"
}
}
}
get_supported_formats
获取支持的文档格式列表
{
"tool": "get_supported_formats",
"arguments": {}
}
validate_document
验证文档格式和完整性
{
"tool": "validate_document",
"arguments": {
"filePath": "./document.docx"
}
}
📋 支持格式
| 输入格式 | 输出格式 | 状态 | 特性 |
|---|---|---|---|
| Word (.docx, .doc) | Markdown, HTML, PDF, TXT | ✅ | 保持格式、图片提取 |
| Markdown (.md) | Word, HTML, PDF, TXT | ✅ | 语法高亮、表格支持 |
| PDF (.pdf) | Word, Markdown, HTML, TXT | ✅ | 文本提取、布局识别 |
| HTML (.html) | Word, Markdown, PDF, TXT | ✅ | 样式保持、标签解析 |
| 纯文本 (.txt) | Word, Markdown, HTML, PDF | ✅ | 智能格式识别 |
⚙️ 配置选项
interface ConversionOptions {
preserveFormatting?: boolean; // 保持原格式 (默认: true)
quality?: 'low' | 'medium' | 'high'; // 转换质量 (默认: medium)
includeImages?: boolean; // 包含图片 (默认: true)
customStyles?: string; // 自定义样式
}
🏗️ 项目结构
document-covert-mcp/
├── src/
│ ├── index.ts # MCP 服务器入口
│ ├── converter/ # 转换器核心
│ │ ├── DocumentConverter.ts # 主转换器
│ │ └── formats/ # 格式转换器
│ │ ├── WordConverter.ts
│ │ ├── MarkdownConverter.ts
│ │ ├── PdfConverter.ts
│ │ ├── HtmlConverter.ts
│ │ └── TextConverter.ts
│ ├── types/ # 类型定义
│ │ └── index.ts
│ └── utils/ # 工具函数
│ ├── logger.ts
│ └── validation.ts
├── examples/ # 示例文件
├── dist/ # 编译输出
├── LICENSE # MIT 许可证
├── package.json # 项目配置
└── README.md # 项目文档
🔧 开发
# 克隆项目
git clone https://github.com/pickstar-2002/document-covert-mcp.git
cd document-covert-mcp
# 安装依赖
npm install
# 开发模式
npm run dev
# 构建项目
npm run build
# 启动服务
npm start
# 代码格式化
npm run format
# 代码检查
npm run lint
📚 使用示例
基础转换
// Word 转 Markdown
await converter.convertDocument(
'report.docx',
'report.md',
'md',
{ preserveFormatting: true }
);
// Markdown 转 PDF
await converter.convertDocument(
'readme.md',
'readme.pdf',
'pdf',
{ quality: 'high' }
);
批量处理
// 批量转换多个文档
const results = await converter.batchConvert(
['doc1.docx', 'doc2.pdf', 'doc3.html'],
'./output/',
'md',
{ includeImages: true }
);
console.log(`成功转换 ${results.filter(r => r.success).length} 个文档`);
格式验证
// 验证文档
const validation = await converter.validateDocument('document.docx');
if (validation.isValid) {
console.log(`文档有效,格式: ${validation.format}`);
} else {
console.error(`文档无效: ${validation.error}`);
}
🤝 贡献
欢迎提交 Issue 和 Pull Request!
- Fork 本项目
- 创建特性分支 (
git checkout -b feature/AmazingFeature) - 提交更改 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 开启 Pull Request
📄 许可证
本项目基于 MIT 许可证开源 - 查看 LICENSE 文件了解详情。
👨💻 作者
pickstar-2002
- 微信: pickstar_loveXX
让文档转换变得简单高效! 🚀✨
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。