Skip to main content
Glama

convert_document

Convert any document to another format without storing a template. Supports 100+ input/output combinations: Office documents, PDFs, images, and more.

Instructions

Convert any document to another format without storing a template. Supports 100+ input/output format combinations: Office documents, PDFs, images, web pages, spreadsheets, and more. The source file can be a local path, a URL, or a base64 string. Use render_document instead when you need data injection ({d.field} tags), translations, or batch generation. Common conversions: DOCX → PDF (file: "report.docx", convertTo: "pdf"), XLSX → PDF (file: "data.xlsx", convertTo: "pdf"), PPTX → PDF (file: "slides.pptx", convertTo: "pdf", converter: "O" for best fidelity), HTML → PDF (file: "page.html", convertTo: "pdf", converter: "C" for full CSS/JS rendering), DOCX → HTML (file: "doc.docx", convertTo: "html"), XLSX → CSV (file: "sheet.xlsx", convertTo: "csv"), PDF → PNG (file: "doc.pdf", convertTo: "png"), PPTX → PNG (first slide as image), MD → PDF (file: "readme.md", convertTo: "pdf").

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fileYesThe document to convert. Three input forms are accepted: (1) Local file path — absolute or relative, e.g. "/home/user/report.docx" or "./invoice.xlsx". (2) HTTPS URL — the file is downloaded automatically, e.g. "https://example.com/file.pptx". (3) Base64-encoded string — the raw file content encoded as base64. Supported input formats include: DOCX, XLSX, PPTX, ODT, ODS, ODP, ODG, HTML, XHTML, XML, IDML, Markdown (MD), PDF, TXT, CSV, PNG, JPG, SVG, and more. Full conversion matrix: https://carbone.io/documentation/developer/http-api/generate-reports.html#output-file-type
convertToYesTarget output format. Documents : "pdf", "docx", "xlsx", "pptx", "odt", "ods", "odp", "odg", "rtf", "epub". Web/text : "html", "xhtml", "txt", "csv", "md", "xml", "idml". Images : "png", "jpg", "jpeg", "webp", "svg", "tiff", "bmp", "gif". Archive : "zip" (batch output). Simple usage: "pdf". Advanced usage: { "formatName": "pdf", "formatOptions": { "EncryptFile": true, "DocumentOpenPassword": "secret" } }.
converterNoConverter engine. Only relevant when convertTo is "pdf" (or an image format rasterised from a document). "L" — LibreOffice (default): best all-round engine for DOCX, XLSX, PPTX, ODT, ODS, ODP. "O" — OnlyOffice: highest fidelity rendering for Microsoft Office formats (DOCX, XLSX, PPTX). "C" — Chromium: best for HTML, CSS, JavaScript — full browser rendering. If omitted, LibreOffice is used by default.

