内容
# ooxml-mcp-server
用于创建、检查、编辑和验证 **Office Open XML** 文档(`.docx`,`.pptx`,`.xlsx`)的MCP服务器,在软件包/部分级别。
从 [ai-ui](https://github.com/Bajahaw/ai-ui) 中提取为独立的 [Model Context Protocol](https://modelcontextprotocol.io/) 服务器。
## 工具列表
| 工具 | 描述 |
|------|-------------|
| `list_document_parts` | 列出所有内部ZIP部件(路径,大小,类型) |
| `read_document_part` | 读取部件的原始XML/内容 |
| `create_document` | 创建最小有效的docx/pptx/xlsx(可选自定义部件) |
| `write_document_part` | 写入/替换一个或多个部件(原子级别 + 验证) |
| `delete_document_part` | 删除部件(仅当结果仍然有效时) |
| `validate_document` | 验证结构、关系、内容类型、XLSX语义 |
所有工具都接受文件系统 **路径** (不是应用程序特定的文件ID)。写入操作在保存之前会进行验证;无效的软件包将被拒绝,原始文件保持不变。
## 安装
```bash
go install github.com/Bajahaw/ooxml-mcp-server/cmd/ooxml-mcp@latest
```
或从源代码构建:
```bash
git clone https://github.com/Bajahaw/ooxml-mcp-server.git
cd ooxml-mcp-server
go build -o ooxml-mcp ./cmd/ooxml-mcp
```
## 配置
### Claude Desktop / Cursor / MCP 客户端
将以下内容添加到您的MCP配置(stdio)中:
```json
{
"mcpServers": {
"ooxml": {
"command": "ooxml-mcp"
}
}
}
```
或使用绝对路径:
```json
{
"mcpServers": {
"ooxml": {
"command": "/path/to/ooxml-mcp"
}
}
}
```
### ai-ui
在ai-ui设置中,通过stdio添加一个指向 `ooxml-mcp` 二进制文件(或 `go run` 命令)的MCP服务器,或者如果您使用远程MCP,请使用HTTP/SSE桥进行包装。
## 验证
在提交任何写入操作之前,软件包会检查:
- 有效的ZIP存档
- 每个 `.xml` / `.rels` 部分中格式良好的XML
- `[Content_Types].xml` 重写和默认扩展
- 关系目标存在
- 转发 `r:id` / `r:embed` / `r:link` 引用解析
- 已知OOXML部件(图表、绘图、工作表等)所需的 内容类型
- XLSX共享字符串/样式索引边界和行排序
## 示例工作流程
```
1. create_document path=./report.docx format=docx
2. list_document_parts path=./report.docx
3. read_document_part path=./report.docx part_path=word/document.xml
4. write_document_part path=./report.docx parts={ "word/document.xml": "<w:document ...>..." }
5. validate_document path=./report.docx
```
## 许可证
MIT — 请参阅 [LICENSE](./LICENSE)。