Skip to main content
Glama
cablate

Simple Document Processing MCP Server

docx_to_html

Transform DOCX documents into HTML while preserving formatting. Provide the input file path and output directory to complete the conversion.

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

  • The docxToHtml async function that handles the actual DOCX-to-HTML conversion using the 'mammoth' library. It reads the DOCX file, converts it to HTML, and saves it to the output directory with a unique ID.
    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",
        };
      }
    }
  • The DOCX_TO_HTML_TOOL constant defines the tool's name ('docx_to_html'), description, and input schema specifying required inputPath and outputDir string parameters.
    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 tool is registered in the 'tools' array exported from _index.ts, making it available to the MCP server.
    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];
  • The call handler in the MCP server that routes 'docx_to_html' requests to the docxToHtml function and returns the result.
    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,
      };
    }
  • Helper function generateUniqueId used to create unique filenames for the converted HTML output.
    function generateUniqueId(): string {
      return randomBytes(9).toString("hex");
    }
Behavior3/5

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

No annotations, so description carries full burden. 'Preserving formatting' adds some behavior, but no info on safety, auth, or side effects. Adequate but not comprehensive.

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?

Single sentence, no wasted words, perfectly concise for a simple tool.

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

Completeness4/5

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

Given simplicity (2 params, no output schema), description covers purpose and core behavior. Lacks mentions of limitations or error cases, but adequate.

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?

Schema coverage 100%, schema descriptions are clear. Description adds no extra meaning beyond 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?

Clearly states verb 'Convert', resources 'DOCX to HTML', and a specific attribute 'preserving formatting'. Distinct from siblings like docx_to_pdf.

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 when-to-use guidance, no mention of alternatives like html_to_text for text extraction, no exclusions provided.

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