Skip to main content
Glama
tatn

MCP Server Fetch TypeScript

by tatn

get_markdown

Convert web pages to structured Markdown while preserving tables, lists, and document hierarchy for clean content extraction.

Instructions

Converts web page content to well-formatted Markdown, preserving structural elements like tables and definition lists. Recommended as the default tool for web content extraction when a clean, readable text format is needed while maintaining document structure.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesURL of the web page to convert to Markdown format, supporting various HTML elements and structures.

Implementation Reference

  • src/index.ts:82-95 (registration)
    Registration of the get_markdown tool in the list of tools, including its name, description, and input schema.
    {
      name: "get_markdown",
      description: "Converts web page content to well-formatted Markdown, preserving structural elements like tables and definition lists. Recommended as the default tool for web content extraction when a clean, readable text format is needed while maintaining document structure.",
      inputSchema: {
        type: "object",
        properties: {
          url: {
            type: "string",
            description: "URL of the web page to convert to Markdown format, supporting various HTML elements and structures."
          }
        },
        required: ["url"]
      }
    },
  • Input schema definition for the get_markdown tool.
    inputSchema: {
      type: "object",
      properties: {
        url: {
          type: "string",
          description: "URL of the web page to convert to Markdown format, supporting various HTML elements and structures."
        }
      },
      required: ["url"]
    }
  • Handler logic for the get_markdown tool within the CallToolRequestSchema handler. Fetches rendered HTML and converts it to Markdown using getMarkdownStringFromHtmlByNHM.
    case "get_markdown": {
      return {
        content: [{
          type: "text",
          text: (await getMarkdownStringFromHtmlByNHM(url))
        }]
      };
    }
  • Core helper function that converts fetched HTML to Markdown using NodeHtmlMarkdown library with custom translators for dl, dt, dd elements and optional main content filtering.
    export async function getMarkdownStringFromHtmlByNHM(
      request_url: string,
      mainOnly: boolean = false,
    ) {
      const htmlString = await getHtmlString(request_url);
    
      const customTranslators: TranslatorConfigObject = {
        dl: () => ({
          preserveWhitespace: false,
          surroundingNewlines: true,
        }),
        dt: () => ({
          prefix: '**',
          postfix: ':** ',
          surroundingNewlines: false,
        }),
        dd: () => ({
          postfix: '\n',
          surroundingNewlines: false,
        }),
        Head: () => ({
          postfix: '\n',
          ignore: false,
          postprocess: (ctx) => {
            const titleNode = ctx.node.querySelector('title');
            if (titleNode) {
              return titleNode.textContent || '';
            }
            return '';
          },
          surroundingNewlines: true,
        }),
      };
    
      if (mainOnly) {
        customTranslators.Header = () => ({
          ignore: true,
        });
        customTranslators.Footer = () => ({
          ignore: true,
        });
        customTranslators.Nav = () => ({
          ignore: true,
        });
      }
    
      const markdownString = NodeHtmlMarkdown.translate(
        htmlString,
        {},
        customTranslators,
      );
    
      return markdownString;
    }
  • Supporting helper that launches a headless Chromium browser to fetch fully rendered HTML content from the URL, which is then passed to the markdown converter.
    async function getHtmlString(request_url: string): Promise<string> {
      let browser: Browser | null = null;
      let page: Page | null = null;
      try {
        browser = await chromium.launch({
          headless: true,
          // args: ['--single-process'], 
        });
        const context = await browser.newContext();
        page = await context.newPage();
    
        await page.goto(request_url, {
          waitUntil: 'domcontentloaded',
          timeout: TIMEOUT,
        });
        const htmlString = await page.content();
        return htmlString;
      } catch (error) {
        console.error(`Failed to fetch HTML for ${request_url}:`, error);
        return ""; 
      } finally {
        if (page) {
          try {
            await page.close();
          } catch (e) {
            console.error("Error closing page:", e);
          }
        }
        if (browser) {
          try {
            await browser.close();
          } catch (error) {
            console.error('Error closing browser:', error);
          }
        }
      }
    }
Behavior3/5

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

No annotations are provided, so the description carries full burden. It discloses key behavioral traits: conversion to Markdown, preservation of structural elements, and suitability as a default extraction tool. However, it lacks details on error handling, performance characteristics, or limitations (e.g., URL accessibility, content size). The description adds value but is incomplete for full 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 appropriately sized and front-loaded, with two sentences that efficiently convey purpose and usage guidelines. Every sentence earns its place by defining the tool's function and providing contextual recommendations without unnecessary details.

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

Completeness4/5

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

Given the tool's moderate complexity (single parameter, no output schema, no annotations), the description is mostly complete. It covers purpose, usage context, and key behavioral aspects. However, it lacks explicit mention of output format details or potential limitations, leaving some gaps in full context for an agent.

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 the single parameter 'url' well-documented in the schema. The description adds no specific parameter semantics beyond what the schema provides, but it implies the URL should point to a web page with content convertible to Markdown. Baseline 3 is appropriate as the schema handles parameter documentation adequately.

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?

The description clearly states the specific action ('Converts web page content to well-formatted Markdown') and resource ('web page'), distinguishing it from siblings by emphasizing preservation of structural elements like tables and definition lists. It explicitly contrasts with other tools by positioning itself as the default for clean, readable text format extraction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance on when to use this tool ('Recommended as the default tool for web content extraction when a clean, readable text format is needed while maintaining document structure'), implying alternatives through sibling tool names (get_markdown_summary, get_raw_text, get_rendered_html) and specifying the context of needing structured, readable output.

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/tatn/mcp-server-fetch-typescript'

If you have feedback or need assistance with the MCP directory API, please join our Discord server