MCP Office Interop Word Server

MCP Office Interop Word Server

site icon
2025.03.27 2
TypeScriptWord 文档自动化开发效率工具开发效率
MCP Office Interop Word Server 是一个基于 Model Context Protocol (MCP) 的服务,通过 COM Interop 技术实现对 Microsoft Word 文档的编程操作。它提供了一系列工具,支持常见的 Word 文档处理任务,如文档创建、文本编辑、格式设置、表格操作等。该服务适用于需要在 Windows 环境下自动化处理 Word 文档的场景。
View on GitHub

Overview

基本能力

产品定位

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 机器上

安装教程

  1. 克隆仓库或下载源代码。
  2. 进入项目目录。
  3. 安装依赖: bash npm install
  4. 编译 TypeScript 代码: bash npm run build

运行服务器

stdio 模式(默认)

npm start

node dist/index.js

SSE 模式

PowerShell:

$env:MCP_TRANSPORT="sse"; npm start

Bash / Cmd:

MCP_TRANSPORT=sse npm start

调试方式

  • SSE 端点http://localhost:3001/sse
  • 消息端点http://localhost:3001/messages

许可证

该项目遵循 MIT 开源许可条款,请参阅 MIT 了解完整条款。