libre-mcp

libre-mcp

MCP server for controlling LibreOffice (Writer and Calc) via the UNO API, enabling document creation, editing, saving, and export from AI clients.

Category
访问服务器

README

libre-mcp

A stdio MCP server for controlling LibreOffice (Writer and Calc) from Claude Code and other MCP clients, over the UNO automation API. macOS and Linux.

Architecture

Two processes, both Python:

Full docs: libre-mcp.krondor.org.

Claude Code ──stdio JSON-RPC──▶  libre-mcp server   (uv, Python >=3.12, mcp SDK)
                                      │ spawns + supervises
                                      ├─▶ headless soffice   (isolated profile + named pipe)
                                      └─▶ uno_worker.py       (LibreOffice's Python, stdlib-only)
                                            └─ newline-JSON RPC over stdio
  • The server owns the MCP stdio channel, defines the tools, and supervises the other two processes. It runs on a normal uv-managed Python ≥3.12 with the mcp SDK.
  • A headless soffice is launched with an isolated UserInstallation profile and a unique named pipe (not a TCP port), so concurrent instances never race over a shared port — important for parallel git worktrees.
  • The UNO worker (src/office/uno_worker.py) runs under LibreOffice's Python — the only interpreter that can reliably import uno. It is intentionally stdlib-only, so there is nothing to install alongside LibreOffice. (On Debian/Ubuntu it falls back to the system python3 provided by python3-uno.)

Instances are disposable: if the URP bridge is disposed (soffice died), the worker reports a fatal error and the session is rebuilt, retrying the call once.

Install

curl -fsSL https://raw.githubusercontent.com/krondor-corp/libre-mcp/main/install.sh | bash
claude mcp add libre -- libre-mcp

Downloads a prebuilt, self-contained binary (no Python needed on the host). Update in place with libre-mcp update.

Requirements

  • LibreOffice installed:
    • macOS: /Applications/LibreOffice.app
    • Debian/Ubuntu: apt install libreoffice-writer libreoffice-calc python3-uno
    • TDF/opt Linux builds bundle their own Python and need nothing extra.

Paths are auto-discovered; override with LIBRE_MCP_SOFFICE_PATH / LIBRE_MCP_PYTHON_PATH if needed. (uv is only needed for development.)

Develop

make sync        # uv sync (dev deps)
make check       # fmt-check + lint + types + test
make inspect     # run the MCP Inspector against the server

make test runs unit tests always; the end-to-end tests run only when LibreOffice is found, otherwise they skip.

Run it locally (dev client)

dev/client.py spawns the server exactly as an MCP host would, does the initialize handshake, and drives tools — no registration needed.

make dev-list          # list the tools
make dev-demo          # scripted writer -> PDF round-trip

For ad-hoc multi-step sessions, pipe TOOL {json-args} lines into run. A single run keeps one server (and one LibreOffice) alive for the whole batch, so doc_ids persist across calls (first created doc is doc-1, next doc-2, …):

uv run python dev/client.py run <<'EOF'
create_document {"kind": "calc"}
set_cells {"doc_id": "doc-1", "cells": [{"cell": "A1", "value": 21}, {"cell": "A2", "formula": "=A1*2"}]}
read_cells {"doc_id": "doc-1", "range": "A1:A2"}
EOF

Register with Claude Code

A project-scoped .mcp.json is committed with a relative command (./bin/run.sh), so a fresh checkout / worktree self-registers and runs its own copy. Or register explicitly:

claude mcp add --transport stdio libre -- $(pwd)/bin/run.sh

Parallel worktrees

The design is worktree-safe by construction:

  • Unique named pipe per instance — no shared TCP port to race over, so two worktrees (or two sessions) starting at the same moment never collide.
  • cwd-relative profiles — .lo_profiles/instance-<pipe> lives under each worktree's own directory, fully isolated and gitignored.
  • Clean reaping — the server tears down its soffice + worker when the client disconnects (lifespan hook), so worktrees don't leak LibreOffice processes.
  • Relative .mcp.json — each worktree registers/runs its own bin/run.sh.

Tools

Tool Purpose
create_document(kind) New writer/calc/impress/draw doc → doc_id
open_document(path) Open a file → doc_id
list_documents() / document_info(doc_id) Inspect open docs
save_document(doc_id, path?, format?) Save in place or to a path
export_document(doc_id, path, format?) Export (pdf, docx, xlsx, csv, …)
close_document(doc_id) Close a doc
get_text(doc_id) Read a Writer doc's text
insert_text(doc_id, text, paragraph_break?) Append text
find_and_replace(doc_id, search, replace, regex?) Replace text
set_cells(doc_id, cells, sheet?) Write Calc cells/formulas
read_cells(doc_id, range, sheet?) Read a Calc range

Configuration

Env var Default Meaning
LIBRE_MCP_SOFFICE_PATH auto soffice binary override
LIBRE_MCP_PYTHON_PATH auto bundled python override
LIBRE_MCP_PROFILE_DIR ./.lo_profiles per-instance profile root
LIBRE_MCP_KEEP_PROFILE false keep profiles for debugging
LIBRE_MCP_STARTUP_TIMEOUT 30 seconds to wait for soffice
LIBRE_MCP_LOG_LEVEL INFO stderr log level

UNO transport uses a unique named pipe per instance (not a TCP port), so nothing needs configuring and concurrent instances never collide.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选