mcp-word-bridge 3.5.2 → 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,37 +47,17 @@ 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
 
83
- ## Tools (91)
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
+
60
+ ## Tools (92)
84
61
 
85
62
  ### Document
86
63
  | Tool | Description |
@@ -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 |
@@ -107,6 +84,7 @@ mcp-word-bridge/
107
84
  | `word_delete_paragraph` | Delete a paragraph by index |
108
85
  | `word_replace_paragraph_text` | Replace paragraph text by index (preserves style) |
109
86
  | `word_move_paragraph` | Move one or more consecutive paragraphs to another position |
87
+ | `word_copy_paragraph` | Copy one or more consecutive paragraphs to another position |
110
88
  | `word_set_paragraph_style` | Change style or alignment of a paragraph |
111
89
  | `word_set_paragraph_spacing` | Set line spacing, before/after, and indentation |
112
90
 
@@ -131,7 +109,7 @@ mcp-word-bridge/
131
109
  | Tool | Description |
132
110
  |------|-------------|
133
111
  | `word_insert_table` | Insert a table with data and optional style |
134
- | `word_list_tables` | List table metadata (count, dimensions, style) — no cell values |
112
+ | `word_list_tables` | List table metadata (count, dimensions, style) |
135
113
  | `word_get_table_data` | Get cell values from a specific table |
136
114
  | `word_set_table_cell` | Set text in a cell |
137
115
  | `word_add_table_row` | Add a row with optional values |
@@ -222,7 +200,7 @@ mcp-word-bridge/
222
200
  | `word_get_sections` | List all sections with page setup |
223
201
  | `word_insert_page_break` | Insert a page break after a paragraph |
224
202
  | `word_insert_section_break` | Insert a section break after a paragraph |
225
- | `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) |
226
204
 
227
205
  ### Custom Properties
228
206
  | Tool | Description |
@@ -242,118 +220,73 @@ mcp-word-bridge/
242
220
  ### Equations
243
221
  | Tool | Description |
244
222
  |------|-------------|
245
- | `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 |
246
224
 
247
225
  ### Batch
248
226
  | Tool | Description |
249
227
  |------|-------------|
250
- | `word_batch` | Execute up to 50 operations in a single call. Native ops are bundled into one message to Word for maximum speed. |
251
-
252
- ## How it works
253
-
254
- 1. The MCP client spawns `index.js` via stdio
255
- 2. `index.js` starts an HTTPS server on port 3000 (serves taskpane + WebSocket relay)
256
- 3. The Word add-in taskpane connects via WebSocket
257
- 4. MCP tool calls are forwarded to the taskpane, which executes them via the Word JS API
258
- 5. Changes go through Word's editing pipeline — cursor follows edits like a human typing
259
- 6. When the MCP client terminates the process, the bridge server stops automatically
260
-
261
- ## Resources
262
-
263
- 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 |
264
229
 
265
230
  ## Equations
266
231
 
267
- `word_insert_equation` converts LaTeX math to native Word equations via:
232
+ `word_insert_equation` converts LaTeX math to native Word equations:
268
233
 
269
234
  ```
270
235
  LaTeX → temml → MathML → mathml2omml → OMML → OOXML → Word
271
236
  ```
272
237
 
273
- - **Display mode** (`displayMode: true`, default): centered block equation on its own line
274
- - **Inline mode** (`displayMode: false`): inserted at the current cursor position within a paragraph
275
- - With `anchorText`: searches for the text and inserts the equation after the match (recommended — no manual cursor positioning needed)
276
- - Without `anchorText`: inserts at wherever the cursor currently is
277
- - 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
278
241
  - Equations are fully editable in Word's built-in equation editor
279
- - 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.
280
246
 
281
247
  ## TLS Certificate
282
248
 
283
- 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:
284
250
 
285
251
  ```
286
252
  [mcp-word-bridge] ✓ Certificate generated.
287
- [mcp-word-bridge]
288
- [mcp-word-bridge] To trust the certificate (required once for Word to connect):
289
- [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"
290
254
  ```
291
255
 
292
- 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
293
259
 
294
- **To regenerate:**
295
260
  ```bash
296
- rm certs/cert.pem certs/key.pem
297
- # 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)
298
269
  ```
299
270
 
300
- ## Known Limitations & Word API Behavior
301
-
302
- ### Search defaults
303
-
304
- 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.
305
-
306
- ### TOC paragraphs
307
-
308
- `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").
309
-
310
- ### Alignment values
311
-
312
- The Word JS API uses specific enum strings for paragraph alignment. The bridge accepts common aliases and normalizes them:
313
-
314
- | You can pass | API receives |
315
- |---|---|
316
- | `Left` | `Left` |
317
- | `Center` or `Centered` | `Centered` |
318
- | `Right` | `Right` |
319
- | `Justify` or `Justified` | `Justified` |
320
-
321
- ### Content controls and search
322
-
323
- 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.
324
-
325
- ### CheckBox content controls
326
-
327
- 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
328
272
 
329
- ### Table cell paragraphs
330
-
331
- 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).
332
-
333
- ### Tracked changes coalescing
334
-
335
- 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`.
336
-
337
- ### Tracked changes and replacements
338
-
339
- 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.
340
-
341
- ### TOC and duplicate text
342
-
343
- 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.
344
-
345
- ### Hyperlink indices
346
-
347
- `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`.
348
-
349
- ### Document path
350
-
351
- `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.
352
-
353
- ### Line spacing units
354
-
355
- `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
+ ```
356
289
 
357
- ### Paragraph ordering with concurrent inserts
290
+ ## License
358
291
 
359
- 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