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