Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
partsYes
watermarkNo
output_formatNoPDF

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • 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()
  • The @mcp.tool() decorator registers compose_document as an MCP tool with the FastMCP instance.
    @mcp.tool()
  • 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()
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the burden. It discloses the composition behavior, optional watermark, output format options, and return type (Base64-encoded bytes). However, it omits details like error handling, required permissions, or whether the operation is destructive (though composition is likely non-destructive).

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise, with a clear opening sentence, bullet-style parameter explanations, and a return statement. Every sentence adds value without redundancy, and the structure is front-loaded with the core purpose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (multi-part composition with flexible fields) and the lack of schema descriptions, the description covers key aspects: part structure, watermark, output format, and return value. It lacks error handling or edge-case guidance but is sufficient for basic use. The presence of an output schema (even if not described) lowers the burden slightly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It explains the 'parts' parameter as a list of dicts with fields like htmlContent, markdownContent, templateName, and fields. It also clarifies 'watermark' as diagonal text overlay and enumerates output_format options (PDF, DOCX, ODT). This adds significant meaning beyond the bare schema types.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool composes a multi-part document from several sections, which distinguishes it from sibling tools like generate_document or generate_pdf_from_html that likely create single-part documents. The verb 'compose' and resource 'multi-part document' are specific and descriptive.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description lacks explicit guidance on when to use this tool versus alternatives such as generate_document or generate_pdf_from_html. It does not state prerequisites, limitations, or scenarios where other tools would be more appropriate.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/dokmatiq/docgen-sdks'

If you have feedback or need assistance with the MCP directory API, please join our Discord server