Skip to main content
Glama
cablate

Simple Document Processing MCP Server

html_cleaner

Cleans HTML files by stripping unnecessary tags and attributes, outputting simplified markup to a specified directory.

Instructions

Clean HTML by removing unnecessary tags and attributes

Input Schema

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

Implementation Reference

  • The actual handler function 'cleanHtml' that executes the html_cleaner tool logic. It reads an HTML file via JSDOM, removes unwanted tags (script, style, iframe, noscript) and attributes (onclick, onload, onerror, style), then writes the cleaned HTML to an output file.
    export async function cleanHtml(inputPath: string, outputDir: string) {
      try {
        console.error(`Starting HTML cleaning...`);
        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 unwantedTags = ["script", "style", "iframe", "noscript"];
        const unwantedAttrs = ["onclick", "onload", "onerror", "style"];
    
        unwantedTags.forEach((tag) => {
          document.querySelectorAll(tag).forEach((el) => el.remove());
        });
    
        document.querySelectorAll("*").forEach((el) => {
          unwantedAttrs.forEach((attr) => el.removeAttribute(attr));
        });
    
        const cleanedHtml = dom.serialize();
        const outputPath = path.join(outputDir, `cleaned_${uniqueId}.html`);
        await fs.writeFile(outputPath, cleanedHtml);
        console.error(`Written cleaned HTML to ${outputPath}`);
    
        return {
          success: true,
          data: `Successfully cleaned HTML and saved to ${outputPath}`,
        };
      } catch (error) {
        console.error(`Error in cleanHtml:`, error);
        return {
          success: false,
          error: error instanceof Error ? error.message : "Unknown error",
        };
      }
    }
  • The tool definition/schema for 'html_cleaner', including its name, description, and inputSchema (inputPath, outputDir).
    export const HTML_CLEAN_TOOL: Tool = {
      name: "html_cleaner",
      description: "Clean HTML by removing unnecessary tags and attributes",
      inputSchema: {
        type: "object",
        properties: {
          inputPath: {
            type: "string",
            description: "Path to the input HTML file",
          },
          outputDir: {
            type: "string",
            description: "Directory where cleaned HTML should be saved",
          },
        },
        required: ["inputPath", "outputDir"],
      },
    };
  • src/index.ts:150-166 (registration)
    The registration/handler dispatch in index.ts where the server routes 'html_cleaner' requests to the cleanHtml function.
    if (name === "html_cleaner") {
      const { inputPath, outputDir } = args as {
        inputPath: string;
        outputDir: string;
      };
      const result = await cleanHtml(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,
      };
    }
  • The tool is registered in the 'tools' array exported from _index.ts, which is used by the ListToolsRequestSchema handler.
    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];
  • Helper function 'generateUniqueId' used by cleanHtml to generate unique output filenames.
    function generateUniqueId(): string {
      return randomBytes(9).toString("hex");
    }
Behavior2/5

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

With no annotations, the description must disclose behavioral traits. It only states removal of 'unnecessary' elements without specifying criteria (e.g., scripts, styles, attributes). No mention of side effects, file permissions, or output structure.

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?

The description is a single sentence, which is concise but arguably too brief. It lacks details that would help the agent understand the tool's behavior, though it is front-loaded with the action and resource.

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 no output schema, the description does not explain what the output looks like (e.g., cleaned HTML file, error handling). It omits return values and side effects, leaving gaps for a tool with two required file path parameters.

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 is 100%, so the schema already describes both parameters. The description adds no additional meaning beyond what the schema provides; it does not clarify file formats, required permissions, or naming conventions for the output directory.

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 uses a specific verb 'clean' and resource 'HTML', stating it removes 'unnecessary tags and attributes'. This differentiates from siblings like html_formatter (formatting) and html_to_markdown (conversion), though it lacks clarity on what constitutes 'unnecessary'.

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 is provided on when to use this tool versus siblings such as html_formatter or html_extract_resources. The description does not mention prerequisites, use cases, or scenarios to avoid.

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