使用说明
Word MCP服务器
功能齐全 模型上下文协议(MCP) 用于创建和操作Microsoft Word的服务器(.docx)直接从Claude Code或任何兼容MCP的AI助手下载文件。
作者 Renato Tadeu de Figueiredo 的 许可证: 麻省理工学院
特性
| 类别 | 功能 |
|---|---|
| 文档生命周期 | 创建、打开、保存、另存为、关闭、复制、自动备份 |
| 阅读 | 完整内容(段落+表格)、大纲、章节内容、文本搜索、页眉/页脚 |
| 文本编辑 | 替换文本、替换段落、替换/删除章节、插入/删除段落、移动章节 |
| 格式化 | 段落样式、对齐、间距、缩进、行距、保持在一起;字符格式(粗体、斜体、下划线、删除线、字体、大小、颜色、全大写、小写) |
| 页眉和页脚 | 设置文本,添加页码(第X页/第X页,共Y页),插入徽标图像,清晰、均匀/第一页变体 |
| 图像 | 在正文或页眉中插入图像、调整大小、对齐、添加标题 |
| 表格 | 创建、读取、编辑单元格、添加/删除行、删除表、合并单元格(H/V)、列宽、单元格背景和边框格式、标题行 |
| 列表 | 项目符号和编号列表,多级 |
| 页面布局 | 页边距、方向(纵向/横向)、页面大小(A4、A3、A5、信纸、法律、自定义)、分节、分页符、多列布局 |
| 风格 | 列出所有样式,创建/更新自定义段落样式 |
| 目录 | 插入TOC字段(由Word自动更新) |
| 超链接 | 为段落添加可点击的链接 |
| 评论 | 添加本机Word注释(在审阅窗格中可见) |
| 书签 | 添加命名书签 |
| 文档属性 | 标题、作者、主题、关键字、描述、类别 |
| 高级XML | 用于复杂格式化的直接OOXML补丁 |
| 批量生成器 | 使用JSON规范在一次调用中创建完整的文档 |
安装
先决条件
- Python 3.11或更高版本
pip或uv
1.克隆存储库
git clone https://github.com/RenatoTadeuFigueiredo/word-mcp-server.git
cd word-mcp-server
2.安装依赖项
pip install -r requirements.txt
或与 uv:
uv pip install -r requirements.txt
配置
克劳德代码(CLI)
将服务器添加到您的Claude Code MCP配置中。从项目文件夹运行此命令:
claude mcp add word -- python /absolute/path/to/word-mcp-server/word_mcp_server.py
或编辑 ~/.claude/mcp_servers.json 手动:
{
"mcpServers": {
"word": {
"command": "python",
"args": ["/absolute/path/to/word-mcp-server/word_mcp_server.py"]
}
}
}
编辑配置后重新启动Claude Code。
克劳德桌面版
编辑 ~/Library/Application Support/Claude/claude_desktop_config.json (macOS)或Windows/Linux上的等效路径:
{
"mcpServers": {
"word": {
"command": "python",
"args": ["/absolute/path/to/word-mcp-server/word_mcp_server.py"]
}
}
}
用法示例
下面的示例显示了连接MCP服务器后可以给Claude的自然语言提示。
1.在一次通话中创建完整的公司文档
Create a document at /Documents/company-report.docx with:
- Default font "Calibri", size 11
- Page margins: 2.5 cm all sides
- Title "Q1 2026 Business Report", author "Renato Figueiredo"
- Header: "Acme Corp — Confidential" (right-aligned)
- Footer: page numbers in "Page X of Y" format, centered
- Heading 1: "Executive Summary"
- A paragraph summarizing the quarter results
- Heading 1: "Financial Results"
- A table with columns: Quarter, Revenue, Expenses, Profit
and three rows of data
- Heading 1: "Next Steps"
- A bullet list with three action items
克劳德将使用 build_document 在一次调用中生成完整文档。
2.打开并编辑现有文档
Open /Documents/contract.docx, replace every occurrence of
"ACME Corp" with "Globex Corporation", and save.
Open /Documents/proposal.docx and change the font of all
paragraphs under the "Introduction" heading to
"Times New Roman" 12pt, justified alignment.
3.在标题中添加公司徽标
Open /Documents/report.docx, insert the image at
/images/logo.png into the header (width 4 cm, left-aligned),
and add a right-aligned footer with "Page X of Y".
4.使用桌子
Open /Documents/budget.docx and add a new row to the first table
with values: "Q4 2026", "$120,000", "$95,000", "$25,000".
In the open document, merge cells in table 0,
row 0, from column 0 to column 3 (full-width header row),
set its background color to "2E74B5" and text color to white.
5.重组部门
In the open document, move the section "Appendix A"
to appear after the "Conclusion" section.
Delete the "Draft Notes" section entirely from the document.
6.插入目录
Open /Documents/manual.docx, insert a Table of Contents
at the beginning (after the title page) with the heading
"Contents", including up to level 3 headings.
在Word中打开文件后,按 Ctrl+A 然后 F9 以呈现页码。
7.添加评论以供审查
Open /Documents/draft.docx and add a comment from author
"Renato" to the paragraph containing "payment terms" with
the text: "Please confirm this clause with legal team."
8.页面布局调整
Open /Documents/brochure.docx, set the page to A4 landscape,
set 2 columns with 1.5 cm spacing between them.
Set page margins of the open document to:
top 3 cm, bottom 2.5 cm, left 2.5 cm, right 2 cm.
9.创建自定义样式并应用它
In the open document, create a paragraph style called
"Highlight Box" based on "Normal", with bold text,
font size 11, color "2E74B5", and 6 pt spacing before and after.
Then apply it to all paragraphs containing the word "IMPORTANT".
10.添加超链接
In the open document, find the paragraph containing
"visit our website" and add a hyperlink with text
"our website" pointing to https://example.com.
可用工具(共41个)
文档生命周期
| 工具 | 说明 |
|---|---|
open_document |
打开现有 .docx 文件 |
create_new_document |
创建新的空白文档(可选模板) |
save_document |
保存(创建 .bak 默认备份) |
save_as |
保存到新路径 |
close_document |
关闭而不保存 |
duplicate_document |
复制到新路径 |
阅读与检查
| 工具 | 说明 |
|---|---|
get_document_info |
元数据、单词/字符计数、节计数 |
read_document |
全结构化JSON(段落+表格) |
get_outline |
标题层次结构 |
get_section |
特定标题下的内容 |
find_text |
搜索段落和表格单元格 |
read_table |
阅读一个或所有表格 |
list_styles |
列出可用样式 |
get_document_xml |
段落或正文的原始OOXML |
read_headers_footers |
阅读所有页眉/页脚 |
文本编辑
| 工具 | 说明 |
|---|---|
replace_text |
查找和替换(保留格式,也搜索表格) |
replace_paragraph |
替换整段文字 |
replace_section |
替换标题下的所有内容 |
insert_paragraph |
插入位置(after_text、after_heading、index、end) |
delete_paragraph |
按索引或文本匹配删除 |
delete_section |
删除标题及其所有内容 |
move_section |
将一个部分移到另一个部分之前/之后 |
add_heading |
在任何级别添加标题 |
格式化
| 工具 | 说明 |
|---|---|
format_paragraph |
样式、对齐、间距、缩进、行距 |
format_text_run |
粗体、斜体、下划线、字体、颜色、大写、删除线 |
create_style |
创建/更新自定义段落样式 |
页眉和页脚
| 工具 | 说明 |
|---|---|
set_header |
设置标题文本的格式 |
set_footer |
设置页脚文本+可选页码 |
add_image_to_header |
将徽标/图像插入页眉 |
clear_header |
删除标题内容 |
clear_footer |
删除页脚内容 |
read_headers_footers |
读取页眉/页脚内容 |
图像
| 工具 | 说明 |
|---|---|
insert_image |
在正文中插入带有可选标题的图像 |
表格
| 工具 | 说明 |
|---|---|
insert_table |
使用数据和样式创建表 |
read_table |
读取表格内容 |
edit_table_cell |
编辑单元格文本和格式 |
add_table_row |
添加一行 |
delete_table_row |
删除一行 |
delete_table |
删除整个表 |
merge_table_cells |
水平或垂直合并单元格 |
format_table_cell |
设置单元格背景和边框 |
页面布局
| 工具 | 说明 |
|---|---|
set_page_margins |
设置边距(cm) |
set_page_orientation |
肖像或风景 |
set_page_size |
A4、A3、A5、信纸、法律或习俗 |
add_page_break |
插入硬分页符 |
add_section_break |
新页、连续页、偶数页/奇数页 |
set_columns |
多列布局 |
高级
| 工具 | 说明 |
|---|---|
insert_toc |
插入目录字段 |
add_hyperlink |
在段落中添加可点击的链接 |
add_comment |
添加本机Word注释 |
add_bookmark |
添加命名书签 |
set_document_properties |
标题、作者、主题、关键词等。 |
apply_xml_patch |
直接OOXML替换 |
build_document |
从JSON规范创建完整文档 |
自动备份
每 save_document 调用创建了一个 .bak 默认情况下,文件位于原始文件旁边。要禁用:
Save the document without creating a backup.
备注
目录
TOC字段作为Word字段代码插入。在Microsoft Word或LibreOffice Writer中打开文件,然后按 Ctrl+A→ F9 以呈现实际页码。
评论
原生词注释被注入到 word/comments.xml 部分。它们出现在Word审阅窗格中。如果注释部分不可访问,则使用纯内联文本回退。
页码
PAGE 和 NUMPAGES 字段在Word和LibreOffice Writer中正确呈现。
依赖项
| 包装 | 版本 | 用途 |
|---|---|---|
python-docx |
≥1.1.2 | 核心 .docx 操纵 |
lxml |
≥5.2.0 | XML处理 |
mcp |
≥1.0.0 | MCP服务器协议 |
贡献
欢迎拉取请求。对于重大更改,请先打开一个问题来讨论您想要更改的内容。
许可证
麻省理工学院 --版权所有(c)2026 Renato Tadeu de Figueiredo