Skip to main content
Glama
cablate

Simple Document Processing MCP Server

html_formatter

Format and beautify HTML code by taking an input file path and saving the structured output to a specified directory.

Instructions

Format and beautify HTML code

Input Schema

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

Implementation Reference

  • The core handler function that implements the html_formatter tool logic: reads input HTML, parses with JSDOM, serializes (beautifies), generates unique filename, and saves to output directory.
    export async function formatHtml(inputPath: string, outputDir: string) {
      try {
        console.error(`Starting HTML formatting...`);
        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;
    
        // 格式化 HTML
        const formattedHtml = dom.serialize();
        const outputPath = path.join(outputDir, `formatted_${uniqueId}.html`);
        await fs.writeFile(outputPath, formattedHtml);
        console.error(`Written formatted HTML to ${outputPath}`);
    
        return {
          success: true,
          data: `Successfully formatted HTML: ${outputPath}`,
        };
      } catch (error) {
        console.error(`Error in formatHtml:`, error);
        return {
          success: false,
          error: error instanceof Error ? error.message : "Unknown error",
        };
      }
    }
  • The Tool object defining the schema, name, and description for the html_formatter tool.
    export const HTML_FORMAT_TOOL: Tool = {
      name: "html_formatter",
      description: "Format and beautify HTML code",
      inputSchema: {
        type: "object",
        properties: {
          inputPath: {
            type: "string",
            description: "Path to the input HTML file",
          },
          outputDir: {
            type: "string",
            description: "Directory where formatted HTML should be saved",
          },
        },
        required: ["inputPath", "outputDir"],
      },
    };
  • src/index.ts:222-238 (registration)
    Registration and dispatch logic in the main CallToolRequestSchema handler: matches tool name and invokes the formatHtml function.
    if (name === "html_formatter") {
      const { inputPath, outputDir } = args as {
        inputPath: string;
        outputDir: string;
      };
      const result = await formatHtml(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 tools array export that registers HTML_FORMAT_TOOL for the ListToolsRequestSchema.
    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 in formatHtml to create 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 provided, the description carries the full burden of behavioral disclosure. 'Format and beautify' implies a transformation that modifies the HTML structure, but it doesn't specify whether this is a read-only operation, what formatting rules are applied, if it preserves original content, or what happens on errors. For a tool with two parameters and no annotations, 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 phrase ('Format and beautify HTML code') that directly conveys the core functionality without any wasted words. It's appropriately sized and front-loaded, making it easy to parse quickly.

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 has two parameters, no annotations, and no output schema, the description is incomplete. It doesn't explain what 'beautify' entails, the expected output format, error handling, or how it differs from similar tools. For a transformation tool with this context, more detail is needed to guide 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?

The input schema has 100% description coverage, clearly documenting both parameters ('inputPath' and 'outputDir') with their purposes. The description adds no additional parameter information beyond what's in the schema, so it meets the baseline of 3 for high schema coverage without compensating value.

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 'Format and beautify HTML code' clearly states the verb ('format and beautify') and resource ('HTML code'), making the purpose immediately understandable. However, it doesn't distinguish this tool from its sibling 'text_formatter' or 'html_cleaner', which might have overlapping functionality with HTML content.

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 like 'html_cleaner' or 'text_formatter'. There's no mention of prerequisites, specific use cases, or exclusions, leaving the agent to infer usage from the tool name 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