office-gateway
README.md
# Build-Office-Gateway
One MCP door for Word, Excel, PowerPoint — and a PDF parser switchboard.
`office-gateway` is a Python MCP server built on one idea: an AI agent should
never open an Office file itself. It asks the door; the door picks the hand.
## The hands behind the door
| Job | Hand |
|---|---|
| Light reads and edits on Word / Excel / PPT | **officecli** (external binary) |
| Complex Excel edits | the **zero-loss XML engine** (`engines/xlsx/`): unzip the xlsx, patch the exact cell XML, zip it back — no library round-trip that would drop styles, charts or pivots |
| Excel risk pre-check | formula-impact analysis before any write; writes that would clobber complex structures are intercepted and the agent is told to run `analyze_formula_impact` first |
| Dynamic formula recalculation | LibreOffice headless (`engines/xlsx/libreoffice_recalc.py`), then `formula_check.py` for runtime errors (#DIV/0!, #N/A, …) |
| PPTX generation | an external **html2pptx** Node.js engine (`engines/pptx/` — manifest included, engine file not; see that README) |
| DOCX generation / templating | a **C# OpenXML engine** (`engines/docx/`), driven via `dotnet run` |
| Markdown ↔ Word conversion | Pandoc |
| PDF parsing | three strategies: **MinerU** (academic deep: two-column papers, formulas → LaTeX), **MarkItDown** (OCR / visual pages), **PyMuPDF** (fast plain text) |
## Safety gates
- Every path must resolve inside `OFFICE_GATEWAY_WORKSPACE_ROOT`; segments like
`.git`, `.venv`, `node_modules`, `Trash` are refused outright.
- Excel writes run a pre-check first; if the workbook cannot be safely analysed,
the write is blocked — fail closed.
## Install
```bash
pip install .
# then point your MCP client at:
python server.py
```
External tools used when the corresponding action is requested: `officecli`,
`pandoc`, `magic-pdf` (MinerU), LibreOffice, the .NET SDK, Node.js.
## Configuration (environment variables)
| Variable | Default | Purpose |
|---|---|---|
| `OFFICE_GATEWAY_WORKSPACE_ROOT` | `~` | the only directory tree the gateway will touch |
| `OFFICECLI_PATH` | `officecli` | path to the officecli binary |
| `LO_MCP_PROFILE` | `~/.lo_mcp_profile` | shared LibreOffice profile (lets headless runs hand off to an always-on listener) |
## Notes
- Every account, key and password in the published sources is a mock. Real
credentials never leave the machine.
- The engines are pluggable on purpose: the door and the safety rules are the
contribution here, and each hand can be swapped without touching the router.
## Licence
MIT
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo issues