Skip to main content
Glama
cablate

Simple Document Processing MCP Server

html_extract_resources

Extract images, videos, and links from HTML files to save resources in a specified directory for document processing.

Instructions

Extract all resources (images, videos, links) from HTML

Input Schema

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

Implementation Reference

  • The main handler function that extracts images, links, and videos from HTML using JSDOM, saves them as JSON.
    export async function extractHtmlResources(
      inputPath: string,
      outputDir: string
    ) {
      try {
        console.error(`Starting resource extraction...`);
        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 resources = {
          images: Array.from(document.querySelectorAll("img")).map(
            (img) => (img as HTMLImageElement).src
          ),
          links: Array.from(document.querySelectorAll("a")).map(
            (a) => (a as HTMLAnchorElement).href
          ),
          videos: Array.from(document.querySelectorAll("video source")).map(
            (video) => (video as HTMLSourceElement).src
          ),
        };
    
        const outputPath = path.join(outputDir, `resources_${uniqueId}.json`);
        await fs.writeFile(outputPath, JSON.stringify(resources, null, 2));
        console.error(`Written resources to ${outputPath}`);
    
        return {
          success: true,
          data: `Successfully extracted resources: ${outputPath}`,
        };
      } catch (error) {
        console.error(`Error in extractHtmlResources:`, error);
        return {
          success: false,
          error: error instanceof Error ? error.message : "Unknown error",
        };
      }
    }
  • Tool schema definition including name, description, and input schema requiring inputPath and outputDir.
    export const HTML_EXTRACT_RESOURCES_TOOL: Tool = {
      name: "html_extract_resources",
      description: "Extract all resources (images, videos, links) from HTML",
      inputSchema: {
        type: "object",
        properties: {
          inputPath: {
            type: "string",
            description: "Path to the input HTML file",
          },
          outputDir: {
            type: "string",
            description: "Directory where resources should be saved",
          },
        },
        required: ["inputPath", "outputDir"],
      },
    };
  • src/index.ts:204-220 (registration)
    Server request handler dispatches calls to 'html_extract_resources' by invoking the extractHtmlResources function.
    if (name === "html_extract_resources") {
      const { inputPath, outputDir } = args as {
        inputPath: string;
        outputDir: string;
      };
      const result = await extractHtmlResources(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 includes HTML_EXTRACT_RESOURCES_TOOL, served via listTools endpoint.
    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];
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 what the tool does but lacks critical details: it doesn't specify if this is a read-only operation, whether it modifies files, what permissions are needed, how errors are handled, or the output format (e.g., saved files vs. returned list). For a tool with two parameters and no annotations, this is a significant gap in transparency.

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 front-loads the core functionality ('Extract all resources') without unnecessary words. Every part of the sentence contributes directly to understanding the tool's purpose, making it highly concise and well-structured.

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 complexity (2 parameters, no output schema, no annotations), the description is incomplete. It explains what the tool does but omits behavioral aspects (e.g., side effects, error handling), usage context, and output details. For a tool that likely involves file I/O and resource handling, this leaves significant gaps for an agent to operate effectively.

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%, with clear descriptions for both parameters ('inputPath' and 'outputDir'), so the schema already documents their purpose. The description adds no additional meaning beyond implying resource extraction, which aligns with the schema but doesn't provide extra context like file format expectations or directory creation behavior.

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 action ('Extract') and target resources ('images, videos, links') from a specific source ('HTML'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'html_cleaner' or 'html_to_text', which might also process HTML content in different ways.

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. It doesn't mention prerequisites (e.g., needing an HTML file), exclusions (e.g., not for extracting text), or compare it to siblings like 'html_to_markdown' or 'html_cleaner', leaving the agent to infer usage context.

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