Skip to main content
Glama
README.md
<img src="docs/img/icon-400.png" width="96" align="right">

# office-mcp

An [MCP](https://modelcontextprotocol.io) server that lets an AI assistant
**understand, read, change and port Excel workbooks and PowerPoint decks**:
map a 25 MB calibration model in a second, see a sheet's structure as a
picture, read exact stored values, make safe edits, and export a porting spec
for rewriting the model in R or Python.

It is one Go binary speaking MCP over stdio. `.xlsx`/`.xlsm`/`.pptx` are read
directly from the file, on any OS, with no Office installed. On Windows with
Office, it also drives Excel and PowerPoint for `.xlsb`, live sessions,
recalculation and pixel-exact pictures.

## Contents

- [Install](#install)
- [How to think about it](#how-to-think-about-it)
- [The tools](#the-tools)
- [Workflows](#workflows)
- [Behaviour worth knowing](#behaviour-worth-knowing)
- [Configuration](#configuration)
- [Architecture](#architecture)
- [Development](#development)

## Install

Build it (Go 1.26 or later):

```powershell
git clone <this repository> office-mcp
cd office-mcp
go run ./scripts/build          # writes bin\office-mcp.exe, keeps the last build as office-mcp.previous.exe
```

Register it with Claude Code:

```powershell
claude mcp add --scope user office -- "C:\path\to\office-mcp\bin\office-mcp.exe"
```

or with any MCP client:

```json
{ "mcpServers": { "office": { "command": "C:\\path\\to\\office-mcp\\bin\\office-mcp.exe" } } }
```

`office-mcp --version` prints the build. To roll back a bad build, rename
`office-mcp.previous.exe` over `office-mcp.exe`.

## How to think about it

There are fifteen tools, and they are **orthogonal**: each does one kind of
thing, and what it acts on is an argument. Every tool takes `path` — an
absolute path or the `https://` link of a SharePoint/OneDrive file synced to
this computer — and the Excel tools share `sheet` and `range`, where `range` is
an A1 range (`B2:F40`), a sheet-qualified range (`Data!B2:F40`) or a defined
name (`alpha`).

| Want to… | Excel | PowerPoint |
| --- | --- | --- |
| get oriented | `excel_inspect` | `pptx_inspect` |
| read content | `excel_read` | `pptx_read` |
| search | `excel_find` | `pptx_find` |
| see it | `excel_render` | `pptx_render` |
| move it elsewhere | `excel_export` | — |
| change cells | `excel_write`, `excel_replace`, `excel_format` | — |
| change structure | `excel_sheet`, `excel_name`, `excel_table` | — |

The natural order on an unfamiliar workbook is **inspect → render → read**:
`excel_inspect` tells you what each sheet is and suggests the next calls with
their arguments filled in; `excel_render` shows the shape of a sheet; then you
read exactly the cells you need.

## The tools

Arguments marked * are required. Full descriptions are in each tool's schema,
which your MCP client shows.

### Understand (read-only)

**`excel_inspect`** — `path*`, `sheet`, `include`, `format`
The workbook map: every sheet (hidden and very hidden included) with used
range, role (input/config, calc engine, raw data, results, chart), sheets
built from one template, which sheets read which, add-in functions,
defined-name health, charts, VBA and external links, and next steps. `include`
adds detail: `names`, `formulas` (formula families), `charts`, `vba`,
`features` (merges, comments, validation, conditional formats, panes), `links`,
`tables`.

**`excel_read`** — `path*`, `sheet`, `range`, `show`, `source`, `maxCells`, `format`
Cells as a TSV grid with row numbers. `show`: `all` (formula → value, default),
`values`, `formulas`, `display` (as formatted in Excel). Large ranges come a
page at a time; the reply names the next range.

**`excel_find`** — `path*`, `query`, `what`, `in`, `regex`, `sheet`, `maxResults`, `format`
`what=text` finds text or a regex in formulas and/or values;
`what=errors` finds error values and `#REF!`; `what=references` finds the
formulas that read a name, sheet or range — through ranges, names, tables and
3-D references, not by substring.

**`excel_render`** — `path*`, `sheet`, `range`, `style`, `engine`, `maxPixels`
A PNG. `style=layout` colours every cell by what it holds (input numbers,
dates, formulas, formulas reading another sheet or workbook, labels, errors)
and fits a whole 7,000-row sheet in one picture; `style=appearance` draws what
a person sees. The reply also lists cell counts and the column and row
pattern, so it is useful to a model that cannot see images.

**`excel_export`** — `path*`, `to*`, `sheet`, `range`, `out`, `overwrite`
`to=csv` writes saved values; `to=model` writes a JSON porting spec — inputs,
defined names, formula families in calculation order, outputs, add-in calls —
for rewriting the workbook elsewhere; `to=vba` writes each module as a
`.bas`/`.cls` file. Never changes the workbook; never replaces a file unless
`overwrite=true`.

**`pptx_inspect`**, **`pptx_read`**, **`pptx_find`**, **`pptx_render`** —
`path*`, `slides` (1-based numbers; omit for all), `format`. Inspect maps the
deck (properties, sections, each slide's title, layout, role, notes and
comments). Read returns text in reading order, tables, charts with their data,
notes and comments (`includePictures` attaches images). Find searches all of
those. Render exports slides as PowerPoint draws them.

### Change

| Tool | Ops | Notes |
| --- | --- | --- |
| `excel_write` | `set` (default), `append`, `insert_rows`, `delete_rows`, `insert_cols`, `delete_cols`, `clear` | `values` is rows of strings/numbers/booleans/null; `"=..."` is a formula. `append` adds below a sheet's data or a `table` (which grows). Reads back what it wrote. |
| `excel_replace` | find/replace | In formulas (default) and/or text values; `regex` with `$1` groups; **`preview` is on by default** — set `preview:false` to apply. |
| `excel_format` | — | One `style` for the range or a per-cell `styles` grid; `numberFormat`, `columnWidth`, `rowHeight`. Only the parts given change. |
| `excel_sheet` | `add`, `copy`, `rename`, `move`, `hide`, `unhide`, `delete` | `rename` updates formulas on every sheet, as Excel does. |
| `excel_name` | `set`, `delete` | `set` refuses to repoint an existing name unless `replace:true`. |
| `excel_table` | `create`, `delete`, `resize` | `delete` keeps the cells; `resize` moves the last row. |

Read-only tools carry the MCP read-only hint; every tool that writes (the six
above and `excel_export`) carries the destructive hint, since each can
overwrite or remove something, so clients can ask before running them.

## Workflows

**Understand a model you have been handed.**
`excel_inspect` → follow its next steps → `excel_render style=layout` on each
calc sheet → `excel_inspect include=[formulas] sheet=…` for its families →
`excel_read` the inputs.

**Port a workbook to R or Python.**
`excel_export to=model` gives inputs (with values), every formula family with
its representative formula, precedents and range, the calculation order, and
the outputs. Families are the unit of porting: a family filled down 7,000 rows
is one vectorised line, not 7,000. Check a port against `excel_read
source=saved`. Workbooks calling add-in functions (`_xll.…`) need those
functions reimplemented; `excel_inspect` lists them.

**Add this month's data.**
`excel_write op=append sheet=Data values=[[…]]` (or `table=Prices`), then
`excel_read` the new rows to confirm.

**Rename something used everywhere.**
`excel_replace find=… replace=…` (a preview) → check the before/after table →
run again with `preview:false`.

## Behaviour worth knowing

**Values are stored values.** A rate shown as `2.20%` reads as `0.022`; dates
read as ISO-8601; numbers in the shortest form that round-trips exactly. Use
`show=display` for the formatted text. This avoids the ambiguity of guessing
whether a number is a fraction or a percentage.

**Saved, live or recalculated.** `excel_read source=saved` (default) reads
the values last saved and needs no Excel, so formulas calling add-ins you do
not have still show their results. `live` reads the workbook open in your
Excel, unsaved edits included. `recalc` opens a private Excel and recalculates
first.

**Edits are safe by construction.**
- If the workbook is open in your Excel, edits happen there, so you see them
  and nothing races your session, and they are **not saved**: saving would
  also commit your own unsaved changes, so that stays your call. The reply
  says "changed in your open Excel session; not saved — save in Excel to keep
  it". If such an edit fails part-way, the error says what was already done
  in your session. The server only edits a workbook open in Excel when it is
  sure it is the same file: by its local path, or by a SharePoint/OneDrive
  address that a sync mapping resolves to it. Otherwise the file on disk is
  edited.
- Without Excel the file is saved atomically (written beside it, then
  renamed), so a failure never leaves half a file. A save that wrote formulas
  asks Excel to recalculate on opening; until then they show no value.
- Edits to one file run one at a time; concurrent writes lose nothing.
- A failed edit saves nothing.
- Formulas stay right: filled-down (shared) formulas survive overwriting their
  first cell and inserting or deleting rows and columns across them; array
  formulas are changed whole or not at all; renaming a sheet updates formulas,
  names, charts, validation, conditional formats and hyperlinks.

**Fast on repeat.** A workbook is parsed once and cached until the file
changes (by size and time), so later calls on the same file take
milliseconds. Paging through a long sheet costs one parse in total.

**Windows and Office.** Everything for `.xlsx`/`.xlsm`/`.pptx` works without
Office on Windows, macOS and Linux. These need Windows with Office: `.xlsb`
and `.xls`, `source=live` and `source=recalc`, `excel_render engine=excel`,
`pptx_render`, and `.ppt`. Hidden Excel and PowerPoint instances the server
starts are closed when it exits; PowerPoint is also released after 30 s idle.

## Configuration

| Variable | Default | Meaning |
| --- | --- | --- |
| `OFFICE_MCP_MAX_OPEN` | 4 | Documents kept open between calls |
| `OFFICE_MCP_PAGE_CELLS` | 4000 | Cells per `excel_read` page when `maxCells` is not given |
| `OFFICE_MCP_POWERPOINT_IDLE` | 30 | Seconds before an idle hidden PowerPoint is released |
| `SHAREPOINT_SYNC_MAPPINGS` | — | Extra `url|localPath` pairs, `;`-separated, for SharePoint links the OneDrive registry does not cover |

## Architecture

```dot
digraph office_mcp {
  rankdir=LR;
  node [shape=box, fontname="Helvetica", fontsize=11];
  edge [fontname="Helvetica", fontsize=9];

  client [label="MCP client", shape=ellipse];
  server [label="server\nregistration, timing,\npanic recovery"];
  tools [label="tools/*\none file per tool"];
  tool [label="tool\nargs → schema,\nstrict decoding, results"];
  store [label="store\nopen · cache · lock ·\nsave · invalidate"];
  analysis [label="analysis\nfamilies, dependency\ngraph, roles"];
  render [label="render\nlayout & appearance"];
  xlsx [label="excel/xlsx\npure Go"];
  ooxml [label="ooxml\nstreaming reader"];
  excelcom [label="excel/excelcom\nExcel (Windows)"];
  pptx [label="pptx\npure Go"];
  pptcom [label="pptx/pptcom\nPowerPoint (Windows)"];
  sta [label="sta\nCOM thread"];

  client -> server [label="stdio"];
  server -> tools -> tool;
  tools -> store; tools -> analysis; tools -> render;
  store -> xlsx -> ooxml;
  store -> excelcom -> sta;
  store -> pptx;
  store -> pptcom -> sta;
}
```

- **`store` is the only way to a file.** Tools pass it a callback; it owns
  opening, caching, locking, saving and invalidation, so no tool can leak a
  workbook or leave a stale copy.
- **Backends implement capabilities, not one fat interface.** The read core
  is small; editing, features, pictures and VBA are separate interfaces a
  backend implements only when it can. An unsupported operation is an error,
  never an empty result that looks like "none".
- **The pure-Go reader streams each sheet once** into a flat, row-major cell
  grid, expanding shared formulas itself (including sheet-qualified
  references, which the excelize library leaves unshifted). It was checked
  against excelize on all 1,535,907 cells of a real 25 MB model.
- **One argument struct per tool** is the single source of its schema; the
  server refuses to start if a declared argument would be missing from it.

Design rationale: [`docs/design/v2.md`](docs/design/v2.md). Conventions for
contributors (human or AI): [`CLAUDE.md`](CLAUDE.md).

## Development

```powershell
go test ./...                       # unit, end-to-end and (when installed) Excel/PowerPoint tests
go vet ./...
$env:GOOS="linux"; go build ./cmd/office-mcp; Remove-Item Env:GOOS
```

Tests that drive Excel or PowerPoint skip when they are not installed. Tests
against a real workbook run when `OFFICE_MCP_REAL_XLSM` names one.

## Licence

MIT. Originally forked from
[excel-mcp-server](https://github.com/negokaz/excel-mcp-server) by Kazuki
Negoro; rewritten since.