Skip to main content
Glama

fetch_markdown

Convert website content into Markdown format by specifying a URL. Use optional headers to customize the request for streamlined content retrieval and integration.

Instructions

Fetch a website and return the content as Markdown

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
headersNoOptional headers to include in the request
urlYesURL of the website to fetch

Implementation Reference

  • The core handler function for the 'fetch_markdown' tool. Fetches HTML from the given URL and converts it to Markdown using TurndownService, returning the content or error.
    static async markdown(requestPayload: RequestPayload) { try { const response = await this._fetch(requestPayload); const html = await response.text(); const turndownService = new TurndownService(); const markdown = turndownService.turndown(html); return { content: [{ type: "text", text: markdown }], isError: false }; } catch (error) { return { content: [{ type: "text", text: (error as Error).message }], isError: true, }; } }
  • src/index.ts:47-63 (registration)
    Registers the 'fetch_markdown' tool in the ListTools handler, providing name, description, and input schema.
    name: "fetch_markdown", description: "Fetch a website and return the content as 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", }, }, required: ["url"], }, },
  • Zod schema used to validate the input arguments for the 'fetch_markdown' tool (and others) before calling the handler.
    export const RequestPayloadSchema = z.object({ url: z.string().url(), headers: z.record(z.string()).optional(), });
  • Dispatches 'fetch_markdown' tool calls to the Fetcher.markdown implementation in the CallToolRequestSchema handler.
    if (request.params.name === "fetch_markdown") { const fetchResult = await Fetcher.markdown(validatedArgs); return fetchResult; }
  • Shared helper method for performing the HTTP fetch request with custom headers and error handling, used by all fetch tools including fetch_markdown.
    private static async _fetch({ url, headers, }: RequestPayload): Promise<Response> { try { 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/tokenizin/mcp-npx-fetch'

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