
xlsx-tools-mcp
io.github.ruriazzPublished by GitHub account ruriazzv0.3.2Updated Oct 24, 2026
MCP server for accurate, structure-preserving read/write access to Excel (.xlsx) files
Overview
Local MCP server that gives an assistant 29 tools to read, query and edit Excel .xlsx workbooks while preserving their existing structure, styles and formulas.
- What you can do
- List preloaded workbooks, sheets and workbook metadata, and read cell ranges or single cells with formatting detail
- Search values across sheets, profile sheet data, and filter or aggregate rows with pandas expressions
- Create workbooks and sheets, write cells and formulas, append rows, and insert or delete rows and columns
- Rename, copy, merge, unmerge and clear ranges, apply cell styles, autofit columns, and build native tables and charts
- Recalculate formulas through headless LibreOffice, report formula errors, and restore .bak backups
- When to use it
- Useful when an assistant needs to inspect or modify real Excel files on the user's machine rather than plain CSV, especially when existing formatting, formulas and layout must survive edits. Also fits data profiling, filtering and aggregation tasks inside spreadsheets.
- Requirements
- Runs locally as a stdio process from the PyPI package (Python 3.10 or newer), typically launched with uvx or pip. LibreOffice is optional but recommended for formula recalculation. Optional environment variables: XLSX_MCP_FILES, XLSX_MCP_ALLOWED_DIRS, XLSX_MCP_AUTO_BACKUP, XLSX_MCP_BACKUP_DIR, XLSX_MCP_LOCK_TIMEOUT, XLSX_MCP_RECALC_TIMEOUT.
Installation
In SourceWeft
- Open xlsx-tools-mcp in the dashboard and add it to a workspace.
- Enable the server for the chats that should use its tools.
Desktop only via STDIO. STDIO servers start a local process, so they need the SourceWeft desktop host.
Other MCP clients
Follow the launch instructions in the repository.
README
xlsx-tools-mcp
An MCP server for reading and writing Excel (.xlsx) files with high accuracy, while preserving the file's existing structure, styles, and formulas.
[CI] [PyPI Version] [Downloads/month] [Listed on mcpservers.org]
Overview
xlsx-tools-mcp exposes 29 Model Context Protocol (MCP) tools that give an LLM agent accurate, structure-preserving read and write access to Excel .xlsx files. It runs as a standard stdio MCP server: you install it and register it with an MCP client (Claude Code, OpenCode, etc.), and the client's agent can list sheets, read cell ranges, search values, aggregate data, write cells/formulas, manage sheets/rows/columns, apply styles, and force formula recalculation.
It is built around the principle that editing an existing workbook should not destroy what it doesn't touch.
Features
- Structure-preserving writes via openpyxl — writes load the existing workbook and save it back, preserving styles, merged cells, comments, and any aspect the edit doesn't touch.
- Never-stale formula results via LibreOffice recalculation — openpyxl writes formula strings but never evaluates them. After every value/formula write the server runs a headless LibreOffice pass to recompute real results, then returns
errors_found— any Excel error values (#REF!,#DIV/0!,#N/A, …) produced by the recalculation. - Fast reads via python-calamine — a Rust-backed parser for accurate, fast type inference, with an automatic openpyxl fallback when you need formulas/styles/comments or when calamine can't parse the file.
- pandas-based grouping/aggregation & querying —
aggregate_sheetandquery_sheetperform operations without destroying source structure, equipped with AST expression validation to block code injection. - Native Excel objects — create formal Excel Tables (
create_table) with autofilter and styles, and native charts (create_chartfor bar, line, pie, scatter). - Sheet lifecycle & formatting — rename sheets (
rename_sheet), duplicate sheets with styles intact (copy_sheet), clear ranges (clear_range), and auto-fit column widths (autofit_columns). - Cross-platform reliability (Windows, macOS, Linux) — case-insensitive path confinement, comma or semicolon
;environment delimiters, safe atomic file replacement with transient lock retry (WinError 32/ antivirus defense), and silent headless recalculation without window flicker. - Per-file locking — concurrent tool calls (or other processes) touching the same workbook are serialized via a sibling
<path>.lockfile (filelock), so writes never interleave and corrupt the file. - Path confinement —
XLSX_MCP_ALLOWED_DIRS(comma or semicolon-separated) restricts all reads and writes to specific directories. If set, any attempt to access a file outside these boundaries raisesAccessDeniedError. Case-insensitive path comparisons and multi-drive paths on Windows are supported. - Auto-backup & restore — Write tools automatically create a
.baksibling file before modifying the workbook ifbackup=True(which defaults toXLSX_MCP_AUTO_BACKUP=true). Userestore_backupto atomically revert changes. - Formula injection guard —
write_cellsandappend_rowsreject formulas containingWEBSERVICE,HYPERLINK,INDIRECT,RTD,CALL,REGISTER, or DDE commands (|) by default to prevent data exfiltration or malicious links. Passallow_external_formulas=Trueto bypass this check. - XML-bomb protection — the
defusedxmlpackage is an automatic dependency; openpyxl detects it and uses its hardened XML parser, so hostilexlsxXML can't expand into resource exhaustion. - Preload files at startup — set
XLSX_MCP_FILESto preload one or more workbooks (comma or semicolon-separated); tools can then be called withpathomitted or with a short alias instead of a full filesystem path.
Download Stats
[Downloads/month] [Downloads/week]
Live via pypistats.org, non-mirror downloads. These count download events, not unique users or installs — one user can trigger many downloads (CI, reinstalls, Docker rebuilds, mirrors).
Architecture
The io layer (io/) is deliberately decoupled from the MCP transport (server.py). Each MCP tool is a thin wrapper that resolves the target path, takes the per-file lock, and calls one io-layer function. This keeps the core logic independent of MCP, so it can be tested directly (see tests/).
The recalculation tradeoff
After a write that touches cell values or formulas, the server runs soffice --headless --convert-to xlsx on the file so every formula gets a real computed value. This round-trip recomputes formulas but re-exports the whole workbook — it is a tradeoff, not a guarantee of bit-perfect preservation. Features that openpyxl would otherwise preserve may not survive identically: pivot tables, charts, data validation, some formats, and some defined names.
If you're working on a structurally complex workbook where that risk matters, you can pass recalculate=False on the value/formula-writing tools (write_cells, append_rows, insert_rows, delete_rows, insert_columns, delete_columns) to save with openpyxl only and skip the round-trip entirely.
Requirements
- Python ≥ 3.10
- LibreOffice — optional but recommended. Needed only for formula recalculation. Without it, writes still succeed (saved via openpyxl) but formulas are not recomputed and a warning is returned in the
messagefield.
Install LibreOffice:
The server finds LibreOffice by checking soffice / libreoffice on PATH, the standard macOS install location (/Applications/LibreOffice.app/Contents/MacOS/soffice), and standard Windows paths (%ProgramFiles%\LibreOffice\program\soffice.exe, etc.). On Windows, headless recalculation runs silently without window flicker (CREATE_NO_WINDOW) and with isolated user profiles.
Installation
The server speaks stdio transport (standard MCP): after installation it waits for an MCP client to connect and call tools. You don't usually run it yourself; you register it with a client.
1. From PyPI via uvx (recommended — no clone)
uvx fetches and runs the published package without polluting your project. This is the simplest way to power up an MCP client (see configuration snippets below).
2. From source
3. Via pip
This installs the console entry point, so you can run the server directly:
Configuration for MCP clients
The simplest registration for every client uses uvx xlsx-tools-mcp (no clone, always the published version).
Tip for Windows: In JSON client configuration files (
.mcp.json,opencode.json), use forward slashes (e.g."C:/path/to/data.xlsx") or escaped backslashes (e.g."C:\\\\path\\\\to\\\\data.xlsx") to prevent JSON escape sequence errors.
Claude Code
Or via .mcp.json in your project:
OpenCode
In opencode.json (project) or ~/.config/opencode/opencode.json (global):
When running from a source clone
If you cloned the repo instead of installing from PyPI, point the client at your local checkout by swapping uvx xlsx-tools-mcp for the dynamic uv run form (use the absolute path to the clone):
Claude Code .mcp.json:
OpenCode:
Replace /absolute/path/to/xlsx-reader with the actual location of your clone.
Preloading files (XLSX_MCP_FILES)
Set the XLSX_MCP_FILES environment variable in the MCP server config env section (not your interactive shell — the server is launched by the client) to preload workbooks at startup. Format: comma- or semicolon-separated alias=absolute/path entries, or bare absolute paths:
Bare paths get an alias defaulting to the filename:
With alias/filename as the alias:
- One file configured → every tool can be called with
pathomitted entirely. - Multiple files configured → pass the alias (or filename) as
path. list_configured_files()returns the alias → absolute-path mapping.- Raw absolute and relative paths still work for files you didn't preload.
Claude Code — .mcp.json with preloading:
OpenCode with preloading:
Tool reference
All 29 tools. Unless noted, path accepts a filesystem path, a preloaded alias/filename, or may be omitted when exactly one file is preloaded. create_workbook is the exception — its path is required because a new file is never preloaded.
Response shape (all write tools): every write tool returns
{"saved": bool, "recalculated": bool, "errors_found": list, "message": str}. When non-empty,errors_foundis a list of{"sheet": "...", "cell": "B2", "error": "#DIV/0!"}.
Inspect / Read
Write
Example payload — write_cells
A call writing a formula and a value:
Matching response:
If a formula this touches produced an error, errors_found would look like:
Example payload — query_sheet
Example payload — create_table & create_chart
Environment variables
Security & concurrency
- Path confinement —
XLSX_MCP_ALLOWED_DIRS(comma or semicolon-separated) restricts all reads and writes to specific directories. If set, any attempt to access a file outside these boundaries raisesAccessDeniedError. Case-insensitive path comparisons and multi-drive paths on Windows are supported. - Auto-backup & restore — Write tools will automatically create a
.baksibling file before modifying the workbook ifbackup=True(which defaults toXLSX_MCP_AUTO_BACKUP=true). UseXLSX_MCP_BACKUP_DIRto save backups to a specific folder. Userestore_backupto atomically revert changes. - Formula injection guard —
write_cellsandappend_rowsreject formulas containingWEBSERVICE,HYPERLINK,INDIRECT,RTD,CALL,REGISTER, or DDE commands (|) by default to prevent data exfiltration or command execution. Passallow_external_formulas=Trueto bypass this check. - AST safe query validation —
query_sheetuses an AST parser to strictly allow only comparisons, boolean logic, and safe operators, blocking@variable lookups, code execution calls, and private dunder attributes. - XML-bomb protection —
defusedxmlis an automatic dependency of this package. openpyxl auto-detects it and uses its hardened XML parser, so a malicious.xlsx(a zip of XML) can't trigger entity-expansion resource exhaustion. No configuration needed. - Per-file locking — every read/write acquires a sibling
<path>.lockfile (viafilelock). Concurrent tool calls or other processes touching the same workbook are serialized so writes never interleave and corrupt the file. - Transient lock resilience — on Windows NTFS, atomic file swaps can momentarily encounter sharing violations (
WinError 32/33) while antivirus scanners or search indexers inspect newly saved files. The server performs an exponential backoff retry to transparently succeed once released, or provides a clear guidance message if the file is permanently open in Microsoft Excel. - Recalc timeout —
XLSX_MCP_RECALC_TIMEOUT(seconds, default60) caps how long the LibreOffice recalculation pass may run. - Lock timeout —
XLSX_MCP_LOCK_TIMEOUT(seconds, default10) caps how long a tool will wait to acquire the per-file lock before failing.
Troubleshooting
errors_foundis empty even though my formula is broken — recalculation likely didn't run. Check themessagefield: if it says LibreOffice wasn't found, the file was saved via openpyxl as-is and formulas were not recomputed (cached values may be stale). Install LibreOffice (see Requirements).- Recalculation is slow or times out — raise
XLSX_MCP_RECALC_TIMEOUT(default 60s). On timeout, the file is still saved, butrecalculatedwill befalseandmessagesays the recalc timed out. LockTimeoutErroron concurrent access — another operation holds the lock. RaiseXLSX_MCP_LOCK_TIMEOUT(default 10s), or retry when the other operation finishes.Workbook is locked by another process/WinError 32— on Windows, Microsoft Excel and some applications lock open files exclusively. Close the workbook in Excel and retry. Transient locks from antivirus scanners or search indexers are automatically retried by the server before failing.- "Sheet not found" — the error message lists the available sheet names, so you can pick the correct one.
pathrequired / no file configured — you called a tool withoutpathbut no (or multiple) files are preloaded. Preload one file viaXLSX_MCP_FILES, pass an explicit alias, or pass a raw path.
Development / Contributing
See CONTRIBUTING.md. Run the test suite with:
Source: README.md at commit 452c821
Tools
0Version history
4- v0.3.2LatestOct 17, 2026
- v0.3.1Oct 9, 2026
- v0.3.0Oct 3, 2026
- v0.1.1Sep 16, 2026
Score
50% of the applicable checks met
How complete this listing is, computed from the registry entry, the endpoint and public sources. Not a rating of the server and not a statement that it is safe or working today: reachability is a dated check, and no installs or reviews go into the score.
- Reached in the last 30 days25 pts
Keep the endpoint answering the MCP handshake; SourceWeft probes it every 30 days.
- Auth declared10 pts
Declare the credential headers in the registry entry, or keep the endpoint answering the probe so its auth can be classified.
- Tools listed15 pts
Answer tools/list without a credential, or ship a package that starts in a sandbox without one.
- DescriptionRequired15 pts
- Logo10 pts
- Documentation15 pts
- License10 pts
