compose_document
Assemble multi-part documents from HTML or Markdown sections, add watermarks, and export as PDF, DOCX, or ODT.
Instructions
Compose a multi-part document from several sections.
Each part is a dict with: htmlContent, markdownContent, templateName, fields.
Args: parts: List of document parts. Each part can have htmlContent, markdownContent, templateName, fields. watermark: Optional diagonal watermark text overlay. output_format: Output format – PDF, DOCX, or ODT (default: PDF).
Returns: Base64-encoded document bytes.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| parts | Yes | ||
| watermark | No | ||
| output_format | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- mcp/src/docgen_mcp/server.py:125-159 (handler)The compose_document MCP tool handler. It takes a list of document parts, builds a multi-part document via the DocGen client, and returns a base64-encoded result.
@mcp.tool() def compose_document( parts: list[dict[str, Any]], watermark: str | None = None, output_format: str = "PDF", ) -> str: """Compose a multi-part document from several sections. Each part is a dict with: htmlContent, markdownContent, templateName, fields. Args: parts: List of document parts. Each part can have htmlContent, markdownContent, templateName, fields. watermark: Optional diagonal watermark text overlay. output_format: Output format – PDF, DOCX, or ODT (default: PDF). Returns: Base64-encoded document bytes. """ dg = _get_client() from docgen.models import DocumentPart, OutputFormat builder = dg.compose() for p in parts: builder.part(DocumentPart( html_content=p.get("htmlContent"), markdown_content=p.get("markdownContent"), template_name=p.get("templateName"), fields=p.get("fields"), )) if watermark: builder.watermark(watermark) builder.output_format(OutputFormat(output_format)) result = builder.generate() return base64.b64encode(result).decode() - mcp/src/docgen_mcp/server.py:125-125 (registration)The @mcp.tool() decorator registers compose_document as an MCP tool with the FastMCP instance.
@mcp.tool() - mcp/src/docgen_mcp/server.py:125-159 (schema)The function signature and docstring define the input schema: parts (list of dicts with htmlContent, markdownContent, templateName, fields), watermark (optional string), output_format (string, default PDF). Returns base64 string.
@mcp.tool() def compose_document( parts: list[dict[str, Any]], watermark: str | None = None, output_format: str = "PDF", ) -> str: """Compose a multi-part document from several sections. Each part is a dict with: htmlContent, markdownContent, templateName, fields. Args: parts: List of document parts. Each part can have htmlContent, markdownContent, templateName, fields. watermark: Optional diagonal watermark text overlay. output_format: Output format – PDF, DOCX, or ODT (default: PDF). Returns: Base64-encoded document bytes. """ dg = _get_client() from docgen.models import DocumentPart, OutputFormat builder = dg.compose() for p in parts: builder.part(DocumentPart( html_content=p.get("htmlContent"), markdown_content=p.get("markdownContent"), template_name=p.get("templateName"), fields=p.get("fields"), )) if watermark: builder.watermark(watermark) builder.output_format(OutputFormat(output_format)) result = builder.generate() return base64.b64encode(result).decode()