Skip to main content
Glama
cablate

Simple Document Processing MCP Server

html_to_markdown

Convert HTML files to Markdown format for easier editing and documentation. Specify input HTML file and output directory to generate clean Markdown content.

Instructions

Convert HTML to Markdown format

Input Schema

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

Implementation Reference

  • The core handler function that reads an HTML file from inputPath, converts it to Markdown using TurndownService, generates a unique filename, saves it to outputDir, and returns success/error info.
    export async function htmlToMarkdown(inputPath: string, outputDir: string) {
      try {
        console.error(`Starting HTML to Markdown 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 htmlContent = await fs.readFile(inputPath, "utf-8");
        const turndownService = new TurndownService();
        const markdown = turndownService.turndown(htmlContent);
    
        const outputPath = path.join(outputDir, `markdown_${uniqueId}.md`);
        await fs.writeFile(outputPath, markdown);
        console.error(`Written Markdown to ${outputPath}`);
    
        return {
          success: true,
          data: `Successfully converted HTML to Markdown: ${outputPath}`,
        };
      } catch (error) {
        console.error(`Error in htmlToMarkdown:`, error);
        return {
          success: false,
          error: error instanceof Error ? error.message : "Unknown error",
        };
      }
    }
  • Defines the tool's metadata, name, description, and input schema (requiring inputPath and outputDir strings).
    export const HTML_TO_MARKDOWN_TOOL: Tool = {
      name: "html_to_markdown",
      description: "Convert HTML to Markdown format",
      inputSchema: {
        type: "object",
        properties: {
          inputPath: {
            type: "string",
            description: "Path to the input HTML file",
          },
          outputDir: {
            type: "string",
            description: "Directory where Markdown file should be saved",
          },
        },
        required: ["inputPath", "outputDir"],
      },
    };
  • Registers HTML_TO_MARKDOWN_TOOL in the central tools array exported for use in 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];
  • Dispatch handler in the main MCP server that matches the tool name, extracts arguments, calls the htmlToMarkdown function, and formats the response.
    if (name === "html_to_markdown") {
      const { inputPath, outputDir } = args as {
        inputPath: string;
        outputDir: string;
      };
      const result = await htmlToMarkdown(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 to generate unique IDs for output filenames, used in htmlToMarkdown.
    function generateUniqueId(): string {
      return randomBytes(9).toString("hex");
    }
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. It states the conversion action but lacks details on error handling, performance, or side effects (e.g., whether it overwrites files in the output directory). This is a significant gap for a tool with file operations, making it inadequate for safe use.

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 purpose without any fluff. It's appropriately sized and front-loaded, making it easy for an agent to parse quickly, earning a perfect score for conciseness.

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 lack of annotations and output schema, the description is incomplete for a file-processing tool. It doesn't cover behavioral aspects like error handling or output format details, and with siblings offering similar conversions, it fails to provide enough context for reliable tool selection and 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 description adds no parameter semantics beyond what the input schema provides, as schema description coverage is 100% with clear documentation for both parameters. This meets the baseline score of 3, where the schema handles the heavy lifting, but the description doesn't enhance understanding of parameter usage or constraints.

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 ('HTML to Markdown format'), making it immediately understandable. However, it doesn't differentiate from sibling tools like 'html_to_text' or 'format_convert', which might offer similar or overlapping functionality, preventing a perfect score.

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. With siblings like 'html_to_text' and 'format_convert' available, it fails to specify scenarios where HTML-to-Markdown conversion is preferred over other text or format transformations, leaving the agent to guess based on tool names alone.

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