docx评论mcp
Claude Desktop的MCP服务器,提供对Word文档的全面读/写访问,包括注释、跟踪更改和回复线程——这些功能 python-docx 没有完全暴露。
特性
- 阅读文档:提取文本、评论(带回复线程)并跟踪更改
- 添加评论:将评论锚定到文档中的特定文本
- 对评论的回复:对现有评论创建线程回复
- 跟踪更改:进行编辑,并跟踪插入和删除
- 解决评论:将评论标记为已完成
- 接受/拒绝更改:应用或撤消跟踪的更改
安装
# Clone the repository
git clone https://github.com/your-username/docx-comments-mcp.git
cd docx-comments-mcp
# Install with uv
uv sync使用Claude Desktop
添加到您的 claude_desktop_config.json:
{
"mcpServers": {
"docx-comments": {
"command": "uv",
"args": ["--directory", "/path/to/docx-comments-mcp", "run", "docx-comments-mcp"]
}
}
}可用工具
read_document
阅读Word文档并提取内容、注释和跟踪更改。
参数:
path(必填):.docx文件的路径include_text(默认值:true):包含完整文档文本include_comments(默认值:true):包含带有锚点的评论include_track_changes(默认值:true):包括插入/删除
退货:
{
"metadata": {
"path": "/path/to/file.docx",
"author": "Original Author",
"created": "2025-01-15T10:30:00Z",
"modified": "2025-01-18T14:22:00Z",
"word_count": 4523
},
"paragraphs": [
{"index": 0, "text": "The paragraph content...", "style": "Heading 1"}
],
"comments": [
{
"id": 0,
"author": "Dr. Smith",
"date": "2025-01-16T09:15:00Z",
"text": "Consider citing Main & Hesse here",
"anchor_text": "disorganized attachment patterns",
"anchor_paragraph": 12,
"resolved": false,
"replies": [
{
"id": 1,
"parent_id": 0,
"author": "Josh",
"date": "2025-01-17T11:00:00Z",
"text": "Added citation — see revision"
}
]
}
],
"track_changes": [
{
"id": 5,
"type": "deletion",
"author": "Dr. Smith",
"date": "2025-01-16T09:20:00Z",
"text": "invariably",
"paragraph": 8
}
]
}create_comment
在Word文档中添加锚定到特定文本的注释。
参数:
path(必填):.docx文件的路径anchor_text(必填):用于锚定评论的文本(必须存在且唯一)comment_text(必填):评论内容author(默认:“Claude”):评论作者姓名output_path(可选):保存到新文件;如果省略,则创建带时间戳的备份并覆盖
退货:
{
"success": true,
"comment_id": 3,
"anchored_to": "the exact text that was matched",
"paragraph": 15,
"output_path": "/path/to/output.docx"
}create_reply
为现有评论添加回复。
参数:
path(必填):.docx文件的路径parent_comment_id(必填):要回复的评论IDreply_text(必填):回复内容author(默认:“Claude”):回复作者姓名output_path(可选):保存到新文件;如果省略,则创建备份
create_track_change
在启用轨迹更改(插入、删除或替换)的情况下进行编辑。
参数:
path(必填):.docx文件的路径find_text(必填):要查找和修改的文本replace_with(必填):替换文本(删除时为空字符串)author(默认:“Claude”):更改作者姓名output_path(可选):保存到新文件;如果省略,则创建备份
mark_comment_resolved
将评论标记为已解决/已完成。
参数:
path(必填):.docx文件的路径comment_id(必填):要解决的评论IDoutput_path(可选):保存到新文件;如果省略,则创建备份
accept_change
接受跟踪更改(永久应用)。
参数:
path(必填):.docx文件的路径change_id(必填):要接受的轨道更改的IDoutput_path(可选):保存到新文件;如果省略,则创建备份
reject_change
拒绝跟踪的更改(撤消更改)。
参数:
path(必填):.docx文件的路径change_id(必填):要拒绝的轨道更改的IDoutput_path(可选):保存到新文件;如果省略,则创建备份
安全特性
- 自动备份:在未指定的情况下修改文件时
output_path创建带时间戳的备份(例如。,document.backup_20250119_143022.docx) - 原子写入:使用临时文件和原子移动来防止损坏
- 独特的锚匹配:评论需要独特的锚文本以防止歧义
发展
# Install dev dependencies
uv sync
uv pip install pytest pytest-asyncio
# Run tests
uv run pytest -v
# Run specific test file
uv run pytest tests/test_reader.py -v建筑
src/docx_comments_mcp/
├── __init__.py
├── server.py # MCP server with tool definitions
├── reader.py # Read operations (document, comments, track changes)
├── writer.py # Write operations (add comments, track changes)
└── xml_helpers.py # Low-level OOXML parsing utilities许可证
麻省理工学院
