update
This commit is contained in:
@@ -8,11 +8,12 @@
|
|||||||
### 功能
|
### 功能
|
||||||
|
|
||||||
- `list_docx_images`:列出 DOCX 中的图片信息,支持 `docx_path` 为本地路径或 HTTP/HTTPS URL。
|
- `list_docx_images`:列出 DOCX 中的图片信息,支持 `docx_path` 为本地路径或 HTTP/HTTPS URL。
|
||||||
- `edit_docx`:对 DOCX 进行编辑,支持:
|
- `html_to_docx_pandoc`:将包含 HTML 标签的文本转换为 DOCX 文件,支持引用模板、Lua 过滤器等高级格式控制。
|
||||||
|
|
||||||
|
另外:`edit_docx` 是 `mcp_docx_server.py` 里的普通函数(不再通过 MCP 暴露),支持同样的参数与返回值:
|
||||||
- `input_docx` 为本地路径或 HTTP/HTTPS URL;
|
- `input_docx` 为本地路径或 HTTP/HTTPS URL;
|
||||||
- `image_replacements[*].file` 为本地路径或 HTTP/HTTPS URL;
|
- `image_replacements[*].file` 为本地路径或 HTTP/HTTPS URL;
|
||||||
- 返回结果中包含 `output_path` 和可选的 `output_url`(见下文)。
|
- 返回结果中包含 `output_path` 和可选的 `output_url`(见下文)。
|
||||||
- `html_to_docx_pandoc`:将包含 HTML 标签的文本转换为 DOCX 文件,支持引用模板、Lua 过滤器等高级格式控制。
|
|
||||||
|
|
||||||
### 安装依赖(本机运行)
|
### 安装依赖(本机运行)
|
||||||
|
|
||||||
@@ -32,7 +33,7 @@ pip install -r requirements.txt
|
|||||||
python mcp_docx_server.py
|
python mcp_docx_server.py
|
||||||
```
|
```
|
||||||
|
|
||||||
在 MCP 客户端中连接该服务器后,会看到上述三个工具。
|
在 MCP 客户端中连接该服务器后,应该会看到其中的 MCP 工具(`list_docx_images` 等);`edit_docx` 不再作为 MCP 工具出现。
|
||||||
|
|
||||||
#### 输出 URL(output_url)
|
#### 输出 URL(output_url)
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,11 @@
|
|||||||
"""
|
"""
|
||||||
基于 mcp_docx.py 封装的 MCP 服务器。
|
基于 mcp_docx.py 封装的 MCP 服务器。
|
||||||
|
|
||||||
暴露两个主要 MCP 工具:
|
暴露主要 MCP 工具:
|
||||||
- list_docx_images:列出 DOCX 中的图片信息
|
- list_docx_images:列出 DOCX 中的图片信息
|
||||||
- edit_docx: 进行文本替换 / 关键字上色 / 图片替换
|
|
||||||
|
另外提供一个普通函数 `edit_docx`(供 Python 代码直接调用),支持:
|
||||||
|
- 进行文本替换 / 关键字上色 / 图片替换
|
||||||
|
|
||||||
额外提供 HTTP 文件接口(仅在 http 模式下可用):
|
额外提供 HTTP 文件接口(仅在 http 模式下可用):
|
||||||
- POST /upload: 上传文件到服务器
|
- POST /upload: 上传文件到服务器
|
||||||
@@ -313,8 +315,7 @@ async def list_docx_images(docx_url: str) -> List[Dict[str, Any]]:
|
|||||||
imgs = get_images_info(_download_to_temp(docx_url, suffix=".docx"))
|
imgs = get_images_info(_download_to_temp(docx_url, suffix=".docx"))
|
||||||
return imgs
|
return imgs
|
||||||
|
|
||||||
@mcp.tool()
|
def edit_docx(
|
||||||
async def edit_docx(
|
|
||||||
input_docx_path: str,
|
input_docx_path: str,
|
||||||
replacements: List[Dict[str, str]] = None,
|
replacements: List[Dict[str, str]] = None,
|
||||||
image_replacements: Optional[List[Dict[str, Any]]] = None,
|
image_replacements: Optional[List[Dict[str, Any]]] = None,
|
||||||
|
|||||||
Reference in New Issue
Block a user