Skip to main content
Glama
tatn

MCP Server Fetch TypeScript

by tatn

get_rendered_html

Fetch fully rendered HTML content from web pages requiring JavaScript execution, including single-page applications and dynamic content.

Instructions

Fetches fully rendered HTML content using a headless browser, including JavaScript-generated content. Essential for modern web applications, single-page applications (SPAs), or any content that requires client-side rendering to be complete.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesURL of the target web page that requires JavaScript execution or dynamic content rendering.

Implementation Reference

  • src/index.ts:68-81 (registration)
    Registers the get_rendered_html tool with its description and input schema (requires 'url').
    {
      name: "get_rendered_html",
      description: "Fetches fully rendered HTML content using a headless browser, including JavaScript-generated content. Essential for modern web applications, single-page applications (SPAs), or any content that requires client-side rendering to be complete.",
      inputSchema: {
        type: "object",
        properties: {
          url: {
            type: "string",
            description: "URL of the target web page that requires JavaScript execution or dynamic content rendering."
          }
        },
        required: ["url"]
      }
    },
  • Tool handler case in CallToolRequestSchema that fetches rendered HTML via getHtmlString and returns it as text content.
    case "get_rendered_html": {
      return {
        content: [{
          type: "text",
          text: (await getHtmlString(url))
        }]
      };
    }
  • Executes the tool logic: launches headless Chromium browser with Playwright, navigates to URL, waits for DOM content loaded, retrieves full HTML content, handles errors and cleanup.
    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);
          }
        }
      }
    }
  • Input schema defining the required 'url' parameter as a string.
    inputSchema: {
      type: "object",
      properties: {
        url: {
          type: "string",
          description: "URL of the target web page that requires JavaScript execution or dynamic content rendering."
        }
      },
      required: ["url"]
    }

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