Skip to main content
Glama

x402_convert_file

Convert files between formats including image resize, CSV to JSON, HTML to PDF, and DOCX to PDF using URL-based inputs with base64 output.

Instructions

Convert files between formats — image resize/reformat, CSV to JSON, HTML to PDF, or DOCX to PDF. Price: $0.02 USDC per conversion (paid mode) | Free test: returns fixture data.

Supported conversions:

  • image: resize/reformat an image from a URL (Pillow) — outputs base64-encoded bytes

  • csv: convert a CSV URL to JSON array

  • html_pdf: render HTML from a URL to PDF — outputs base64-encoded bytes

  • docx: convert a DOCX document URL to PDF — outputs base64-encoded bytes (mammoth + WeasyPrint, content-fidelity not layout-preserving)

Input limit: 10MB source file. Output limit: 8MB (before base64 encoding). Without X402_PRIVATE_KEY, only the free test endpoint is available.

Returns: base64-encoded output bytes with MIME type, or JSON array for csv type.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesURL of the file to convert (public, http/https, max 10MB)
typeYesConversion type: image (resize/reformat), csv (CSV to JSON), html_pdf (HTML to PDF), docx (DOCX to PDF)
formatNoOutput image format (only for type='image', default: jpeg)
widthNoTarget width in pixels (only for type='image', preserves aspect ratio if height omitted)
heightNoTarget height in pixels (only for type='image', preserves aspect ratio if width omitted)

Implementation Reference

  • The implementation of the tool, handling either paid API calls or free test return based on configuration.
    async (params) => {
      const base = APIS.conversion.baseUrl;
      try {
        const usePaid = !!PRIVATE_KEY;
        if (usePaid) {
          const payload: Record<string, unknown> = { type: params.type, url: params.url };
          if (params.format !== undefined) payload.format = params.format;
          if (params.width !== undefined) payload.width = params.width;
          if (params.height !== undefined) payload.height = params.height;
          const data = await apiPost(base, "/convert", payload, true);
          return textResult({ mode: "paid", cost: "$0.02", ...data });
        } else {
          const data = await apiGet(base, "/convert/test");
          return textResult({
            mode: "free_test",
            note: "Free test — returns fixture data. Set X402_PRIVATE_KEY for live conversion.",
            ...data,
          });
        }
      } catch (err: any) {
        return errorResult(err.message);
      }
    }
  • src/index.ts:592-641 (registration)
    Registration of the x402_convert_file tool, including its schema and description.
    server.tool(
      "x402_convert_file",
      `Convert files between formats — image resize/reformat, CSV to JSON, HTML to PDF, or DOCX to PDF.
    Price: $0.02 USDC per conversion (paid mode) | Free test: returns fixture data.
    
    Supported conversions:
    - image: resize/reformat an image from a URL (Pillow) — outputs base64-encoded bytes
    - csv: convert a CSV URL to JSON array
    - html_pdf: render HTML from a URL to PDF — outputs base64-encoded bytes
    - docx: convert a DOCX document URL to PDF — outputs base64-encoded bytes (mammoth + WeasyPrint, content-fidelity not layout-preserving)
    
    Input limit: 10MB source file. Output limit: 8MB (before base64 encoding).
    Without X402_PRIVATE_KEY, only the free test endpoint is available.
    
    Returns: base64-encoded output bytes with MIME type, or JSON array for csv type.`,
      {
        url: z.string().url().describe("URL of the file to convert (public, http/https, max 10MB)"),
        type: z.enum(["image", "csv", "html_pdf", "docx"])
          .describe("Conversion type: image (resize/reformat), csv (CSV to JSON), html_pdf (HTML to PDF), docx (DOCX to PDF)"),
        format: z.enum(["jpeg", "png", "webp", "gif"]).optional()
          .describe("Output image format (only for type='image', default: jpeg)"),
        width: z.number().int().min(1).max(8000).optional()
          .describe("Target width in pixels (only for type='image', preserves aspect ratio if height omitted)"),
        height: z.number().int().min(1).max(8000).optional()
          .describe("Target height in pixels (only for type='image', preserves aspect ratio if width omitted)"),
      },
      async (params) => {
        const base = APIS.conversion.baseUrl;
        try {
          const usePaid = !!PRIVATE_KEY;
          if (usePaid) {
            const payload: Record<string, unknown> = { type: params.type, url: params.url };
            if (params.format !== undefined) payload.format = params.format;
            if (params.width !== undefined) payload.width = params.width;
            if (params.height !== undefined) payload.height = params.height;
            const data = await apiPost(base, "/convert", payload, true);
            return textResult({ mode: "paid", cost: "$0.02", ...data });
          } else {
            const data = await apiGet(base, "/convert/test");
            return textResult({
              mode: "free_test",
              note: "Free test — returns fixture data. Set X402_PRIVATE_KEY for live conversion.",
              ...data,
            });
          }
        } catch (err: any) {
          return errorResult(err.message);
        }
      }
    );
Behavior5/5

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

Excellent disclosure given zero annotations. Details cost model, file size limits (10MB input, 8MB output), authentication requirements, output formats (base64-encoded bytes vs JSON array), and specific behavioral caveats ('content-fidelity not layout-preserving' for DOCX). Explains that free test mode returns fixture data rather than actual conversions.

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?

Well-structured with clear sections (purpose, pricing, supported conversions, limits, auth, returns). Uses bullet points effectively for the four conversion types. Slightly verbose but appropriate for the complexity of four distinct conversion pipelines. Every sentence conveys necessary information about cost, limits, or behavior.

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?

Comprehensive coverage compensates fully for lack of annotations and output schema. Describes return values (base64 bytes with MIME type or JSON), error conditions (size limits), authentication modes, and implementation specifics for each conversion type. Complete enough for an agent to predict outcomes and handle responses without an output schema.

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?

With 100% schema coverage, baseline is 3. Description adds valuable constraints not in schema: 10MB source limit, 8MB output limit, base64 encoding of outputs, and implicit parameter relationships (format/width/height only relevant to image type). Enhances understanding of what the 'url' parameter expects (public, http/https).

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?

Description opens with specific verb ('Convert') and resources ('files between formats'), explicitly listing supported conversions (image resize/reformat, CSV to JSON, HTML to PDF, DOCX to PDF). Clearly distinguishes from sibling tools like x402_scrape_url or x402_screenshot by focusing on file format transformation rather than data extraction or capture.

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?

Provides clear prerequisites (X402_PRIVATE_KEY for paid mode, public HTTP/HTTPS URLs) and cost structure ($0.02 USDC vs free test endpoint). While it doesn't explicitly contrast with sibling tools, the distinct conversion focus and pricing disclosure provide sufficient context for selection. Could improve by explicitly stating when to use this versus x402_pdf_extract or x402_screenshot.

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/jameswilliamwisdom/x402-mcp-server'

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