Skip to main content
Glama
cablate

Simple Document Processing MCP Server

docx_to_html

Convert DOCX files to HTML format while preserving original document formatting for web display or further processing.

Instructions

Convert DOCX to HTML while preserving formatting

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputPathYesPath to the input DOCX file
outputDirYesDirectory where HTML should be saved

Implementation Reference

  • Defines the tool schema for 'docx_to_html', including name, description, and input schema requiring inputPath and outputDir.
    export const DOCX_TO_HTML_TOOL: Tool = {
      name: "docx_to_html",
      description: "Convert DOCX to HTML while preserving formatting",
      inputSchema: {
        type: "object",
        properties: {
          inputPath: {
            type: "string",
            description: "Path to the input DOCX file",
          },
          outputDir: {
            type: "string",
            description: "Directory where HTML should be saved",
          },
        },
        required: ["inputPath", "outputDir"],
      },
    };
  • The core handler function that converts DOCX to HTML using mammoth, ensures output directory exists, generates unique filename, and returns success/error.
    export async function docxToHtml(inputPath: string, outputDir: string) {
      try {
        console.error(`Starting DOCX to HTML conversion...`);
        console.error(`Input file: ${inputPath}`);
        console.error(`Output directory: ${outputDir}`);
    
        // 確保輸出目錄存在
        try {
          await fs.access(outputDir);
          console.error(`Output directory exists: ${outputDir}`);
        } catch {
          console.error(`Creating output directory: ${outputDir}`);
          await fs.mkdir(outputDir, { recursive: true });
          console.error(`Created output directory: ${outputDir}`);
        }
    
        const uniqueId = generateUniqueId();
        const buffer = await fs.readFile(inputPath);
    
        const result = await mammoth.convertToHtml({ buffer });
        console.error(
          `Conversion completed with ${result.messages.length} messages`
        );
    
        const outputPath = path.join(outputDir, `converted_${uniqueId}.html`);
        await fs.writeFile(outputPath, result.value);
        console.error(`Written HTML to ${outputPath}`);
    
        return {
          success: true,
          data: `Successfully converted DOCX to HTML: ${outputPath}`,
        };
      } catch (error) {
        console.error(`Error in docxToHtml:`, error);
        return {
          success: false,
          error: error instanceof Error ? error.message : "Unknown error",
        };
      }
    }
  • Imports DOCX_TO_HTML_TOOL and includes it in the exported 'tools' array used for MCP tool listing.
    import { DOCUMENT_READER_TOOL } from "./documentReader.js";
    import { DOCX_TO_HTML_TOOL, DOCX_TO_PDF_TOOL } from "./docxTools.js";
    import { EXCEL_READ_TOOL } from "./excelTools.js";
    import { FORMAT_CONVERTER_TOOL } from "./formatConverterPlus.js";
    import { HTML_CLEAN_TOOL, HTML_EXTRACT_RESOURCES_TOOL, HTML_FORMAT_TOOL, HTML_TO_MARKDOWN_TOOL, HTML_TO_TEXT_TOOL } from "./htmlTools.js";
    import { PDF_MERGE_TOOL, PDF_SPLIT_TOOL } from "./pdfTools.js";
    import { TEXT_DIFF_TOOL, TEXT_ENCODING_CONVERT_TOOL, TEXT_FORMAT_TOOL, TEXT_SPLIT_TOOL } from "./txtTools.js";
    
    export const tools = [DOCUMENT_READER_TOOL, PDF_MERGE_TOOL, PDF_SPLIT_TOOL, DOCX_TO_PDF_TOOL, DOCX_TO_HTML_TOOL, HTML_CLEAN_TOOL, HTML_TO_TEXT_TOOL, HTML_TO_MARKDOWN_TOOL, HTML_EXTRACT_RESOURCES_TOOL, HTML_FORMAT_TOOL, TEXT_DIFF_TOOL, TEXT_SPLIT_TOOL, TEXT_FORMAT_TOOL, TEXT_ENCODING_CONVERT_TOOL, EXCEL_READ_TOOL, FORMAT_CONVERTER_TOOL];
  • src/index.ts:132-148 (registration)
    MCP server request handler dispatches 'docx_to_html' tool calls to the docxToHtml function.
    if (name === "docx_to_html") {
      const { inputPath, outputDir } = args as {
        inputPath: string;
        outputDir: string;
      };
      const result = await docxToHtml(inputPath, outputDir);
      if (!result.success) {
        return {
          content: [{ type: "text", text: `Error: ${result.error}` }],
          isError: true,
        };
      }
      return {
        content: [{ type: "text", text: fileOperationResponse(result.data) }],
        isError: false,
      };
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. While it mentions 'preserving formatting', it doesn't address critical aspects like error handling (e.g., invalid DOCX files), performance (e.g., large file processing), or output specifics (e.g., HTML structure or embedded resources). This leaves significant gaps for a conversion tool.

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 a single, efficient sentence that directly states the tool's core function and key constraint ('preserving formatting'). It is front-loaded with essential information and contains no redundant or unnecessary details.

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?

Given the complexity of a file conversion tool with no annotations and no output schema, the description is incomplete. It lacks details on behavioral traits (e.g., error cases, performance), output format (e.g., HTML file naming, structure), and usage context compared to siblings. This makes it inadequate for reliable agent invocation.

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

Parameters3/5

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

The input schema has 100% description coverage, clearly documenting both parameters ('inputPath' and 'outputDir'). The description adds no additional parameter semantics beyond what the schema provides, such as file format requirements or directory permissions. Baseline 3 is appropriate since the schema does the heavy lifting.

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's purpose with a specific verb ('Convert') and resource ('DOCX to HTML'), and mentions the key constraint of 'preserving formatting'. However, it doesn't explicitly differentiate from sibling tools like 'format_convert' or 'html_formatter', which could have overlapping functionality.

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 provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'docx_to_pdf' for PDF conversion or 'html_formatter' for HTML formatting, nor does it specify prerequisites such as file accessibility or format compatibility.

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/cablate/mcp-doc-forge'

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