Implementation Reference

  • The handler function that executes the convert_document tool logic. It takes file, convertTo, and optional converter args, calls client.convertDocument(), and returns the converted document content.
    export async function handleConvertDocument(
      args: { file: string; convertTo: z.infer<typeof convertDocumentSchema.convertTo>; converter?: 'L' | 'C' | 'O' },
      client: CarboneClient,
      options?: CallOptions
    ) {
      try {
        const { file, ...rest } = args;
        const result = await client.convertDocument({ ...rest, template: await resolveFileInput(file) }, options);
    
        const content = toToolContent(result.buffer, result.filename, args.convertTo);
        return { content: [content] };
      } catch (error) {
        return {
          isError: true,
          content: [{ type: 'text' as const, text: formatError(error) }],
        };
      }
    }
  • Input schema for convert_document: defines 'file' (path/URL/base64), 'convertTo' (output format with optional advanced options), and 'converter' (engine: L/C/O).
    export const convertDocumentSchema = {
      file: z
        .string()
        .min(1)
        .describe(
          'The document to convert. Three input forms are accepted: ' +
          '(1) Local file path — absolute or relative, e.g. "/home/user/report.docx" or "./invoice.xlsx". ' +
          '(2) HTTPS URL — the file is downloaded automatically, e.g. "https://example.com/file.pptx". ' +
          '(3) Base64-encoded string — the raw file content encoded as base64. ' +
          'Supported input formats include: DOCX, XLSX, PPTX, ODT, ODS, ODP, ODG, HTML, XHTML, XML, IDML, ' +
          'Markdown (MD), PDF, TXT, CSV, PNG, JPG, SVG, and more. ' +
          'Full conversion matrix: https://carbone.io/documentation/developer/http-api/generate-reports.html#output-file-type'
        ),
    
      convertTo: z
        .union([
          z.enum(OUTPUT_FORMATS),
          z.object({
            formatName: z.enum(OUTPUT_FORMATS).describe('Target format name.'),
            formatOptions: z
              .record(z.string(), z.unknown())
              .optional()
              .describe(
                'Advanced format options object. Examples by format: ' +
                'PDF — { "EncryptFile": true, "DocumentOpenPassword": "secret", "DocumentPermissionPassword": "owner" } password-protect; ' +
                'PDF — { "Watermarks": [{ "text": "DRAFT", "opacity": 0.2, "rotation": -45, "fontsize": 60 }] } up to 5 watermarks; ' +
                'PDF — { "SelectPdfVersion": 1 } PDF/A-1b compliance (use 2 for PDF/A-2, 3 for PDF/A-3); ' +
                'PDF — { "PageRange": "1-3,5" } export specific pages only; ' +
                'PDF — { "ConvertSlideshow": true } convert each slide to a separate PDF page; ' +
                'Images (PNG/JPG/WEBP) — { "Quality": 90 } set compression quality 0-100; ' +
                'Images — { "density": 150 } set DPI for rasterisation (default 96); ' +
                'CSV — { "fieldSeparator": ";" } custom column separator.'
              ),
          }),
        ])
        .describe(
          'Target output format. ' +
          'Documents : "pdf", "docx", "xlsx", "pptx", "odt", "ods", "odp", "odg", "rtf", "epub". ' +
          'Web/text  : "html", "xhtml", "txt", "csv", "md", "xml", "idml". ' +
          'Images    : "png", "jpg", "jpeg", "webp", "svg", "tiff", "bmp", "gif". ' +
          'Archive   : "zip" (batch output). ' +
          'Simple usage: "pdf". ' +
          'Advanced usage: { "formatName": "pdf", "formatOptions": { "EncryptFile": true, "DocumentOpenPassword": "secret" } }.'
        ),
    
      converter: z
        .enum(CONVERTERS)
        .optional()
        .describe(
          'Converter engine. Only relevant when convertTo is "pdf" (or an image format rasterised from a document). ' +
          '"L" — LibreOffice (default): best all-round engine for DOCX, XLSX, PPTX, ODT, ODS, ODP. ' +
          '"O" — OnlyOffice: highest fidelity rendering for Microsoft Office formats (DOCX, XLSX, PPTX). ' +
          '"C" — Chromium: best for HTML, CSS, JavaScript — full browser rendering. ' +
          'If omitted, LibreOffice is used by default.'
        ),
    };
  • Exported constants: convertDocumentToolName ('convert_document'), convertDocumentDescription (tool description string).
    export const convertDocumentToolName = 'convert_document';
    
    export const convertDocumentDescription =
      'Convert any document to another format without storing a template. ' +
      'Supports 100+ input/output format combinations: Office documents, PDFs, images, web pages, spreadsheets, and more. ' +
      'The source file can be a local path, a URL, or a base64 string. ' +
      'Use render_document instead when you need data injection ({d.field} tags), translations, or batch generation. ' +
      'Common conversions: ' +
      'DOCX → PDF (file: "report.docx", convertTo: "pdf"), ' +
      'XLSX → PDF (file: "data.xlsx", convertTo: "pdf"), ' +
      'PPTX → PDF (file: "slides.pptx", convertTo: "pdf", converter: "O" for best fidelity), ' +
      'HTML → PDF (file: "page.html", convertTo: "pdf", converter: "C" for full CSS/JS rendering), ' +
      'DOCX → HTML (file: "doc.docx", convertTo: "html"), ' +
      'XLSX → CSV (file: "sheet.xlsx", convertTo: "csv"), ' +
      'PDF → PNG (file: "doc.pdf", convertTo: "png"), ' +
      'PPTX → PNG (first slide as image), ' +
      'MD → PDF (file: "readme.md", convertTo: "pdf").';
  • src/tools/index.ts:4-9 (registration)
    Imports convertDocumentToolName, convertDocumentDescription, convertDocumentSchema, and handleConvertDocument from convert.ts.
    import {
      convertDocumentToolName,
      convertDocumentDescription,
      convertDocumentSchema,
      handleConvertDocument,
    } from './convert.js';
  • Registration of the convert_document MCP tool via server.registerTool() with its name, description, schema, and handler callback.
    server.registerTool(
      convertDocumentToolName,
      { description: convertDocumentDescription, inputSchema: convertDocumentSchema },
      (args, extra) => handleConvertDocument(args, client, { apiKey: extra.authInfo?.token })
    );
Behavior3/5

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

No annotations are provided, so the description bears the full burden of behavioral disclosure. It does disclose the three input forms (local path, URL, base64) and three converter engines (L, O, C) with their strengths, which is useful. However, it lacks operational details such as whether the conversion is synchronous or asynchronous, typical response format, file size limits, or how temporary files are handled. The description is moderately transparent but incomplete.

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 relatively long but well-structured: it starts with a clear purpose statement, then lists the alternative tool, then provides a bulleted list of common conversions. Every sentence contributes useful information, though the list of examples could be slightly more compact. It is front-loaded with key distinctions.

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

Completeness2/5

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

The tool has no output schema, so the description should explain the return value and any side effects. However, it does not mention the output format (e.g., returns a file URL, binary data, or base64 string) or error handling. The only hint is 'zip' for batch output. This omission significantly reduces completeness for an agent that needs to process the result.

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?

The input schema already has 100% description coverage for all three parameters. The description adds substantial value beyond the schema by providing extensive examples for each parameter (e.g., converter engine choices, advanced formatOptions for PDF encryption, watermarks, page ranges). It explains complex parameter usage (convertTo as string or object) that the schema only partially covers.

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 specifies the action: 'Convert any document to another format without storing a template.' It lists over 100 format combinations and provides numerous concrete examples, making the tool's purpose unmistakable. It also explicitly distinguishes itself from the sibling tool render_document by describing when to use the alternative (data injection, translations, batch generation).

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

Usage Guidelines4/5

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

The description gives clear guidance on when to use render_document instead, citing scenarios with data injection, translations, and batch generation. It also provides many conversion examples to help the agent pick the right approach. However, it does not explicitly state when not to use this tool (e.g., if no conversion is possible) or elaborate on prerequisites like file size limits or access permissions.

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/carboneio/carbone-mcp'

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