Word文档评论提取 MCP服务
这是一个基于Model Context Protocol (MCP)的Word文档评论提取服务,提供从Word文档中提取和分析评论的功能。
功能特性
核心功能
- 提取所有评论 - 从Word文档中提取所有评论及其元数据
- 按作者筛选评论 - 提取指定作者的所有评论
- 按段落提取评论 - 提取特定段落的相关评论
技术特性
- 基于FastMCP框架构建
- 支持异步操作
- 完整的错误处理和验证
- JSON格式输出,便于处理
- 支持表格内评论检测
- 智能XML解析和备用方案
- 详细的评论元数据提取
安装要求
- Python 3.10+
- python-docx >= 1.1.0
- fastmcp >= 2.8.1
安装方法
使用uv安装依赖:
cd python/Word文档评论提取
uv sync
或使用pip安装:
pip install python-docx fastmcp
使用方法
启动MCP服务器
# 使用uv运行
uv run python -m word_document_comment_extractor.main
# 或直接运行
python -m word_document_comment_extractor.main
MCP配置
将以下配置添加到您的MCP客户端配置文件中:
{
"mcpServers": {
"Word文档评论提取": {
"timeout": 60,
"type": "stdio",
"command": "uvx",
"args": [
"word-document-comment-extractor-mcp@1.0.1"
],
"env": {}
}
}
}
API参考
提取所有评论
get_all_comments_tool(filename: str)
filename: Word文档路径
返回JSON格式:
{
"success": true,
"comments": [
{
"id": "comment_1",
"comment_id": "1",
"author": "张三",
"initials": "ZS",
"date": "2024-01-15T10:30:00",
"text": "这里需要修改",
"paragraph_index": 2,
"in_table": false,
"reference_text": "相关文本内容..."
}
],
"total_comments": 1
}
按作者提取评论
get_comments_by_author_tool(filename: str, author: str)
filename: Word文档路径author: 作者姓名(不区分大小写)
按段落提取评论
get_comments_for_paragraph_tool(filename: str, paragraph_index: int)
filename: Word文档路径paragraph_index: 段落索引(从0开始)
使用示例
提取所有评论
# 获取文档中的所有评论
result = get_all_comments_tool("document.docx")
按作者筛选评论
# 获取张三的所有评论
result = get_comments_by_author_tool("document.docx", "张三")
# 不区分大小写
result = get_comments_by_author_tool("document.docx", "zhang san")
按段落提取评论
# 获取第一个段落的评论
result = get_comments_for_paragraph_tool("document.docx", 0)
# 获取第五个段落的评论
result = get_comments_for_paragraph_tool("document.docx", 4)
评论数据结构
每个评论包含以下字段:
id: 唯一标识符comment_id: Word文档中的评论IDauthor: 评论作者initials: 作者缩写date: 评论日期(ISO格式)text: 评论内容paragraph_index: 关联的段落索引in_table: 是否在表格中reference_text: 被评论的文本片段
错误处理
服务提供完整的错误处理:
- 文件存在性检查
- 段落索引有效性验证
- 作者名称验证
- XML解析错误处理
- 详细的错误信息返回
技术实现
评论提取策略
- 主要方法: 通过文档关系访问评论部分
- 备用方法: 扫描段落XML查找评论引用
- 智能解析: 处理不同版本的Word文档格式
支持的评论类型
- 段落评论
- 表格内评论
- 文本范围评论
- 嵌套评论结构
限制说明
- 某些复杂的评论格式可能无法完全解析
- 评论的精确位置信息依赖于Word文档的内部结构
- 加密或受保护的文档可能无法访问评论
- 非标准格式的评论可能显示为占位符
注意事项
- 确保Word文档存在且可读
- 段落索引从0开始计算
- 作者名称匹配不区分大小写
- 返回结果为JSON格式字符串
- 大型文档的评论提取可能需要较长时间
许可证
MIT License
作者
Word MCP Services
Metadata
Release files for word-document-comment-extractor-mcp 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| word_document_comment_extractor_mcp-1.0.2.tar.gz | 9.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| word_document_comment_extractor_mcp-1.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.9 kB
Release files / word_document_comment_extractor_mcp-1.0.2.tar.gz
| Download URL | word_document_comment_extractor_mcp-1.0.2.tar.gz |
|---|---|
| Size | 9.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a4283c9f9df87b28199375ced4dff7447109b1a45a2fd732dd7d08d85e481897
|
|
BLAKE2b-256 checksum How to use checksums |
969e3e6ae9536d07515fd9df39ad1c64f7e5f230dc2dd1b6e74b8b7c3a6104e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|
Release files / word_document_comment_extractor_mcp-1.0.2-py3-none-any.whl
| Download URL | word_document_comment_extractor_mcp-1.0.2-py3-none-any.whl |
|---|---|
| Size | 8.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6bf9f7b55eaa86a9fa6cbac04c305614eb2dd4f6b5bede940b9ed1caf6081fe6
|
|
BLAKE2b-256 checksum How to use checksums |
e39dadccfb54b464aad5afe41cd75deee57fa6feb40d96afd0d790e2bbc498f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|