LibreOffice MCP Tools
# LibreOffice MCP Tools
[](https://npmjs.org/package/@passerbyflutter/libreoffice-mcp-tools)
> [!WARNING]
> This project was **written by GitHub Copilot** and has not been fully reviewed by a human.
> Code may contain bugs, security issues, or unexpected behavior. **Use at your own risk.** Do not use in production without thorough review.
A [Model Context Protocol (MCP)](https://modelcontextprotocol.io) server that gives AI agents (Claude, Copilot, Gemini, Cursor, etc.) the ability to **read, write, and edit Office documents** via LibreOffice โ with a token-efficient design that minimizes LLM context usage.
Inspired by the architecture of [chrome-devtools-mcp](https://github.com/ChromeDevTools/chrome-devtools-mcp).
## โจ Features
- **22 MCP tools** covering reading, writing, spreadsheets, and presentations
- **Token-efficient design**: outline-first navigation, range-based access, pagination
- **Broad format support**: DOCX, DOC, XLSX, XLS, PPTX, PPT, ODT, ODS, ODP, RTF, CSV, TXT, PDF
- **Legacy format bridge**: `.doc`, `.xls`, `.ppt` auto-converted via LibreOffice before parsing
- **No LibreOffice required for basic reads**: native parsers handle DOCX, XLSX, PPTX directly
- **LibreOffice required for**: legacy formats, PDF export, format conversion
## ๐ Supported Formats
| Format | Extensions | Read | Write | Method |
|---|---|---|---|---|
| Word 2007+ | `.docx`, `.dotx` | โ
| โ
| Native (mammoth read / JSZip OOXML write) |
| Word 97-2003 | `.doc`, `.dot` | โ
| โ
| LibreOffice bridge |
| Excel 2007+ | `.xlsx`, `.xlsm` | โ
| โ
| Native (ExcelJS) |
| Excel 97-2003 | `.xls` | โ
| โ
| LibreOffice bridge |
| PowerPoint 2007+ | `.pptx` | โ
| โ
| Native (JSZip OOXML) |
| PowerPoint 97-2003 | `.ppt` | โ
| โ
| LibreOffice bridge |
| OpenDocument Text | `.odt` | โ
| โ
| LibreOffice bridge |
| OpenDocument Spreadsheet | `.ods` | โ
| โ
| LibreOffice bridge |
| OpenDocument Presentation | `.odp` | โ
| โ
| LibreOffice bridge |
| Rich Text Format | `.rtf` | โ
| โ
| LibreOffice bridge |
| CSV | `.csv` | โ
| โ
| Native |
| PDF | `.pdf` | โ
(text) | โ | LibreOffice CLI |
| Plain text | `.txt` | โ
| โ
| Native |
## ๐ Quick Start
### Prerequisites
- **Node.js 20+**
- **LibreOffice** (optional for basic DOCX/XLSX/PPTX reads; required for .doc/.xls/.ppt and format conversion)
- Windows: [Download LibreOffice](https://www.libreoffice.org/download/download/)
- macOS: `brew install --cask libreoffice`
- Linux: `sudo apt install libreoffice` or `sudo dnf install libreoffice`
### Installation
**Using npx (recommended โ no install needed):**
```json
{
"mcpServers": {
"libreoffice": {
"command": "npx",
"args": ["-y", "@passerbyflutter/libreoffice-mcp-tools"]
}
}
}
```
**Global install:**
```bash
npm install -g @passerbyflutter/libreoffice-mcp-tools
```
**From source:**
```bash
git clone https://github.com/passerbyflutter/libreoffice-mcp-tools
cd libreoffice-mcp-tools
npm install
npm run build
```
### Configure your MCP client
Add to your MCP client configuration (e.g., Claude Desktop `claude_desktop_config.json`):
```json
{
"mcpServers": {
"libreoffice": {
"command": "npx",
"args": ["-y", "@passerbyflutter/libreoffice-mcp-tools"],
"env": {
"SOFFICE_PATH": "/path/to/soffice"
}
}
}
}
```
Or use `.mcp.json` at your project root:
```json
{
"mcpServers": {
"libreoffice": {
"command": "npx",
"args": ["-y", "@passerbyflutter/libreoffice-mcp-tools"]
}
}
}
```
### CLI Options
```
node build/bin/libreoffice-mcp.js [options]
--libreoffice-path <path> Path to soffice executable
(default: auto-detected or SOFFICE_PATH env)
```
## ๐ Tool Reference
### Document Management
| Tool | Description |
|---|---|
| `document_open` | Open a file โ returns `docId` handle. Auto-bridges legacy formats. |
| `document_close` | Release document handle and temp files |
| `document_list` | List all open documents |
| `document_create` | Create new empty document (writer/calc/impress) |
| `document_save` | Save to current or new path |
| `document_export` | Export via LibreOffice (PDF, HTML, CSV, etc.) |
| `document_convert` | Convert file format (DOCโDOCX, XLSXโCSV, etc.) |
### Reading (Token-Efficient)
| Tool | Description |
|---|---|
| `document_get_metadata` | Title, author, word/page count, dates |
| `document_get_outline` | Headings (Writer) / sheet names (Calc) / slide titles (Impress) |
| `document_read_text` | Paginated document text as Markdown |
| `document_read_range` | Specific paragraph or slide range |
| `document_search` | Find text with surrounding context |
### Writing (Writer)
| Tool | Description |
|---|---|
| `document_insert_text` | Insert at start/end/after heading |
| `document_replace_text` | Find & replace (first or all occurrences) |
| `document_insert_paragraph` | Insert paragraph at specific index |
| `document_apply_style` | Apply heading/paragraph style |
### Spreadsheet (Calc)
| Tool | Description |
|---|---|
| `spreadsheet_list_sheets` | Sheet names with row/col counts |
| `spreadsheet_get_range` | Cell range as JSON + markdown table |
| `spreadsheet_set_cell` | Set cell value or formula |
| `spreadsheet_set_range` | Set 2D range of values |
| `spreadsheet_add_sheet` | Add new sheet |
| `spreadsheet_get_formulas` | Get formula expressions in range |
### Presentation (Impress)
| Tool | Description |
|---|---|
| `presentation_list_slides` | Slide titles with index |
| `presentation_get_slide` | Full slide content (title, body, notes) |
| `presentation_get_notes` | Speaker notes |
| `presentation_add_slide` | Add new slide (requires LibreOffice) |
| `presentation_update_slide` | Update slide content |
## ๐ก Token-Saving Workflow
For maximum token efficiency, follow this pattern:
```
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
```
Instead of dumping the entire document, you navigate to exactly what you need.
**Spreadsheet workflow:**
```
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
```
## ๐ Architecture
```
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
```
## ๐งช Testing
```bash
# Create sample fixtures
node tests/create-fixtures.mjs
# Run smoke tests
npm test
```
## ๐ Environment Variables
| Variable | Description |
|---|---|
| `SOFFICE_PATH` | Path to LibreOffice `soffice` executable |
| `DEBUG` | Set to `lo-mcp:*` for verbose logging |
## ๐ License
MIT
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.