LibreOffice MCP服务器(Ubuntu)
FastMCP服务器,为Claude Code提供了通过HTTP API桥控制LibreOfficeWriter的工具。
建筑
Claude Code (Ubuntu VM)
│
└── LibreOffice MCP Server (this)
│
│ HTTP requests (localhost:8765)
▼
LibreOffice Writer
│
└── MCP Extension (HTTP API)组件
1.MCP服务器(libreoffice_mcp_server.py)
FastMCP服务器提供9个整合的文档操作工具:
| 工具 | 操作 | 描述 |
|---|---|---|
document | 创建、信息、列表、内容、状态 | 文档管理 |
structure | 大纲、段落、范围、计数 | 导航文档结构 |
cursor | goto_deral、goto_position、position、context | 光标导航 |
selection | 段落、范围、删除、替换 | 文本选择和操作 |
search | 查找、替换、替换_all | 查找和替换(跟踪更改感知) |
track_changes | 状态、启用、禁用、列表、接受、拒绝、接受全部、拒绝全部 | 修订跟踪 |
comments | 列表,添加 | 评论管理 |
save | 保存、导出 | 保存和导出文档 |
text | 插入,格式化 | 插入和格式化文本 |
2.LibreOffice扩展(libreoffice-mcp-extension.oxt)
LibreOffice扩展,在端口8765上为MCP服务器提供HTTP API以供连接。
设置
1.安装LibreOffice扩展
# Install via LibreOffice
unopkg add libreoffice-mcp-extension.oxt或:工具→ 扩展管理器→ Add → 选择.oxt文件
2.创建虚拟环境
uv venv
source .venv/bin/activate
uv pip install fastmcp httpx3.配置克劳德代码
增添 .mcp.json:
{
"mcpServers": {
"libreoffice": {
"command": "/home/vboxuser/projects/libreoffice-mcp/run_libreoffice_mcp.sh",
"args": []
}
}
}用法
- 启动LibreOffice编写程序
- 启动MCP服务器 LibreOffice:工具→ MCP服务器→ 启动MCP服务器
- 使用克劳德代码 使用LibreOffice工具
示例命令
# Check connection
document(action="status")
# Create new document
document(action="create", doc_type="writer")
# Get document content
document(action="content")
# Insert text at cursor
text(action="insert", content="Hello, World!")
# Find and replace
search(action="replace_all", old="foo", new="bar")
# Enable track changes
track_changes(action="enable")
# Save document
save(action="save", file_path="/path/to/document.odt")与Zotero集成
此MCP服务器与 Zotero MCP服务器 完整的学术写作工作流程:
- LibreOffice MCP -文档编辑和格式化
- Zotero MCP -使用可扫描引文标记进行引文管理
- Zotero ODF插件 -将标记转换为实时引用
文件
libreoffice_mcp_server.py-MCP服务器(FastMCP)libreoffice-mcp-extension.oxt-LibreOffice扩展run_libreoffice_mcp.sh-Claude代码的包装脚本
