Word文档评论提取MCP服务 - 提供文档评论提取相关功能
Project description
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-document-comment-extractor": {
"command": "uv",
"args": [
"--directory",
"/path/to/Word文档评论提取",
"run",
"python",
"-m",
"word_document_comment_extractor.main"
],
"env": {
"MCP_TRANSPORT": "stdio"
}
}
}
}
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file word_document_comment_extractor_mcp-1.0.1.tar.gz.
File metadata
- Download URL: word_document_comment_extractor_mcp-1.0.1.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ac84feb453f9482972b26ffb05ca9815431482179316c571f61d0a44a5989d2
|
|
| MD5 |
cb96a9c89dd25fee52add21130fbf79a
|
|
| BLAKE2b-256 |
f829ff95ca1741685fc08214caf46b80814c664333ab661fd2598f83a5985943
|
File details
Details for the file word_document_comment_extractor_mcp-1.0.1-py3-none-any.whl.
File metadata
- Download URL: word_document_comment_extractor_mcp-1.0.1-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e92f401b3cc2be5ff9fc3952660cb843081511cff68c6a622d531796625b8e7
|
|
| MD5 |
4155529a44bfd50640712147c13e0186
|
|
| BLAKE2b-256 |
221f9fa73502045112071560820afee6af9795e0b33bd80a7f03242b865e0610
|