LibreOffice MCP Tools

LibreOffice MCP Tools

Enables AI agents to read, write, and edit Office documents via LibreOffice with token-efficient design. Supports multiple formats including DOCX, XLSX, PPTX, and legacy formats through LibreOffice bridge.

Category
访问服务器

README

LibreOffice MCP Tools

npm version

[!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) 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.

✨ 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
    • macOS: brew install --cask libreoffice
    • Linux: sudo apt install libreoffice or sudo dnf install libreoffice

Installation

Using npx (recommended — no install needed):

{
  "mcpServers": {
    "libreoffice": {
      "command": "npx",
      "args": ["-y", "@passerbyflutter/libreoffice-mcp-tools"]
    }
  }
}

Global install:

npm install -g @passerbyflutter/libreoffice-mcp-tools

From source:

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):

{
  "mcpServers": {
    "libreoffice": {
      "command": "npx",
      "args": ["-y", "@passerbyflutter/libreoffice-mcp-tools"],
      "env": {
        "SOFFICE_PATH": "/path/to/soffice"
      }
    }
  }
}

Or use .mcp.json at your project root:

{
  "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

# 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

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选