LibreOffice MCP Tools
LibreOffice MCP 工具
[!WARNING] 本项目由 GitHub Copilot 编写,未经人工全面审核。 代码可能包含错误、安全问题或意外行为。使用风险自负。 在未经过彻底审查的情况下,请勿在生产环境中使用。
A Model Context Protocol (MCP) 服务器,使 AI 智能体(Claude、Copilot、Gemini、Cursor 等)能够通过 LibreOffice 读取、写入和编辑 Office 文档 —— 采用节省 Token 的设计,最大限度地减少 LLM 上下文的使用。
灵感来源于 chrome-devtools-mcp 的架构。
✨ 特性
22 个 MCP 工具,涵盖读取、写入、电子表格和演示文稿
节省 Token 的设计:大纲优先导航、基于范围的访问、分页
广泛的格式支持:DOCX, DOC, XLSX, XLS, PPTX, PPT, ODT, ODS, ODP, RTF, CSV, TXT, PDF
旧版格式桥接:
.doc,.xls,.ppt在解析前通过 LibreOffice 自动转换基础读取无需 LibreOffice:原生解析器直接处理 DOCX, XLSX, PPTX
以下情况需要 LibreOffice:旧版格式、PDF 导出、格式转换
Related MCP server: docx-mcp-server
📋 支持的格式
格式 | 扩展名 | 读取 | 写入 | 方法 |
Word 2007+ |
| ✅ | ✅ | 原生 (mammoth 读取 / JSZip OOXML 写入) |
Word 97-2003 |
| ✅ | ✅ | LibreOffice 桥接 |
Excel 2007+ |
| ✅ | ✅ | 原生 (ExcelJS) |
Excel 97-2003 |
| ✅ | ✅ | LibreOffice 桥接 |
PowerPoint 2007+ |
| ✅ | ✅ | 原生 (JSZip OOXML) |
PowerPoint 97-2003 |
| ✅ | ✅ | LibreOffice 桥接 |
OpenDocument Text |
| ✅ | ✅ | LibreOffice 桥接 |
OpenDocument Spreadsheet |
| ✅ | ✅ | LibreOffice 桥接 |
OpenDocument Presentation |
| ✅ | ✅ | LibreOffice 桥接 |
Rich Text Format |
| ✅ | ✅ | LibreOffice 桥接 |
CSV |
| ✅ | ✅ | 原生 |
| ✅ (文本) | ❌ | LibreOffice CLI | |
纯文本 |
| ✅ | ✅ | 原生 |
🚀 快速开始
前置要求
Node.js 20+
LibreOffice (基础 DOCX/XLSX/PPTX 读取可选;.doc/.xls/.ppt 及格式转换必需)
Windows: 下载 LibreOffice
macOS:
brew install --cask libreofficeLinux:
sudo apt install libreoffice或sudo dnf install libreoffice
安装
使用 npx (推荐 — 无需安装):
{
"mcpServers": {
"libreoffice": {
"command": "npx",
"args": ["-y", "@passerbyflutter/libreoffice-mcp-tools"]
}
}
}全局安装:
npm install -g @passerbyflutter/libreoffice-mcp-tools从源码安装:
git clone https://github.com/passerbyflutter/libreoffice-mcp-tools
cd libreoffice-mcp-tools
npm install
npm run build配置你的 MCP 客户端
添加到你的 MCP 客户端配置中(例如 Claude Desktop 的 claude_desktop_config.json):
{
"mcpServers": {
"libreoffice": {
"command": "npx",
"args": ["-y", "@passerbyflutter/libreoffice-mcp-tools"],
"env": {
"SOFFICE_PATH": "/path/to/soffice"
}
}
}
}或者在项目根目录使用 .mcp.json:
{
"mcpServers": {
"libreoffice": {
"command": "npx",
"args": ["-y", "@passerbyflutter/libreoffice-mcp-tools"]
}
}
}CLI 选项
node build/bin/libreoffice-mcp.js [options]
--libreoffice-path <path> Path to soffice executable
(default: auto-detected or SOFFICE_PATH env)🛠 工具参考
文档管理
工具 | 描述 |
| 打开文件 → 返回 |
| 释放文档句柄和临时文件 |
| 列出所有打开的文档 |
| 创建新的空文档 (Writer/Calc/Impress) |
| 保存到当前或新路径 |
| 通过 LibreOffice 导出 (PDF, HTML, CSV 等) |
| 转换文件格式 (DOC→DOCX, XLSX→CSV 等) |
读取 (节省 Token)
工具 | 描述 |
| 标题、作者、字数/页数、日期 |
| 标题 (Writer) / 工作表名称 (Calc) / 幻灯片标题 (Impress) |
| 以 Markdown 格式分页读取文档文本 |
| 指定段落或幻灯片范围 |
| 查找带有周围上下文的文本 |
写入 (Writer)
工具 | 描述 |
| 在开头/结尾/标题后插入 |
| 查找并替换 (首次或所有匹配项) |
| 在指定索引处插入段落 |
| 应用标题/段落样式 |
电子表格 (Calc)
工具 | 描述 |
| 带有行/列计数的工作表名称 |
| 以 JSON + Markdown 表格形式获取单元格范围 |
| 设置单元格值或公式 |
| 设置二维值范围 |
| 添加新工作表 |
| 获取范围内的公式表达式 |
演示文稿 (Impress)
工具 | 描述 |
| 带有索引的幻灯片标题 |
| 完整的幻灯片内容 (标题、正文、备注) |
| 演讲者备注 |
| 添加新幻灯片 (需要 LibreOffice) |
| 更新幻灯片内容 |
💡 节省 Token 的工作流
为了实现最大的 Token 效率,请遵循此模式:
1. document_open(filePath) → get docId
2. document_get_metadata(docId) → understand size/type
3. document_get_outline(docId) → see structure
4. document_read_range(docId, startIndex=N, endIndex=M) → read specific section不要一次性转储整个文档,而是导航到你真正需要的部分。
电子表格工作流:
1. document_open(path) → docId
2. spreadsheet_list_sheets(docId) → see all sheets
3. spreadsheet_get_range(docId, sheetName="Sales", range="A1:D20") → targeted data🏗 架构
src/
├── index.ts # createMcpServer() — MCP server factory
├── LibreOfficeAdapter.ts # soffice subprocess manager
├── DocumentContext.ts # Open document registry
├── DocumentSession.ts # Per-document state + format bridge
├── McpResponse.ts # Response builder (text/JSON/markdown)
├── Mutex.ts # Serializes LibreOffice subprocess calls
├── parsers/
│ ├── DocxParser.ts # DOCX read → {paragraphs, outline, metadata} (mammoth)
│ ├── DocxOoxmlEditor.ts # DOCX write → direct JSZip OOXML manipulation (format-preserving)
│ ├── XlsxParser.ts # XLSX read/write via ExcelJS
│ ├── PptxParser.ts # PPTX read → {slides[]} (JSZip XML)
│ └── PptxOoxmlEditor.ts # PPTX write → add/update slides, create PPTX (JSZip OOXML)
├── formatters/
│ ├── MarkdownFormatter.ts
│ ├── JsonFormatter.ts
│ └── TableFormatter.ts # Spreadsheet → Markdown table
└── tools/
├── documents.ts # open/close/list/create
├── reader.ts # metadata/outline/read/search
├── writer.ts # insert/replace/style
├── spreadsheet.ts # get/set cells/ranges/sheets
├── presentation.ts # slides/notes
└── converter.ts # save/export/convert🧪 测试
# Create sample fixtures
node tests/create-fixtures.mjs
# Run smoke tests
npm test📝 环境变量
变量 | 描述 |
| LibreOffice |
| 设置为 |
📄 许可证
MIT
Available Tools
27 toolsdocument_apply_styleC
Apply a heading or paragraph style to a specific paragraph by index.
Inputs: docId (required), paragraphIndex (required), style (required).
document_closeA
Close an open document and release its resources (including any temp files from format bridging).
Inputs: docId (required).
document_convertA
Convert a document file to a different format using LibreOffice CLI. Creates a new file; original is not modified. Useful for: DOC→DOCX, DOCX→PDF, XLSX→CSV, etc. LibreOffice must be installed.
Inputs: filePath (required), format (required), outputPath.
document_createB
Create a new empty document and open it. Returns a docId. Supports creating: writer (text document → .docx), calc (spreadsheet → .xlsx), impress (presentation → .pptx).
Inputs: documentType (required), filePath (required).
document_exportA
Export a document to a different format using LibreOffice. Supports exporting to: PDF, HTML, TXT, DOCX, XLSX, PPTX, ODT, ODS, ODP, CSV. LibreOffice must be installed.
Inputs: docId (required), format (required), outputPath.
document_get_metadataA
Get metadata for an open document: title, author, page count, word count, format, file size, dates. Token-efficient: use this before reading document content to understand its size and structure.
Inputs: docId (required).
document_get_outlineA
Get the structural outline of a document:
Writer documents: headings hierarchy (H1, H2, H3...)
Calc spreadsheets: list of sheet names with row/column counts
Impress presentations: slide titles with index numbers Token-efficient: always call this before document_read_text to understand structure.
Inputs: docId (required).
document_insert_paragraphC
Insert a new paragraph at a specific index in a Writer document.
Inputs: docId (required), text (required), index (required), style.
document_insert_textB
Insert text into a Writer document at a specified position. Position options: 'start' (beginning), 'end' (end of document), or after a specific heading text.
Inputs: docId (required), text (required), position, headingText, +1 more.
document_listB
List all currently open documents with their docId, file path, format, and size.
Inputs: no named parameters.
document_openA
Open a document file and return a docId handle for use with other tools. Supports: .docx, .doc, .xlsx, .xls, .pptx, .ppt, .odt, .ods, .odp, .rtf, .csv, .txt, .pdf Legacy binary formats (.doc, .xls, .ppt, .odt, .ods, .odp, .rtf) are automatically converted via LibreOffice before parsing. Returns docId to use with all other document tools.
Inputs: filePath (required).
document_read_rangeA
Read a specific range of a document by paragraph index (for Writer) or slide index (for Impress). More token-efficient than document_read_text when you only need a specific section.
Inputs: docId (required), startIndex (required), endIndex.
document_read_textA
Read document content as Markdown text. For large documents, use limit/offset for pagination. Default returns up to 4000 characters. Use document_get_outline first to understand structure.
Inputs: docId (required), limit, offset, maxChars.
document_replace_textC
Find and replace text in a Writer document. Optionally replace all occurrences.
Inputs: docId (required), find (required), replace (required), replaceAll, +1 more.
document_saveB
Save the current state of a document to its file path (or a new path).
Inputs: docId (required), filePath.
document_searchA
Search for text within a document. Returns matching paragraphs/cells/slides with surrounding context.
Inputs: docId (required), query (required), limit.
presentation_add_slideC
Add a new slide to a presentation.
Inputs: docId (required), title (required), body, notes.
presentation_get_notesB
Get speaker notes for all slides or a specific slide.
Inputs: docId (required), slideIndex.
presentation_get_slideB
Get the full content of a specific slide: title, body text, and speaker notes.
Inputs: docId (required), slideIndex (required).
presentation_list_slidesA
List all slides in a presentation with their index and title. Token-efficient overview before reading content.
Inputs: docId (required).
presentation_update_slideC
Update the title or body text of an existing slide.
Inputs: docId (required), slideIndex (required), title, body.
spreadsheet_add_sheetC
Add a new sheet to a spreadsheet workbook.
Inputs: docId (required), sheetName (required), headers.
spreadsheet_get_formulasA
Get all formulas in a spreadsheet range (returns formula expressions, not computed values).
Inputs: docId (required), sheetName, range.
spreadsheet_get_rangeA
Read a range of cells from a spreadsheet sheet. Returns data as structured JSON and a markdown table. Use range like "A1:D10" for specific cells, or omit for paginated full sheet. Token-efficient: specify a range rather than reading the whole sheet.
Inputs: docId (required), sheetName, range, limit, +2 more.
spreadsheet_list_sheetsB
List all sheets in a spreadsheet with their names, row counts, and column counts.
Inputs: docId (required).
spreadsheet_set_cellA
Set the value or formula of a single cell in a spreadsheet. Changes are saved immediately.
Inputs: docId (required), cell (required), value (required), sheetName, +1 more.
spreadsheet_set_rangeC
Set multiple cell values in a spreadsheet. Provide a 2D array of values matching the range.
Inputs: docId (required), startCell (required), values (required), sheetName.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 27 tools
Most tools have distinct purposes with clear boundaries, such as document operations versus presentation or spreadsheet tools. However, some overlap exists: document_read_text and document_read_range both handle reading content, and document_convert and document_export both involve format conversion, which could cause minor confusion in selection.
Tool names follow a highly consistent verb_noun pattern with clear prefixes (document_, presentation_, spreadsheet_) that group related operations. All names use snake_case uniformly, making them predictable and easy to parse for agents.
With 27 tools, the count is borderline high for a single server, potentially overwhelming for agents. While the tools cover a broad range of LibreOffice operations, the number feels heavy and could be streamlined by consolidating overlapping functions like reading or conversion tools.
The tool set provides comprehensive coverage for document, presentation, and spreadsheet workflows, including creation, reading, updating, conversion, and metadata operations. There are no obvious gaps; agents can perform full CRUD/lifecycle tasks across all supported file types without dead ends.
Maintenance
Related MCP Connectors
Convert, create and edit Word, PowerPoint, Excel and PDF documents from any AI agent.
Online office suite for AI agents: edit docs, sheets, slides and PDFs in browser or via MCP.
Document conversion and OCR for AI agents: PDF, Office docs, images to text.
Real Word and Excel for agents: open your .docx/.xlsm, read, propose, apply, get it back intact.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to create, read, edit, and manipulate LibreOffice documents with support for track changes, comments, search/replace, and real-time document operations through a native extension or HTTP API.17MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to read, edit, and create Microsoft Word documents (.docx) with support for rich text, tables, and images, deployable locally or via SSE.2MIT
- AlicenseBqualityDmaintenanceEnables complete Office document lifecycle management for AI agents, including creation, editing, conversion, and templating of DOCX, XLSX, PPTX, PDF, and EML files.4057 PyPIMIT
- AlicenseNot gradedqualityAmaintenanceEnables AI agents to create and process office documents locally, including generating branded PDF, Word, Excel, and editable PowerPoint files from templates and themes, plus reading, OCR, form-filling, manipulation, and conversion of PDFs.1MIT