tb-word-mgagent

v0.3.1
@unboundai/tb-word-mgagent Checked 1 day ago Published 1 month ago

MCP server that hands a document outline to the Traffic Builders Word Managed Agent, then retrieves the finished .docx

A Model Context Protocol (MCP) server that hands a document outline to Anthropic's hosted Managed Agent for building Traffic Builders-branded Word documents, then retrieves the finished file once it's done. This is a sibling of tb-ppt-mgagent (the parent folder) — same Managed Agents wiring, same brand-asset-attachment pattern via the Files API — pointed at a separate agent/environment configured to write .docx instead of .pptx, and at a Word-specific design brief (TrafficBuilders-Word-Handoff.md) instead of the slide-deck one.

Summary extracted from the README.

Traffic Builders Word MCP Server

A Model Context Protocol (MCP) server that hands a document outline to Anthropic's hosted Managed Agent for building Traffic Builders-branded Word documents, then retrieves the finished file once it's done.

This is a sibling of tb-ppt-mgagent (the parent folder) — same Managed Agents wiring, same brand-asset-attachment pattern via the Files API — pointed at a separate agent/environment configured to write .docx instead of .pptx, and at a Word-specific design brief (TrafficBuilders-Word-Handoff.md) instead of the slide-deck one. See the parent README for the full rationale behind the resources-attachment approach and the Managed Agents SDK quirks (e.g. files.download() returning a plain Response, not a writeToFile()-capable object) — it isn't repeated here.

Available tools

  • generate_tb_word_document(outline, template?, docType?, clientName?, contactPerson?, author?, date?, version?, cover?, numberedHeadings?, tableOfContents?, filename?, attachments?) — creates a session against the configured agent + environment, attaches the brand asset resources (brief, logos, Outfit + Figtree fonts), uploads any chat attachments and mounts them too, sends the outline as the first message, returns { success, sessionId, message, attachmentsAttached, imageWarnings? }. Does not wait for the document to finish. template is one of standaard (default), formeel, contract, bold (see the brief; contract is currently built like formeel, legal structure still to be defined). clientName is the Opdrachtgever; contactPerson, author, date (dd-mm-jjjj, default today) and version (default 0.1) fill the meta table/bar of formeel, contract and bold. The footer text © Traffic Builders B.V. 2001–{creation year} · P.J. Oudweg 4, 1314 CH Almere is fixed; the server computes the creation year and passes it to the agent. cover, numberedHeadings and tableOfContents (auto | yes | no, default auto) override the brief's default logic: nothing unless the document is 5+ pages, a whitepaper, offerte or formal document (strategie, mediaplan, plan van aanpak, beleidsdocument); TOC when numbered or 5+ pages. attachments is an optional array (max 10) of { path? | url? | data? | fileId?, filename?, mimeType?, placement? } — any file type (images embedded as numbered figures, PDFs/spreadsheets/documents as source material). images still works as a deprecated alias. See Chat attachments.

  • get_tb_word_document_result(sessionId) — checks on a generation started above, following the same idle/end_turn/file-list/download flow as the PowerPoint server's get_tb_powerpoint_result, but filtering for a .docx filename instead of .pptx.

Chat attachments

Same behaviour as the PowerPoint sibling. An MCP tool call cannot see chat attachments by itself, so the calling model passes a reference:

  • path (preferred in Claude Desktop / Claude Code): the attachment is stored on disk and the model knows its absolute path. The server reads the file itself, so no bytes travel through the model.
  • url: a directly fetchable URL (server-side fetch).
  • data: base64 bytes, as a last resort (costs tokens).
  • fileId: a file already in the Files API, mounted without re-uploading.

Each file is uploaded to the Anthropic Files API and mounted at /mnt/session/uploads/user-attachments/<n>-<name>; the first message tells the agent to embed images as numbered figures with a caption at the given placement and to use other files as source material. A source that fails (bad path, HTTP error) is skipped and reported in imageWarnings instead of failing the whole call.

Optional hardening: set TB_DOC_ATTACHMENT_ROOTS to one or more folders (separated by ; on Windows, : elsewhere); path attachments outside them are refused. Unset means any readable local file is allowed.

