基本能力
产品定位
MCP Office Interop Word Server 是一个用于自动化操作 Microsoft Word 文档的工具,适用于开发者和需要批量处理 Word 文档的用户。
核心功能
- 文档操作:创建、打开、保存、关闭 Word 文档。
- 文本编辑:插入、删除、查找替换文本,设置字体格式(加粗、斜体、下划线)。
- 段落格式:设置对齐方式、缩进、行距等。
- 表格操作:添加表格、设置单元格文本、插入行列、应用表格样式。
- 图片操作:插入图片、调整图片大小。
- 页眉页脚:设置页眉页脚文本。
- 页面设置:设置页边距、页面方向、纸张大小。
适用场景
- 自动化生成 Word 文档。
- 批量修改 Word 文档内容或格式。
- 集成到其他系统中,实现 Word 文档的自动化处理。
工具列表
- 文档操作工具:
word_createDocument
,word_openDocument
,word_saveActiveDocument
,word_saveActiveDocumentAs
,word_closeActiveDocument
。 - 文本编辑工具:
word_insertText
,word_deleteText
,word_findAndReplace
,word_toggleBold
,word_toggleItalic
,word_toggleUnderline
。 - 段落格式工具:
word_setParagraphAlignment
,word_setParagraphLeftIndent
,word_setParagraphRightIndent
,word_setParagraphFirstLineIndent
,word_setParagraphSpaceBefore
,word_setParagraphSpaceAfter
,word_setParagraphLineSpacing
。 - 表格操作工具:
word_addTable
,word_setTableCellText
,word_insertTableRow
,word_insertTableColumn
,word_applyTableAutoFormat
。 - 图片操作工具:
word_insertPicture
,word_setInlinePictureSize
。 - 页眉页脚工具:
word_setHeaderFooterText
。 - 页面设置工具:
word_setPageMargins
,word_setPageOrientation
,word_setPaperSize
。
常见问题解答
- 依赖问题:需要 Microsoft Word 安装在 Windows 机器上,并且支持 COM Interop。
- 错误处理:当前错误处理较为基础,生产环境可能需要更详细的错误检查和恢复机制。
- 常量值:Word 对象模型常量(如
WdSaveFormat
,WdUnits
等)在工具参数中需要以数值形式提供,具体数值可参考 Word VBA 文档。
使用教程
使用依赖
- Node.js (v18 或更高版本)
- npm
- Microsoft Word 安装在 Windows 机器上
安装教程
- 克隆仓库或下载源代码。
- 进入项目目录。
- 安装依赖:
bash
npm install - 编译 TypeScript 代码:
bash
npm run build
运行服务器
stdio 模式(默认)
bash
npm start
或
bash
node dist/index.js
SSE 模式
PowerShell:
powershell
$env:MCP_TRANSPORT="sse"; npm start
Bash / Cmd:
bash
MCP_TRANSPORT=sse npm start
调试方式
- SSE 端点:
http://localhost:3001/sse
- 消息端点:
http://localhost:3001/messages