Skip to main content
Glama

fetch_markdown

Convert web content into Markdown format by fetching a URL. Specify optional headers, character limits, or start indices for tailored content extraction.

Instructions

Fetch a website and return the content as Markdown

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
headersNoOptional headers to include in the request
max_lengthNoMaximum number of characters to return (default: 5000)
start_indexNoStart content from this character index (default: 0)
urlYesURL of the website to fetch

Implementation Reference

  • Core implementation of the fetch_markdown tool: fetches HTML from the URL, converts it to Markdown using TurndownService, applies configurable length limits, and returns the markdown content or an error message.
    static async markdown(requestPayload: RequestPayload) { try { const response = await this._fetch(requestPayload); const html = await response.text(); const turndownService = new TurndownService(); let markdown = turndownService.turndown(html); // Apply length limits markdown = this.applyLengthLimits( markdown, requestPayload.max_length ?? 5000, requestPayload.start_index ?? 0 ); return { content: [{ type: "text", text: markdown }], isError: false }; } catch (error) { return { content: [{ type: "text", text: (error as Error).message }], isError: true, }; } }
  • src/index.ts:56-81 (registration)
    Tool registration in the ListTools response, defining the name, description, and input schema for fetch_markdown.
    { name: "fetch_markdown", description: "Fetch a website and return its contents converted content to Markdown", inputSchema: { type: "object", properties: { url: { type: "string", description: "URL of the website to fetch", }, headers: { type: "object", description: "Optional headers to include in the request", }, max_length: { type: "number", description: `Maximum number of characters to return (default: ${downloadLimit}})`, }, start_index: { type: "number", description: "Start content from this character index (default: 0)", }, }, required: ["url"], }, },
  • Dispatch handler in CallToolRequest that routes requests for 'fetch_markdown' to the Fetcher.markdown implementation.
    if (request.params.name === "fetch_markdown") { const fetchResult = await Fetcher.markdown(validatedArgs); return fetchResult; }
  • Zod schema for validating the input parameters (url, headers, max_length, start_index) used across all fetch tools including fetch_markdown.
    export const RequestPayloadSchema = z.object({ url: z.string().url(), headers: z.record(z.string()).optional(), max_length: z.number().int().min(0).optional().default(downloadLimit), start_index: z.number().int().min(0).optional().default(0), });
  • Shared helper method for performing the HTTP fetch with private IP blocking for security and custom headers.
    private static async _fetch({ url, headers, }: RequestPayload): Promise<Response> { try { if (is_ip_private(url)) { throw new Error( `Fetcher blocked an attempt to fetch a private IP ${url}. This is to prevent a security vulnerability where a local MCP could fetch privileged local IPs and exfiltrate data.`, ); } const response = await fetch(url, { headers: { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", ...headers, }, }); if (!response.ok) { throw new Error(`HTTP error: ${response.status}`); } return response; } catch (e: unknown) { if (e instanceof Error) { throw new Error(`Failed to fetch ${url}: ${e.message}`); } else { throw new Error(`Failed to fetch ${url}: Unknown error`); } } }

Other Tools

Related 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/zcaceres/fetch-mcp'

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