How the ZeroExport DocGen MCP Server Works: From Org Schema to a Tested Template

A step-by-step look inside the ZeroExport DocGen MCP server: how it reads your Salesforce objects and fields, verifies every merge field, builds data sources and layout, validates and compiles the template in your org, and renders a test PDF.
The ZeroExport MCP server lets Claude or Codex build Salesforce document templates and migrate Conga, Nintex, S-Docs and Word templates. This post covers how it works. It follows one template from the file you hand over to a validated, compiled draft in your org, and a test PDF on a real record.
The design comes down to one rule: the AI proposes, and the org decides. Every field name, relationship and rule the assistant writes is checked against your org's real schema or against ZeroExport's own validator before anything is saved. When something cannot be established, the assistant asks you instead of guessing.
Step 0: Pick the org, and check it can take the template
Every migration targets a Salesforce org, and the server never picks one itself. It lists the orgs your Salesforce CLI (sf) is signed in to and asks which to use, because importing into the wrong org is hard to undo.
It then checks the chosen org before doing any work:
- The Salesforce CLI is installed. Every Salesforce call goes through
sf, which handles sign-in itself. The server never reads or stores an access token. - ZeroExport 1.13 or later is installed. A migration writes features an older package cannot print, so an older org is stopped.
- The environment. Scratch, sandbox, developer or production, judged from the instance URL. Anything that is not clearly disposable is treated as production, and the final import needs your explicit yes.
You also choose the folder for the working .zadt file. .zadt is ZeroExport's portable template format, the same file the builder exports and imports. The migration saves its progress there after each step, so you can read it, share it, or import it by hand.
Step 1: Read the template and verify every field against the org
The first phase reads the source template and checks every merge field against your org's metadata. It only reads: nothing is written to the org until the final import.
- Find the primary object. The server infers which object the template is about (Account, Opportunity, Quote) and reports how confident it is.
- Translate the merge fields. Real Conga templates mostly use aliases such as
{{ACCOUNT_NAME}}, notObject.Field. Each alias is rewritten in ZeroExport's form,{{Account.Name}}. - Verify each field. For each one the server looks up the object, then the field, then the full API path in the org you chose. Labels and API names are both matched, and custom fields and relationships come from the org's schema, not from a built-in list.
- Map system variables (today's date, the current user and so on) against ZeroExport's published system variables page.
Every merge field ends in one of three states, and none of them is a guess:
| State | Meaning | What happens next |
|---|---|---|
| Mapped | Exactly one org field matches | Used as is |
| Ambiguous | Several fields could match | The assistant shows you the candidates and asks |
| Unresolved | No field matches | The assistant asks; you name the field or leave it as text |
When you answer, the assistant sends your choice back and the server checks it against the org again. A field you name that does not exist is rejected, not trusted. Each row records where its mapping came from (the template, a metadata match or your answer), so you can audit the result later.
Conga query aggregates (OPPORTUNITY_EXPR0) are a special case. Their function, field and filter live in the Conga query, not in the Word file, so they cannot be read from the template. You choose the ZeroExport equivalent, such as {{Opportunities.count}} or {{Opportunities.sum(Amount)}}.
Step 2: Build the data sources
Next the server works out where each value will come from. It builds the data sources from the verified analysis, not from the document, using ZeroExport's own data source model:
- Primary: the record the document is generated for.
- Child query: a repeating region, such as the line items on a quote, mapped to a real child relationship in your org. If the object has no matching relationship, or several, you are asked.
- Nested child: a region inside a region, such as products under each opportunity, up to four levels below the primary object.
- Unrelated and Summary sources for extra filtered sets and grouped totals.
Parent lookups are not separate sources. A field such as Account.Name on an Opportunity is read as a related path on the primary record.
The server also keeps the queries lean. Each source asks only for the fields the template actually uses, and regions that read the same relationship share one query.
This step is a conversation. Filters, sort order, limits and names come from you only. A region called "OpenOpps" in the template suggests a filter but is not treated as one. Anything the server cannot establish comes back as a numbered question, and the plan stays blocked until you answer. Answers are remembered, so you are never asked twice.
Step 3: Generate the layout
With the fields and sources settled, the server reads the template file again, this time for its real layout, and builds the template structure:
- Sections and headings come from the document's heading styles. A top-level heading starts a section, and lower headings stay inside it, the way the builder shows them.
- Tables with a header row followed by body rows become ZeroExport tables. A row whose fields belong to a collection repeats by itself, with no start and end tags, and a final
TotalorSubtotalrow is marked as one. - Layout tables with no header row become grids, one column per cell.
- Merge fields are rewritten against the data source that serves their region. Date patterns carry over as formats. Currency formatting is left to ZeroExport, which formats currency itself.
- Headers, footers and page numbers are carried across, and a line that holds only "Page 1 of 3" becomes the template's page numbering.
The layout step decides structure only. Fonts, colours and spacing come later, so a structural mistake is never hidden by styling.
Nothing is dropped silently. Every element is counted as Supported, Transformed or Unsupported, and the coverage report lists each one. A field that could not be mapped stays in the document as visible literal text, never as a broken token or a blank. Embedded pictures become empty image placeholders that keep their size and alt text, for you to upload in the builder.
Step 4: Page setup and conditional logic
The fourth phase handles two things that apply to the whole document:
- Page setup. The page size, orientation and margins are read from the Word file and written in the form the builder's Page Setup tab saves, so they survive the next edit. A margin too small to print is flagged.
- Conditional visibility. Conga conditions such as
TableHideandIFbecome ZeroExport visibility rules. The report says how many converted and how many did not, so nothing is quietly lost.
The server also checks each rule's shape. This matters because a visibility rule that cannot be resolved would hide its section for every record.
Step 5: Styles from what the template actually looks like
The styles are not taken from the Word file's internals. You paste screenshots of the original output, and the assistant records what it can clearly see: heading colours, table header shading, column widths. Each observation is tied to a specific node in the layout from Step 3.
- Observations marked uncertain are reported, never applied.
- Only ZeroExport's existing style system is used. A style it cannot express is reported as unsupported, not approximated.
- Pages can arrive in batches, and progress is saved after each one.
The server never reads, uploads or stores the screenshots. Only the recorded observations go into the .zadt.
An optional last step applies a brand: primary and secondary colours, body and heading fonts, and sizes. You choose every value from the options ZeroExport can print, review them all in one table, and confirm before anything is written.
Step 6: Validate in the org, then import and compile
Validation happens twice, and the second time is in your org.
- Local checks run after every step. They cover the node grammar, merge field syntax, data source structure and page setup, so mistakes surface while the template is still being built.
- Org checks run ZeroExport's own pre-import validation inside your org, through the package's
ZeroExportMcpclass. They confirm that every field exists and that every visibility rule points at a real field. They also do a dry-run import, rolled back afterwards, so the save rules and the query planner (nesting depth, filters, sort order) report problems before anything is saved.
Every error is fixed before the import. The import itself happens only after you say yes:
- The template arrives as an inactive draft. Nothing changes for your users until someone activates it.
- On import ZeroExport compiles the template, the same as a save in the builder. Merge fields, repeating rows, visibility rules and aggregates are parsed once and checked again. Compilation is all-or-nothing, so a template with invalid fields or structure is rejected rather than half-saved.
- The uploaded file is deleted after the import, so no stray
.zadtis left in your Files.
Step 7: Test it on a real record
A validated template is not a finished template until it prints the right document. The server can render a PDF from the draft version for any record you name, and saves it to a local file. Nothing is attached to or changed on the record.
Compare that PDF with the old tool's output for the same record. Try at least a typical record, one with many line items, and one with empty related lists. Then open the draft in the Lightning builder, adjust what you want, and activate it like any template an admin built by hand.
What the MCP server can and cannot touch
The guarantees are enforced in the server's code, not just requested in its instructions. The MCP server architecture page lists its full capabilities and limitations.
- It cannot change org metadata. The only things it writes are ZeroExport template records (through the package's own import) and a temporary
.zadtupload that it deletes afterwards. It cannot run deploys, create objects or fields, or change permission sets. Salesforce CLI commands are allowlisted, and Apex that contains metadata APIs, callouts or direct DML is refused before it is sent. - It does not change how documents are generated. Once a template is saved, generation is the same deterministic Apex as before: the same record produces the same PDF, and no AI model is involved in rendering. The zero data egress architecture is unchanged.
- Product knowledge comes from the published docs. When the assistant is unsure how ZeroExport expresses something, it reads the live ZeroExport docs rather than guessing.
FAQ
What is a DocGen MCP server?
An MCP server for document generation (DocGen) gives AI assistants template-building tools over the Model Context Protocol. The ZeroExport DocGen MCP server reads your Salesforce schema, builds and migrates templates, and validates them in your org. The documents themselves are still rendered by deterministic Apex.
How does the MCP server know my field names are right?
It never assumes. Every field is looked up in the org you chose, and a field you supply in an answer is checked again. Before import, ZeroExport's own validator runs in the org and confirms that every field and visibility rule resolves.
Does the AI generate my documents?
No. The AI helps author the template. Once it is saved and compiled, documents are generated by ZeroExport's Apex engine inside Salesforce, with no AI model in the path.
Can it import straight into production?
Only with your explicit confirmation. Any org that is not clearly a scratch org, sandbox or developer org is treated as production, and the import refuses until you say yes. Even then the template arrives as an inactive draft.
What happens to parts of a template it cannot convert?
They are reported, not dropped or invented. The coverage report lists what was supported, transformed and unsupported. An unmapped field stays as visible text, and a condition that did not convert is listed by name.
Which plan includes it?
The MCP server is included in the Standard plan, a flat $10,000 per org per year with unlimited templates and users. It needs ZeroExport 1.13 or later. See the 1.13 upgrade notes for the permission it needs.
Related Reading
- DocGen MCP Server for Salesforce: Architecture
- Migrate Conga and Nintex Templates With Claude and the ZeroExport DocGen MCP Server
- How to Migrate Off a Salesforce Document Generation Tool Without Breaking It
- Migrating Off Conga Composer: A Phased Plan for Document Generation
- Validating Salesforce Template Field Mappings: Conga, Nintex, OmniStudio and ZeroExport
- Agentforce Document Generation: Generate Salesforce PDFs Instantly with ZeroExport
Ready to try ZeroExport?
Start generating documents directly in your Salesforce org. No integrations, no setup overhead, no complexity.