Skip to main content
Glama

convert_document

Convert documents to PDF, DOCX, images, and more using a local file, URL, or base64 string. Supports 100+ format combinations without storing templates.

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 main handler function for the convert_document tool. It resolves the file input (URL/path/base64), calls client.convertDocument to perform the conversion, and formats the result as MCP content (text, image, or blob resource). Errors are caught and returned as structured error messages.
    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) }],
        };
      }
    }
  • The input schema for convert_document defining three parameters: file (string, accepts path/URL/base64), convertTo (string format name or object with formatName + formatOptions), and converter (optional enum 'L'|'C'|'O' for the engine choice).
    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.'
        ),
    };
  • Tool registration in the MCP server. The convert_document tool is registered using server.registerTool with its name, description, schema, and a handler callback that passes the client and auth token.
    server.registerTool(
      convertDocumentToolName,
      { description: convertDocumentDescription, inputSchema: convertDocumentSchema },
      (args, extra) => handleConvertDocument(args, client, { apiKey: extra.authInfo?.token })
    );
  • The CarboneClient.convertDocument method that makes the actual HTTP POST request to the Carbone API endpoint /render/template?download=true, sending the base64 template content and convertTo/converter parameters, and returns the binary buffer and filename.
    async convertDocument(params: {
      template: string;
      convertTo: OutputFormat;
      converter?: string;
    }, options?: CallOptions): Promise<{ buffer: Buffer; filename: string }> {
      const body: Record<string, unknown> = {
        data: {},
        template: params.template,
        convertTo: params.convertTo,
      };
      if (params.converter) body['converter'] = params.converter;
    
      const response = await this.request('/render/template?download=true', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify(body),
      }, options);
    
      return this.handleBinaryResponse(response);
    }
  • The validation schema (ConvertDocumentSchema) using Zod, used for runtime validation of convert_document inputs. Defines file (base64 string), convertTo (OutputFormatSchema), and converter (optional 'L'|'C'|'O'). Relies on shared OUTPUT_FORMATS and CONVERTERS constants.
    export const ConvertDocumentSchema = z.object({
      file: z.string().min(1, 'File content required'),
      convertTo: OutputFormatSchema,
      converter: z.enum(CONVERTERS).optional(),
    });
Behavior4/5

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

No annotations provided, so description carries the burden. It explains input types (local path, URL, base64) and converter engine options. However, it doesn't detail side effects like temporary files or authentication requirements. Still, it's strong overall.

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 somewhat long but well-organized: summary, usage guideline, and examples. Could be slightly more concise, but each section serves a purpose.

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

Completeness5/5

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

Given no output schema and three parameters, the description covers input formats, output formats, converter engines, and provides many examples. It also references a full conversion matrix. Very complete.

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

Parameters5/5

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

Schema coverage is 100%, but the description adds significant value: groups output formats, explains converter engines with scenarios, and provides advanced format options usage. These go well beyond the schema.

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's purpose: 'Convert any document to another format without storing a template.' It also distinguishes from sibling tool render_document by specifying when that alternative is appropriate.

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

Usage Guidelines5/5

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

Explicitly mentions when to use render_document instead (for data injection, translations, batch generation). Provides numerous examples for common conversions, giving clear context for usage.

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