Skip to main content
Glama

generate_document

Generate documents in PDF, DOCX, or ODT format from HTML or Markdown content. Optionally apply templates, replace fields, and overlay a diagonal watermark.

Instructions

Generate a document with optional template, fields, and watermark.

Args: html_content: HTML content for the document body. markdown_content: Markdown content (alternative to HTML). template_name: Name of a pre-uploaded template (ODT/DOCX). fields: Template field replacements (key-value pairs). watermark: Diagonal watermark text overlay. output_format: Output format – PDF, DOCX, or ODT (default: PDF).

Returns: Base64-encoded document bytes.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
html_contentNo
markdown_contentNo
template_nameNo
fieldsNo
watermarkNo
output_formatNoPDF

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The @mcp.tool() decorated handler function that generates documents from HTML, Markdown, templates, fields, and watermarks, returning a base64-encoded document.
    @mcp.tool()
    def generate_document(
        html_content: str | None = None,
        markdown_content: str | None = None,
        template_name: str | None = None,
        fields: dict[str, str] | None = None,
        watermark: str | None = None,
        output_format: str = "PDF",
    ) -> str:
        """Generate a document with optional template, fields, and watermark.
    
        Args:
            html_content: HTML content for the document body.
            markdown_content: Markdown content (alternative to HTML).
            template_name: Name of a pre-uploaded template (ODT/DOCX).
            fields: Template field replacements (key-value pairs).
            watermark: 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 OutputFormat
    
        builder = dg.document()
        if html_content:
            builder.html(html_content)
        if markdown_content:
            builder.markdown(markdown_content)
        if template_name:
            builder.template(template_name)
        if fields:
            builder.fields(fields)
        if watermark:
            builder.watermark(watermark)
        builder.output_format(OutputFormat(output_format))
    
        result = builder.generate()
        return base64.b64encode(result).decode()
  • The tool is registered as an MCP tool via the @mcp.tool() decorator on the generate_document function. The mcp instance (FastMCP('DocGen')) is created at line 25.
    @mcp.tool()
  • The _get_client() helper function used by generate_document to lazily initialize and return the DocGen client.
    def _get_client():
        """Lazy-initialise the DocGen client."""
        global _client
        if _client is None:
            # Import here so the module can be imported without the SDK installed
            # (useful for schema introspection)
            from docgen import DocGen
    
            api_key = os.environ.get("DOCGEN_API_KEY", "")
            if not api_key:
                raise RuntimeError(
                    "DOCGEN_API_KEY environment variable is required. "
                    "Set it to your DocGen API key before starting the server."
                )
            base_url = os.environ.get("DOCGEN_BASE_URL")
            kwargs: dict[str, Any] = {"api_key": api_key}
            if base_url:
                kwargs["base_url"] = base_url
            _client = DocGen(**kwargs)
        return _client
Behavior3/5

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

No annotations provided, so description must disclose behavior. It mentions that the tool generates a document and returns base64-encoded bytes. However, it does not state whether any state is modified, if authentication is required, or any rate limits. The stateless nature is implied but not explicit.

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

Conciseness4/5

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

The description is concise with a clear opening line and a list of parameters. It avoids redundancy but the list of args is necessary due to lack of schema descriptions. Could be more structured (e.g., separate sections for args and return).

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

Completeness3/5

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

Covers inputs and output, but misses stating that at least one of html_content, markdown_content, or template_name must be provided (though schema marks all optional). No examples or usage notes. Output schema exists, so return values are assumed covered.

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 has no descriptions (0% coverage), so the description fully compensates by explaining each parameter's purpose. However, it does not clarify constraints like mutual exclusivity of html_content and markdown_content, or that a template_name requires a pre-uploaded template.

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

Purpose4/5

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

The description clearly states the tool generates documents with optional template, fields, and watermark. It lists inputs and output format. However, it does not differentiate from siblings like generate_pdf_from_html or generate_pdf_from_markdown, which perform similar tasks.

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?

No guidance on when to use this tool vs alternatives. For example, it doesn't clarify that if only HTML to PDF is needed, generate_pdf_from_html might be more appropriate. No prerequisites or exclusions mentioned.

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