Skip to main content
Glama
cablate

Simple Document Processing MCP Server

html_to_markdown

Convert HTML files to Markdown format by providing an input file path and output directory.

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 converts HTML to Markdown. Reads an input HTML file, uses TurndownService to convert it to Markdown format, and writes the output .md file.
    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",
        };
      }
    }
  • The Tool definition with name 'html_to_markdown', description, and inputSchema requiring inputPath and outputDir.
    // HTML 轉 Markdown 工具
    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"],
      },
    };
  • The tool is registered in the tools array as HTML_TO_MARKDOWN_TOOL (line 9), and re-exported via the wildcard export on line 15.
    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 MCP server request handler that routes 'html_to_markdown' calls to the htmlToMarkdown function and returns the result.
    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,
      };
Behavior1/5

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

No annotations provided, and the description fails to disclose critical behavioral details such as file overwrite behavior, error handling, or output encoding. The description adds no value beyond the tool name.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Single sentence is concise but borderline under-specified. Not wasteful, but lacks structure that could front-load key details.

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

Completeness1/5

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

For a file conversion tool with two required parameters, no output schema, and no annotations, the description is grossly incomplete. It omits file format specifics, error cases, and any behavioral contract.

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?

Input schema covers both parameters with descriptions, so the description adds no extra meaning. Baseline score of 3 applies as schema coverage is 100%.

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 explicitly states the action ('Convert') and resources ('HTML to Markdown'), clearly distinguishing it from sibling tools like html_to_text or html_cleaner.

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 guidance on when to use this tool versus alternatives (e.g., html_to_text). No mention of prerequisites or context, leaving the agent without decision support.

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