Setup

  1. Install dependencies (from this word/ folder):

    npm install
    
  2. Build the project:

    npm run build
    
  3. Upload the brand assets (one time, or again whenever an asset changes):

    .\uploadAssets.ps1 -ApiKey "sk-ant-..."
    

    Uploads TrafficBuilders-Word-Handoff.md, all five logos/*.png, and fonts/Outfit-VariableFont_wght.ttf to the Files API, and prints a file_id per asset along with the matching TB_DOC_* env var name.

  4. Configure environment variables:

    • ANTHROPIC_API_KEY — Anthropic API key with Managed Agents access.
    • ANTHROPIC_AGENT_ID — the Word-document agent's id. This must be a different Managed Agent than the PowerPoint server's (or at least one configured/prompted to produce .docx output) — the env var name is the same as the sibling server's on purpose, since each MCP server process gets its own isolated env block in the client config (step 5), so there's no actual collision.
    • ANTHROPIC_ENVIRONMENT_ID — e.g. env_01VHzZmqBababsghFjQoAGFx.
    • ANTHROPIC_API_BASE — optional, overrides the SDK's default API base URL.
    • TB_DOC_OUTPUT_DIR — required for get_tb_word_document_result. Local folder that's synced to GCS by something outside this server; finished .docx files are written here.
    • TB_DOC_PUBLIC_URL_BASE — required for get_tb_word_document_result. Base URL the synced folder is served from, used to build the returned download link.
    • TB_DOC_LOGO_ICON_WHITE_LARGE_FILE_ID, TB_DOC_FONT_BODY_FILE_ID — the large white brand mark (bold cover/back) and the Figtree body font; from uploadAssets.ps1 like the other asset ids.
    • TB_DOC_ATTACHMENT_ROOTS — optional. Folders that path attachments must live in.
    • TB_DOC_LOG_FILE — optional. Path to the task log file. Defaults to logs/tasks.log next to this package.
    • TB_DOC_DESIGN_BRIEF_FILE_ID, TB_DOC_LOGO_HORIZONTAL_FILE_ID, TB_DOC_LOGO_HORIZONTAL_WHITE_FILE_ID, TB_DOC_LOGO_ICON_FILE_ID, TB_DOC_LOGO_ICON_WHITE_FILE_ID, TB_DOC_LOGO_ICON_TAGLINE_FILE_ID, TB_DOC_FONT_FILE_ID — all optional but strongly recommended, from step 3. Prefixed TB_DOC_ (rather than reusing the PowerPoint server's TB_* names) so both servers' file ids can live in the same secrets store without colliding.
  5. Register with your MCP client (Claude Desktop / TypingMind's local MCP connector), as its own separate server entry alongside tb-ppt-mgagent:

    "tb-word-mgagent": {
      "command": "node",
      "args": [
        "/path/to/tb-ppt-mgAgent/word/build/index.js"
      ],
      "env": {
        "ANTHROPIC_API_KEY": "sk-ant-...",
        "ANTHROPIC_AGENT_ID": "agent_...",
        "ANTHROPIC_ENVIRONMENT_ID": "env_...",
        "TB_DOC_OUTPUT_DIR": "/path/to/gcs-synced-folder",
        "TB_DOC_PUBLIC_URL_BASE": "https://storage.googleapis.com/your-bucket/your-prefix",
        "TB_DOC_DESIGN_BRIEF_FILE_ID": "file_...",
        "TB_DOC_LOGO_HORIZONTAL_FILE_ID": "file_...",
        "TB_DOC_LOGO_HORIZONTAL_WHITE_FILE_ID": "file_...",
        "TB_DOC_LOGO_ICON_FILE_ID": "file_...",
        "TB_DOC_LOGO_ICON_WHITE_FILE_ID": "file_...",
        "TB_DOC_LOGO_ICON_TAGLINE_FILE_ID": "file_...",
        "TB_DOC_FONT_FILE_ID": "file_..."
      }
    }
    

    This package isn't published to npm yet — register it from a local checkout as shown above (npm run build first). If you do want to publish it separately, give it a distinct npm name (already set to @unboundai/tb-word-mgagent in package.json) and follow the same npm version / npm publish flow as the parent package.

Task logging

Same JSON-lines format as the parent server, written to TB_DOC_LOG_FILE (default logs/tasks.log in this folder) and mirrored to stderr, with docxCandidates in place of pptxCandidates at the files_listed step.

Design brief reference

TrafficBuilders-Word-Handoff.md, logos/, and fonts/ in this folder are this server's source material. Unlike the PowerPoint brief, the "Traffic Builders Design System" Claude Design project doesn't (yet) contain real Word/report templates to sync against — the brief's page-setup and Word-Styles sections are this project's own translation of the same brand tokens into standard Word conventions, and it says so explicitly at the top. See its closing section for the recommended next step (attaching a real approved .docx as a reference once one exists) and for what to do if the design-system project later adds real document templates.

Development

# Watch mode
npm run dev