BC Word Layout MCP (Part 3): Add totals and page numbers

The quote from part 2 has a date and repeating lines. It still needs a document total and page numbering.

These are ordinary report requirements, but the wording matters. “Add a total” does not tell the agent whether you mean a total per group or one amount for the whole document.

Updated 25 October 2026: These features first appeared in v1.1.0. The instructions below now use released v2.0.0, including its new table-cell arguments and formatting options.

Start with a working copy

Continue with C:\BCLayoutDemo\Quote.docx, using the v2.0.0 setup from part 1.

Keep a copy before changing it. Ask the agent to inspect the document, identify the line table, and find the total fields in the dataset. Do not assume that the first table is the line table; an address block can be a table too.

For the captured quote, the dataset provides the total caption and amount under /Header/Totals. Confirm whether you need an amount including VAT, excluding VAT, or another value.

Add the document total once

Use BC Word Layout MCP to add a grand-total row to Quote.docx.
Place it after the repeating lines, inside the same table.
Bind the dataset's total-including-VAT caption and amount.
Leave the first two grid columns empty, put the caption next,
and right-align the amount in the last column.
Make the row bold and add a thin rule above it.
The total must print once per document, not once per line.
Do not calculate it from the displayed lines.

The agent can use insert_table_row for the non-repeating row and set_cell_format for the rule.

The layout prints the amount supplied by the report. It does not calculate discounts, tax, or rounding. If the report does not supply the right total, fix the dataset rather than creating a second calculation in the layout.

For saved tool calls, v2.0.0 expresses the four-column row as a cells array like this:

{
  "cells": [
    {"span": 2},
    {"fields": ["/Header/Totals/TotalIncludingVATText"], "alignment": "right"},
    {"fields": ["/Header/Totals/TotalAmountIncludingVAT"], "alignment": "right"}
  ],
  "format": {"bold": true}
}

This is only the row-definition fragment, not a complete tool request. The agent supplies the actual layout path and table index. The empty cell spans two columns; the other two cells use one each.

A subtotal belongs to its group

For a grouped report, the requirement might be “print a subtotal after each salesperson’s entries”.

That needs insert_subtotal_row inside the parent repeater, not a static row at the end of the whole table. Tell the agent what the group is, which detail rows belong to it, and which dataset amount represents the subtotal.

The useful distinction is:

Requirement Intended result
Document total Once after all lines.
Group subtotal Once after each group’s details.
Line amount Once for every line.

You should be able to describe the expected count before asking the agent to change the layout.

Add page numbers that update

Add current page / total pages to the footer of Quote.docx.
Use real Word page numbers, not static text.
Include the report's translated Page caption if the dataset provides one.
Check whether the layout has separate first-page or even-page footers,
and make sure numbering appears on every intended page.
Keep the existing footer content.

The tool for the numbers is insert_page_number. A caption such as “Page” is separate, so the agent can bind it to a dataset label instead of hard-coding English.

Check the first page and a later page. Word layouts can use different footers for them. A number inserted into the default footer can be correct and still be invisible on a one-page printout.

Test the behaviour, not just the look

Ask for full validation and a preview, then print a representative quote in a BC sandbox.

  • On a one-page quote, is the total shown once?
  • On a multi-page quote, does it remain after the final line rather than repeat on every page?
  • Are the page numbers present on the first and subsequent pages?
  • Do the total and caption match the report’s data and language?

The total is a final table row, not a repeating page footer. If you want a different behaviour, say so explicitly.

If a Word save stops the lines repeating

Older Word compatibility settings can cause repeating sections to be lost when someone saves the layout in Word. The server’s validation checks for that risk and for repeaters that have already been downgraded.

If you see those findings, do not treat “Word opens it” as a successful test. Restore a known-good copy or ask the agent to rebuild the affected repeater, then validate and print again.

For a straightforward quote, the acceptance check is simple: correct line values, one final total, and page numbers that follow the printed pages. Keep that result in the brief rather than leaving the agent to infer it.