Skip to main content
Glama
README.md
# word-plumbing — draft template-faithful .docx from an agentic chat

The point of this project: **you never open Word's template GUI or copy files
around in OneDrive again.** A local MCP server exposes the docx pipeline as
tools, so any agent session (Vibe, VS Code Copilot, …) can draft a correctly
formatted assignment from one plain-language message:

> "Draft my assignment for DEMO-101, title 'Luentomuistiinpanojen
> palautus'. Content: ## Johdanto … and add this screenshot as a figure
> with caption and alt text. Date it today."

→ a finished `.docx` appears in `C:\ai\data\exports\`, with the template's
real styles, metadata controls filled, date stamped, figure captioned with
alt text.

## Architecture

```text
chat session (Vibe / VS Code Copilot / any MCP client)
        │  MCP over stdio (client spawns the server — nothing to "start")
        ▼
word_mcp.py  (FastMCP server, 5 tools)
        │  imports the engine
        ▼
fill_master.py::generate()  ──►  stamp_date.py (date picker + header)
        │
        ▼
C:\ai\data\models\master.docx  ──►  C:\ai\data\exports\<slug>.docx
     (never modified)                     (open in Word, submit)
```

HTTP transport is also available (`WORD_MCP_TRANSPORT=streamable-http`,
default `127.0.0.1:8002/mcp`) for Docker/remote clients — same pattern as
the archimate-mcp wrapper.

## MCP tools

| Tool | Does |
|---|---|
| `draft_assignment` | full pipeline from markdown-ish **content text** (images referenced by path; relative paths resolve against `WORD_EXPORTS`). **Style-linted by default**: refuses on error-severity violations |
| `draft_assignment_file` | same, from a **content file** (image paths resolve next to that file) |
| `lint_style` | check content against the human-writing style profile without generating |
| `stamp_date_file` | stamp the submission date into an existing .docx (picker + header); fails loudly if no picker |
| `list_styles` | list the style IDs a template defines |

Content syntax: `## ` heading · plain lines → BodyText (lines join) ·
`- ` bullet · `1. ` numbered · `![alt](img.png)` → caption **above** +
centered image + alt text · `<!-- -->` comments skipped.

## Setup (already done in this workspace)

1. `uv add python-docx fastmcp` in this project.
2. Vibe: `C:\ai\.vibe\config.toml` has a `[[mcp_servers]]` stdio entry
   (command = this venv's `python.exe`, args = `word_mcp.py`, env sets
   `WORD_MASTER` / `WORD_EXPORTS`). **Open a new session in `C:\ai`** —
   project config loads at session start; tools appear as
   `mcp_word_plumbing.*`. (If the folder isn't trusted and tools are
   missing, move the block to `~/.vibe\config.toml`.)
3. VS Code: open `C:\ai` as workspace; `C:\ai\.vscode\mcp.json` registers
   the same stdio server → tools in Copilot **agent mode**.
4. Verify anytime: `uv run test_word_mcp.py` (spawns the server, calls
   `draft_assignment` over MCP, checks the output docx — 9 assertions).

## CLI (same engine, no agent)

```powershell
uv run fill_master.py --master C:\ai\data\models\master.docx `
    --content content.md --title "My Assignment" --course DEMO-101
# name/doctype default from config.local.json; -o, --date, --skip-metadata
```

`--skip-metadata` renders into any plain .docx (content appended, no
controls required).

## How it works (the parts worth stealing)

- **Controls filled by structure**: date = the `w:sdt` with `w:date`,
  bibliography = the "References" block, title = alias `Otsikko`, the rest
  in document order. No hardcoded positions.
- **Split runs**: Word stores text as arbitrary run fragments ("T" +
  "ehtäväasiakirja") — filling sets the first `w:t`, blanks the rest.
- **Stale `w:dataBinding` stripped**: the template binds date/title controls
  to customXml store items with old values; Word re-syncs bound controls
  from the store on open and clobbers fresh values. Unbinding fixes it; the
  date picker still works for manual overrides.
- **Date stamped, not live** (Option B): `w:fullDate` + displayed `d.M.yyyy`
  in document *and* headers — a live DATE field would drift on every open.
- **BIBLIOGRAPHY field left untouched** — manage sources in Word's reference
  manager; F9 rebuilds the field (the "Example. 2026" text is cached output).
- Styles are referenced by **style ID** (`Heading2`, `BodyText`, `Caption`…),
  never by display name.

## De-sloppify layer (human writing style, EN + FI)

Drafted text is checked against `style_profile.json` (edit the rules there):

- **em dash (—) is an error** unless mandated/necessary (`allow_em_dash=True`
  for those cases); en dash (–) only in numeric ranges like 2020–2026
- AI-tell phrases banned **per language** (`banned_phrases.en` seeded from
  blader/humanizer patterns + berenslab/llm-excess-vocab (Kobak et al. 2025)
  + arXiv 2412.11385 focal words; `banned_phrases.fi` is our Finnish seed
  list). Both languages are always checked, so mixed EN/FI documents work
- structure warnings: >5 sentences per paragraph, >40 words per sentence
- `lint_style` tool checks without generating; `draft_assignment*` refuse on
  errors by default (`lint=False` to skip); CLI: `--lint`
- the `human-writing` skill (`skills/human-writing/`) holds the drafting
  rules + lint workflow; the vendored `skills/humanizer/` (blader/humanizer,
  MIT, see its ATTRIBUTION.md) is the full ~260-pattern rewrite pass to apply
  when the linter flags text

Tests: `uv run test_style.py` (unit + bilingual + MCP-level gating),
`uv run test_word_mcp.py` (end-to-end draft).

## Limitations / next steps

- Numbered lists share Word's numbering across blocks (no auto-restart).
- Metadata mode expects a template shaped like the Haaga-Helia master;
  adapt `classify()` for others.
- Public portfolio copy: this repo, published at
  <https://github.com/veenetul/word-plumbing> (paths generalized, personal
  data removed) — `C:\ai-public\word-plumbing` is the local staging copy;
  sync it after changes.

TDQS

A3.7/5.0

Scored across 5 tools

Disambiguation4/5

Each tool targets a distinct step: inspecting styles, linting content, drafting a document, and stamping a date into an existing file. The only overlap is draft_assignment vs draft_assignment_file, which are sibling variants (inline content vs file-sourced content) but explicitly clarify the distinction in their descriptions.

Naming Consistency5/5

All five tools use verb-first snake_case: stamp_date_file, list_styles, lint_style, draft_assignment, draft_assignment_file. The _file suffix is used consistently to denote path-based variants.

Tool Count5/5

Five tools is well-scoped for a focused Word document drafting/plumbing server. Every tool maps to a concrete pipeline stage with no filler.

Completeness4/5

The core lifecycle is covered: inspect template styles, lint content, render a .docx from inline or file content, and stamp a date. Minor gaps exist — no tool to read/extract content from an existing .docx or to update/replace content beyond date stamping — but agents can work around these.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues