Office Word MCP Server
一个模型上下文协议服务器,它使 AI 助手能够通过标准化的工具和资源来创建、读取、编辑和格式化 Microsoft Word 文档。
Tools
create_document
Create a new Word document with optional metadata. Args: filename: Name of the document to create (with or without .docx extension) title: Optional title for the document metadata author: Optional author for the document metadata
add_heading
Add a heading to a Word document. Args: filename: Path to the Word document text: Heading text level: Heading level (1-9, where 1 is the highest level)
add_paragraph
Add a paragraph to a Word document. Args: filename: Path to the Word document text: Paragraph text style: Optional paragraph style name
add_table
Add a table to a Word document. Args: filename: Path to the Word document rows: Number of rows in the table cols: Number of columns in the table data: Optional 2D array of data to fill the table
add_picture
Add an image to a Word document. Args: filename: Path to the Word document image_path: Path to the image file width: Optional width in inches (proportional scaling)
get_document_info
Get information about a Word document. Args: filename: Path to the Word document
get_document_text
Extract all text from a Word document. Args: filename: Path to the Word document
get_document_outline
Get the structure of a Word document. Args: filename: Path to the Word document
list_available_documents
List all .docx files in the specified directory. Args: directory: Directory to search for Word documents
copy_document
Create a copy of a Word document. Args: source_filename: Path to the source document destination_filename: Optional path for the copy. If not provided, a default name will be generated.
format_text
Format a specific range of text within a paragraph. Args: filename: Path to the Word document paragraph_index: Index of the paragraph (0-based) start_pos: Start position within the paragraph text end_pos: End position within the paragraph text bold: Set text bold (True/False) italic: Set text italic (True/False) underline: Set text underlined (True/False) color: Text color (e.g., 'red', 'blue', etc.) font_size: Font size in points font_name: Font name/family
search_and_replace
Search for text and replace all occurrences. Args: filename: Path to the Word document find_text: Text to search for replace_text: Text to replace with
delete_paragraph
Delete a paragraph from a document. Args: filename: Path to the Word document paragraph_index: Index of the paragraph to delete (0-based)
create_custom_style
Create a custom style in the document. Args: filename: Path to the Word document style_name: Name for the new style bold: Set text bold (True/False) italic: Set text italic (True/False) font_size: Font size in points font_name: Font name/family color: Text color (e.g., 'red', 'blue') base_style: Optional existing style to base this on
format_table
Format a table with borders, shading, and structure. Args: filename: Path to the Word document table_index: Index of the table (0-based) has_header_row: If True, formats the first row as a header border_style: Style for borders ('none', 'single', 'double', 'thick') shading: 2D list of cell background colors (by row and column)
add_page_break
Add a page break to the document. Args: filename: Path to the Word document
README
Office-Word-MCP-Server
一个用于创建、读取和操作 Microsoft Word 文档的模型上下文协议 (MCP) 服务器。该服务器使 AI 助手能够通过标准化接口处理 Word 文档,从而提供丰富的文档编辑功能。
<a href="https://glama.ai/mcp/servers/@GongRzhe/Office-Word-MCP-Server"> <img width="380" height="200" src="https://glama.ai/mcp/servers/@GongRzhe/Office-Word-MCP-Server/badge" alt="Office Word Server MCP server" /> </a>
概述
Office-Word-MCP-Server 实现了 模型上下文协议,以将 Word 文档操作公开为工具和资源。它充当 AI 助手和 Microsoft Word 文档之间的桥梁,允许进行文档创建、内容添加、格式设置和分析。
示例
提示
输出
功能
文档管理
- 创建带有元数据的新 Word 文档
- 提取文本并分析文档结构
- 查看文档属性和统计信息
- 列出目录中的可用文档
- 创建现有文档的副本
内容创建
- 添加具有不同级别的标题
- 插入带有可选样式的段落
- 创建带有自定义数据的表格
- 添加具有比例缩放的图像
- 插入分页符
丰富的文本格式
- 格式化特定文本部分(粗体、斜体、下划线)
- 更改文本颜色和字体属性
- 将自定义样式应用于文本元素
- 在整个文档中搜索和替换文本
表格格式
- 使用边框和样式格式化表格
- 创建具有不同格式的标题行
- 应用单元格底纹和自定义边框
- 构造表格以提高可读性
高级文档操作
- 删除段落
- 创建自定义文档样式
- 在整个文档中应用一致的格式
- 使用详细的控制格式化特定范围的文本
安装
前提条件
- Python 3.8 或更高版本
- pip 包管理器
基本安装
# 克隆存储库
git clone https://github.com/GongRzhe/Office-Word-MCP-Server.git
cd Office-Word-MCP-Server
# 安装依赖
pip install -r requirements.txt
使用安装脚本
或者,您可以使用提供的安装脚本,该脚本处理:
- 检查先决条件
- 设置虚拟环境
- 安装依赖
- 生成 MCP 配置
python setup_mcp.py
与 Claude for Desktop 一起使用
配置
方法 1:本地安装后
- 安装后,将服务器添加到您的 Claude for Desktop 配置文件:
{
"mcpServers": {
"word-document-server": {
"command": "python",
"args": [
"/path/to/word_server.py"
]
}
}
}
方法 2:无需安装(使用 uvx)
- 您还可以配置 Claude for Desktop 以使用服务器,而无需通过使用 uvx 包管理器进行本地安装:
{
"mcpServers": {
"word-document-server": {
"command": "uvx",
"args": [
"--from", "office-word-mcp-server", "word_mcp_server"
]
}
}
}
-
配置文件位置:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
- macOS:
-
重新启动 Claude for Desktop 以加载配置。
示例操作
配置完成后,您可以要求 Claude 执行以下操作:
- "创建一个名为 'report.docx' 的新文档,其中包含标题页"
- "向我的文档添加一个标题和三个段落"
- "插入一个包含销售数据的 4x4 表格"
- "将第 2 段中的单词 'important' 格式化为粗体和红色"
- "搜索并将所有 'old term' 实例替换为 'new term'"
- "为节标题创建自定义样式"
- "将格式应用于文档中的表格"
API 参考
文档创建和属性
create_document(filename, title=None, author=None)
get_document_info(filename)
get_document_text(filename)
get_document_outline(filename)
list_available_documents(directory=".")
copy_document(source_filename, destination_filename=None)
内容添加
add_heading(filename, text, level=1)
add_paragraph(filename, text, style=None)
add_table(filename, rows, cols, data=None)
add_picture(filename, image_path, width=None)
add_page_break(filename)
文本格式
format_text(filename, paragraph_index, start_pos, end_pos, bold=None,
italic=None, underline=None, color=None, font_size=None, font_name=None)
search_and_replace(filename, find_text, replace_text)
delete_paragraph(filename, paragraph_index)
create_custom_style(filename, style_name, bold=None, italic=None,
font_size=None, font_name=None, color=None, base_style=None)
表格格式
format_table(filename, table_index, has_header_row=None,
border_style=None, shading=None)
故障排除
常见问题
-
缺少样式
- 某些文档可能缺少标题和表格操作所需的样式
- 服务器将尝试创建缺少的样式或使用直接格式
- 为了获得最佳效果,请使用带有标准 Word 样式的模板
-
权限问题
- 确保服务器具有读取/写入文档路径的权限
- 使用
copy_document函数创建锁定文档的可编辑副本 - 如果操作失败,请检查文件所有权和权限
-
图像插入问题
- 使用图像文件的绝对路径
- 验证图像格式兼容性(建议使用 JPEG、PNG)
- 检查图像文件大小和权限
调试
通过设置环境变量启用详细日志记录:
export MCP_DEBUG=1 # Linux/macOS
set MCP_DEBUG=1 # Windows
贡献
欢迎贡献!请随时提交 Pull Request。
- Fork 存储库
- 创建您的功能分支 (
git checkout -b feature/amazing-feature) - 提交您的更改 (
git commit -m 'Add some amazing feature') - 将分支推送到远程仓库 (
git push origin feature/amazing-feature) - 打开一个 Pull Request
许可证
该项目已获得 MIT 许可证的许可 - 有关详细信息,请参阅 LICENSE 文件。
致谢
- 模型上下文协议 用于协议规范
- python-docx 用于 Word 文档操作
- FastMCP 用于 Python MCP 实现
注意:此服务器与系统上的文档文件交互。在 Claude for Desktop 或其他 MCP 客户端中确认请求的操作之前,请务必验证这些操作是否合适。
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。