Skip to main content
Glama
cablate

Simple Document Processing MCP Server

html_to_text

Extract plain text from HTML files while maintaining document structure for easier reading and processing.

Instructions

Convert HTML to plain text while preserving structure

Input Schema

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

Implementation Reference

  • The core execution function for the html_to_text tool. Reads HTML file using fs, parses with JSDOM, extracts textContent from body, generates unique filename, writes to output directory.
    export async function htmlToText(inputPath: string, outputDir: string) {
      try {
        console.error(`Starting HTML to text 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 dom = new JSDOM(htmlContent);
        const { document } = dom.window;
    
        // 保留結構的文字轉換
        const text = document.body.textContent?.trim() || "";
        const outputPath = path.join(outputDir, `text_${uniqueId}.txt`);
        await fs.writeFile(outputPath, text);
        console.error(`Written text to ${outputPath}`);
    
        return {
          success: true,
          data: `Successfully converted HTML to text: ${outputPath}`,
        };
      } catch (error) {
        console.error(`Error in htmlToText:`, error);
        return {
          success: false,
          error: error instanceof Error ? error.message : "Unknown error",
        };
      }
    }
  • The Tool object definition for html_to_text, including name, description, and inputSchema for MCP validation.
    export const HTML_TO_TEXT_TOOL: Tool = {
      name: "html_to_text",
      description: "Convert HTML to plain text while preserving structure",
      inputSchema: {
        type: "object",
        properties: {
          inputPath: {
            type: "string",
            description: "Path to the input HTML file",
          },
          outputDir: {
            type: "string",
            description: "Directory where text file should be saved",
          },
        },
        required: ["inputPath", "outputDir"],
      },
    };
  • Imports HTML_TO_TEXT_TOOL from htmlTools.ts and registers it in the central 'tools' array exported for the MCP server.
    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:47-49 (registration)
    MCP server handler for listing tools, returns the 'tools' array which includes html_to_text.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools,
    }));
  • MCP CallToolRequestSchema dispatcher that matches name 'html_to_text', extracts args, calls htmlToText handler, and formats response.
    if (name === "html_to_text") {
      const { inputPath, outputDir } = args as {
        inputPath: string;
        outputDir: string;
      };
      const result = await htmlToText(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. It mentions 'preserving structure' which adds some behavioral context beyond basic conversion, but fails to disclose critical details like error handling, file size limits, supported HTML features, or whether it overwrites existing files. For a file-processing tool with zero annotation coverage, this is insufficient.

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 is front-loaded and appropriately sized for a straightforward conversion tool, with every word contributing to understanding.

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 tool involves file I/O and structure preservation, the description is incomplete. No output schema exists, so it doesn't explain return values like success status or error messages. With no annotations and minimal behavioral disclosure, it lacks details on performance, limitations, or integration context, making it inadequate for safe and effective use.

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 description coverage is 100%, so the schema fully documents both parameters (inputPath and outputDir). The description adds no parameter-specific information beyond what the schema provides, such as file format expectations or directory creation behavior. Baseline 3 is appropriate when the schema handles all parameter documentation.

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 verb 'convert' and the resource 'HTML to plain text', specifying the transformation. It distinguishes from siblings like 'html_to_markdown' by focusing on plain text output, but doesn't explicitly contrast with 'html_cleaner' or 'html_formatter' which might have overlapping functions.

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 like 'html_to_markdown' or 'html_cleaner' is provided. The description implies usage for HTML-to-text conversion but offers no context about prerequisites, limitations, or scenarios where other tools might be more appropriate.

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