mcp-word-bridge 3.5.3 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,48 +1,45 @@
1
1
  # MCP Word Bridge
2
2
 
3
- [![Tests](https://github.com/likelion/mcp-word-bridge/actions/workflows/tests.yml/badge.svg)](https://github.com/likelion/mcp-word-bridge/actions/workflows/tests.yml)
4
- [![codecov](https://codecov.io/gh/likelion/mcp-word-bridge/branch/main/graph/badge.svg)](https://codecov.io/gh/likelion/mcp-word-bridge)
5
-
6
3
  MCP server for live Word document editing via Office Add-in. Enables programmatic editing of Word documents through the Word JavaScript API, with changes appearing as user edits in co-authoring sessions.
7
4
 
8
- ## Architecture
9
-
10
- ```
11
- MCP Client←stdio→index.js←WebSocket→Taskpane (Office Add-in)←→Word JS API←→Word Document
12
- ```
5
+ ## Quick Start
13
6
 
14
- Single process. The MCP client spawns `index.js`, which starts both the HTTPS bridge server (for the add-in) and the MCP server (on stdio). Everything starts and stops together.
7
+ ### 1. Add to your MCP client
15
8
 
16
- ## Setup
9
+ ```json
10
+ {
11
+ "mcpServers": {
12
+ "word-bridge": {
13
+ "command": "npx",
14
+ "args": ["-y", "mcp-word-bridge"]
15
+ }
16
+ }
17
+ }
18
+ ```
17
19
 
18
- ### 1. Install and sideload the add-in
20
+ ### 2. Install the Word add-in
19
21
 
20
22
  ```bash
21
23
  npx mcp-word-bridge-install
22
24
  ```
23
25
 
24
- This copies the manifest into Word's sideload directory. On macOS it's automatic; on Windows it attempts the standard location and prints manual steps if needed.
25
-
26
26
  Restart Word → Home → Add-ins → **MCP Word Bridge**
27
27
 
28
- ### 2. Add MCP config
28
+ ### 3. Trust the TLS certificate (first time only)
29
29
 
30
- Add to your MCP client configuration:
30
+ On first run the server auto-generates a self-signed localhost certificate and prints the trust command. Run it once:
31
31
 
32
- ```json
33
- {
34
- "mcpServers": {
35
- "word-bridge": {
36
- "command": "npx",
37
- "args": ["-y", "mcp-word-bridge"]
38
- }
39
- }
40
- }
32
+ ```bash
33
+ # macOS
34
+ security add-trusted-cert -r trustRoot -k ~/Library/Keychains/login.keychain-db "$(npm root -g)/mcp-word-bridge/certs/cert.pem"
35
+
36
+ # Windows
37
+ certutil -user -addstore Root "%APPDATA%\npm\node_modules\mcp-word-bridge\certs\cert.pem"
41
38
  ```
42
39
 
43
- ### 3. Open Word and activate the add-in
40
+ ### 4. Open Word and activate
44
41
 
45
- Open Word → Home → Add-ins → MCP Word Bridge
42
+ Open Word → Home → Add-ins → MCP Word Bridge. The taskpane shows "Word: connected ✓" and "WebSocket: connected ✓".
46
43
 
47
44
  That's it. The MCP server starts automatically when your MCP client loads the config, and stops when it unloads.
48
45
 
@@ -50,36 +47,16 @@ That's it. The MCP server starts automatically when your MCP client loads the co
50
47
 
51
48
  | Variable | Default | Description |
52
49
  |----------|---------|-------------|
53
- | `MCP_WORD_BRIDGE_PORT` | `3000` | HTTPS port for the bridge server. Must match the manifest `SourceLocation`. |
50
+ | `MCP_WORD_BRIDGE_PORT` | `3000` | HTTPS port for the bridge server |
54
51
 
55
- ## File Layout
52
+ ## How It Works
56
53
 
57
54
  ```
58
- mcp-word-bridge/
59
- ├── index.js # Entry point: HTTPS server + MCP handlers + WebSocket relay
60
- ├── lib/
61
- │ ├── tools.js # Tool definitions and action mapping
62
- │ ├── equations.js # LaTeX→OMML pipeline (fixDelimiters, fixNaryOperands, latexToOmml)
63
- │ └── usage-guide.js # MCP resource content (usage patterns for LLMs)
64
- ├── taskpane-app.js # Client-side Word JS API logic (runs in add-in)
65
- ├── install-manifest.js # Manifest sideloader (npx mcp-word-bridge-install)
66
- ├── taskpane.html # Served to Word add-in
67
- ├── certs/
68
- │ ├── cert.pem # Self-signed TLS cert
69
- │ ├── key.pem # TLS private key
70
- │ └── cert.conf # OpenSSL config for cert regeneration
71
- ├── manifest.xml # Office add-in manifest
72
- ├── test/
73
- │ ├── mcp-protocol.test.js # Tool schema & mapping tests (CI)
74
- │ ├── equations.test.js # LaTeX→OMML pipeline tests (CI)
75
- │ ├── validation.test.js # Input validation tests (CI)
76
- │ └── live/ # Integration tests against real Word (manual)
77
- │ ├── run-all.test.js
78
- │ └── bridge-client.js
79
- ├── package.json
80
- └── README.md
55
+ MCP Client ←stdio→ Server ←WebSocket→ Taskpane (Office Add-in) ←→ Word JS API ←→ Document
81
56
  ```
82
57
 
58
+ Single process. The MCP client spawns the server, which starts both the HTTPS bridge (for the add-in) and the MCP protocol handler (on stdio). Everything starts and stops together.
59
+
83
60
  ## Tools (92)
84
61
 
85
62
  ### Document
@@ -89,7 +66,7 @@ mcp-word-bridge/
89
66
  | `word_get_document_properties` | Get metadata (title, author, path, timestamps) |
90
67
  | `word_set_document_properties` | Set metadata fields |
91
68
  | `word_save` | Save document to disk |
92
- | `word_clear` | Clear all document body content. Leaves one empty Normal paragraph. |
69
+ | `word_clear` | Clear all document body content |
93
70
  | `word_create_document` | Create and open a new blank document in a new Word window |
94
71
  | `word_get_word_count` | Get word, character, and paragraph counts |
95
72
  | `word_get_styles` | List available styles |
@@ -132,7 +109,7 @@ mcp-word-bridge/
132
109
  | Tool | Description |
133
110
  |------|-------------|
134
111
  | `word_insert_table` | Insert a table with data and optional style |
135
- | `word_list_tables` | List table metadata (count, dimensions, style) — no cell values |
112
+ | `word_list_tables` | List table metadata (count, dimensions, style) |
136
113
  | `word_get_table_data` | Get cell values from a specific table |
137
114
  | `word_set_table_cell` | Set text in a cell |
138
115
  | `word_add_table_row` | Add a row with optional values |
@@ -223,7 +200,7 @@ mcp-word-bridge/
223
200
  | `word_get_sections` | List all sections with page setup |
224
201
  | `word_insert_page_break` | Insert a page break after a paragraph |
225
202
  | `word_insert_section_break` | Insert a section break after a paragraph |
226
- | `word_get_page_info` | Get page count and per-page paragraphs with document indices (Desktop only) |
203
+ | `word_get_page_info` | Get page count and per-page paragraph ranges (Desktop only) |
227
204
 
228
205
  ### Custom Properties
229
206
  | Tool | Description |
@@ -243,118 +220,73 @@ mcp-word-bridge/
243
220
  ### Equations
244
221
  | Tool | Description |
245
222
  |------|-------------|
246
- | `word_insert_equation` | Insert a LaTeX equation as a native editable Word equation. Display (block) or inline mode with optional anchor text positioning. |
223
+ | `word_insert_equation` | Insert a LaTeX equation as a native editable Word equation |
247
224
 
248
225
  ### Batch
249
226
  | Tool | Description |
250
227
  |------|-------------|
251
- | `word_batch` | Execute up to 50 operations in a single call. Native ops are bundled into one message to Word for maximum speed. |
252
-
253
- ## How it works
254
-
255
- 1. The MCP client spawns `index.js` via stdio
256
- 2. `index.js` starts an HTTPS server on port 3000 (serves taskpane + WebSocket relay)
257
- 3. The Word add-in taskpane connects via WebSocket
258
- 4. MCP tool calls are forwarded to the taskpane, which executes them via the Word JS API
259
- 5. Changes go through Word's editing pipeline — cursor follows edits like a human typing
260
- 6. When the MCP client terminates the process, the bridge server stops automatically
261
-
262
- ## Resources
263
-
264
- The server exposes an MCP resource at `word-bridge://usage-guide` containing patterns, workflows, and pitfalls for LLMs operating on Word documents. MCP clients that support resources can read this for context on how to use the tools effectively.
228
+ | `word_batch` | Execute up to 50 operations in a single call |
265
229
 
266
230
  ## Equations
267
231
 
268
- `word_insert_equation` converts LaTeX math to native Word equations via:
232
+ `word_insert_equation` converts LaTeX math to native Word equations:
269
233
 
270
234
  ```
271
235
  LaTeX → temml → MathML → mathml2omml → OMML → OOXML → Word
272
236
  ```
273
237
 
274
- - **Display mode** (`displayMode: true`, default): centered block equation on its own line
275
- - **Inline mode** (`displayMode: false`): inserted at the current cursor position within a paragraph
276
- - With `anchorText`: searches for the text and inserts the equation after the match (recommended — no manual cursor positioning needed)
277
- - Without `anchorText`: inserts at wherever the cursor currently is
278
- - Supports: fractions, roots, integrals, sums, products, matrices, Greek letters, piecewise functions, aligned systems, and all standard LaTeX math
238
+ - **Display mode** (default): centered block equation
239
+ - **Inline mode** (`displayMode: false`): within a paragraph, optionally positioned via `anchorText`
240
+ - Supports: fractions, roots, integrals, sums, matrices, Greek letters, AMS math
279
241
  - Equations are fully editable in Word's built-in equation editor
280
- - Invalid LaTeX returns a descriptive error message
242
+
243
+ ## Resources
244
+
245
+ The server exposes an MCP resource at `word-bridge://usage-guide` containing patterns and best practices for LLMs operating on Word documents.
281
246
 
282
247
  ## TLS Certificate
283
248
 
284
- A self-signed localhost certificate is **auto-generated on first run** if `certs/cert.pem` and `certs/key.pem` don't exist. The server prints the exact trust command with the resolved path:
249
+ Auto-generated on first run. The server prints the trust command:
285
250
 
286
251
  ```
287
252
  [mcp-word-bridge] ✓ Certificate generated.
288
- [mcp-word-bridge]
289
- [mcp-word-bridge] To trust the certificate (required once for Word to connect):
290
- [mcp-word-bridge] security add-trusted-cert -r trustRoot -k ~/Library/Keychains/login.keychain-db "/path/to/certs/cert.pem"
253
+ [mcp-word-bridge] Trust it: security add-trusted-cert -r trustRoot -k ~/Library/Keychains/login.keychain-db "/path/to/certs/cert.pem"
291
254
  ```
292
255
 
293
- Run the printed command once. No `sudo` required it adds to your user login keychain.
256
+ Run it once. To regenerate: delete `certs/cert.pem` and `certs/key.pem`, then restart.
257
+
258
+ ## Development
294
259
 
295
- **To regenerate:**
296
260
  ```bash
297
- rm certs/cert.pem certs/key.pem
298
- # restart the MCP server — it will regenerate and print the trust command again
261
+ git clone https://github.com/likelion/mcp-word-bridge.git
262
+ cd mcp-word-bridge
263
+ npm install
264
+ npm run build # build server + taskpane
265
+ npm run dev # watch mode
266
+ npm run typecheck # TypeScript type checking
267
+ npm test # unit tests (67 tests, <500ms)
268
+ npm run test:live # integration tests (requires Word)
299
269
  ```
300
270
 
301
- ## Known Limitations & Word API Behavior
302
-
303
- ### Search defaults
304
-
305
- All search-based operations (search, search_and_replace, format_text, insert_footnote, add_comment, etc.) are **case-insensitive by default**. Pass `matchCase: true` for exact case matching.
306
-
307
- ### TOC paragraphs
308
-
309
- `get_paragraphs` includes a `isTocEntry` boolean field to distinguish Table of Contents entries from body content. TOC entries have styles starting with "TOC" (e.g., "TOC 1", "TOC 2").
310
-
311
- ### Alignment values
312
-
313
- The Word JS API uses specific enum strings for paragraph alignment. The bridge accepts common aliases and normalizes them:
314
-
315
- | You can pass | API receives |
316
- |---|---|
317
- | `Left` | `Left` |
318
- | `Center` or `Centered` | `Centered` |
319
- | `Right` | `Right` |
320
- | `Justify` or `Justified` | `Justified` |
321
-
322
- ### Content controls and search
323
-
324
- In heavily-mutated documents (many rapid operations in a single session), text adjacent to content controls may occasionally become invisible to `search`. This is a transient Word API state issue. If search fails to find text you know exists, saving and reopening the document typically resolves it.
325
-
326
- ### CheckBox content controls
327
-
328
- CheckBox content controls are atomic widgets — they REPLACE the anchor text with a checkbox glyph (☐), unlike RichText and PlainText which wrap the text. `set_content_control_text` cannot modify CheckBox controls (they only support checked/unchecked state).
271
+ ### Project Structure
329
272
 
330
- ### Table cell paragraphs
331
-
332
- Table cells always contain at least one paragraph. `delete_paragraph` on a table cell paragraph clears the cell text but cannot remove the structural cell itself. `insert_section_break` and `insert_page_break` cannot target paragraphs inside table cells (Word constraint).
333
-
334
- ### Tracked changes coalescing
335
-
336
- Adjacent insertions by the same author at the same timestamp are merged into a single tracked change by Word. Two separate `insert_paragraph` calls may appear as one revision in `get_tracked_changes`.
337
-
338
- ### Tracked changes and replacements
339
-
340
- When `search_and_replace` creates a tracked change with tracking enabled, the Word API may only expose the "Added" half of the replacement. The "Deleted" half can appear later (often with empty text) after the "Added" change is accepted. This is a Word API limitation. Use `accept_all_tracked_changes` when you don't need granular control.
341
-
342
- ### TOC and duplicate text
343
-
344
- After inserting a Table of Contents, heading text appears twice in the document (once in the TOC, once in the body). Search-based operations will match TOC entries first. Use the `occurrence` parameter (0-indexed) to target the correct instance.
345
-
346
- ### Hyperlink indices
347
-
348
- `get_hyperlinks` returns indices from the underlying fields collection (which includes non-hyperlink fields). Indices may be non-contiguous — this is by design for cross-referencing with `get_fields`.
349
-
350
- ### Document path
351
-
352
- `path` in `get_document_properties` is only reliable for documents saved to a user-chosen location with a `.docx` extension. For unsaved documents or auto-saved container documents, it returns `null`. Save the document explicitly (File → Save As) if you need the file path.
353
-
354
- ### Line spacing units
355
-
356
- `lineSpacing` in `set_paragraph_spacing` and `get_paragraph_by_index` is in **points** (not a multiplier). For a 12pt font: 12 = single spacing, 18 = 1.5x, 24 = double spacing.
273
+ ```
274
+ src/
275
+ ├── server/ # MCP server (Node.js)
276
+ │ ├── tools/ # One file per tool category
277
+ │ ├── bridge.ts # WebSocket bridge to taskpane
278
+ │ ├── mcp.ts # MCP protocol handlers
279
+ │ └── validation.ts # Shared input validators
280
+ ├── taskpane/ # Runs inside Word's add-in webview
281
+ │ ├── commands/ # One file per command category
282
+ │ └── log.ts # Taskpane UI logger
283
+ ├── shared/ # Types shared between server and taskpane
284
+ │ ├── protocol.ts # WebSocket message types
285
+ │ └── constants.ts # Limits and timeouts
286
+ └── lib/
287
+ └── equations.ts # LaTeX→OMML conversion pipeline
288
+ ```
357
289
 
358
- ### Paragraph ordering with concurrent inserts
290
+ ## License
359
291
 
360
- When multiple paragraphs are inserted at `"End"` in rapid succession, Word may reorder them based on heading level or style hierarchy. For guaranteed ordering, insert sequentially and verify with `get_paragraphs`.
292
+ MIT