Skip to main content
Glama
dazeb

Markdown Downloader

download_markdown

Convert webpages to markdown files by providing a URL, with options to save in a specified subdirectory and generate date-stamped filenames automatically.

Instructions

Download a webpage as markdown using r.jina.ai

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
subdirectoryNoOptional subdirectory to save the file in
urlYesURL of the webpage to download

Implementation Reference

  • The execution handler for the 'download_markdown' tool. Validates URL input, prepends r.jina.ai, downloads markdown with axios, generates a sanitized filename with date, saves to configurable directory (optionally subdirectory), and returns success/error message.
    if (request.params.name === 'download_markdown') {
      const url = request.params.arguments?.url;
      const subdirectory = request.params.arguments?.subdirectory;
    
      if (!url || typeof url !== 'string') {
        throw new McpError(
          ErrorCode.InvalidParams,
          'A valid URL must be provided'
        );
      }
    
      try {
        // Get current download directory
        const config = getConfig();
    
        // Prepend r.jina.ai to the URL
        const jinaUrl = `https://r.jina.ai/${url}`;
    
        // Download markdown
        const response = await axios.get(jinaUrl, {
          headers: {
            'Accept': 'text/markdown'
          }
        });
    
        // Generate filename
        const filename = generateFilename(url);
        let filepath = path.join(config.downloadDirectory, filename);
    
        // If subdirectory is specified, use it
        if (subdirectory && typeof subdirectory === 'string') {
          filepath = path.join(config.downloadDirectory, subdirectory, filename);
          fs.ensureDirSync(path.dirname(filepath));
        }
    
        // Save markdown file
        await fs.writeFile(filepath, response.data);
    
        return {
          content: [
            {
              type: 'text',
              text: `Markdown downloaded and saved as ${filename} in ${path.dirname(filepath)}`
            }
          ]
        };
      } catch (downloadError) {
        console.error('Download error:', downloadError);
        return {
          content: [
            {
              type: 'text',
              text: `Failed to download markdown: ${downloadError instanceof Error ? downloadError.message : 'Unknown error'}`
            }
          ],
          isError: true
        };
      }
    }
  • src/index.ts:115-131 (registration)
    Registration of the 'download_markdown' tool in the ListTools response, including its description and input schema definition.
      name: 'download_markdown',
      description: 'Download a webpage as markdown using r.jina.ai',
      inputSchema: {
        type: 'object',
        properties: {
          url: {
            type: 'string',
            description: 'URL of the webpage to download'
          },
          subdirectory: {
            type: 'string',
            description: 'Optional subdirectory to save the file in'
          }
        },
        required: ['url']
      }
    },
  • Input schema definition for the 'download_markdown' tool, specifying required 'url' and optional 'subdirectory'.
    inputSchema: {
      type: 'object',
      properties: {
        url: {
          type: 'string',
          description: 'URL of the webpage to download'
        },
        subdirectory: {
          type: 'string',
          description: 'Optional subdirectory to save the file in'
        }
      },
      required: ['url']
    }
  • Helper function to generate a sanitized filename from the URL with a datestamp suffix for the markdown file.
    function generateFilename(url: string): string {
      const sanitizedUrl = sanitizeFilename(url);
      const datestamp = new Date().toISOString().split('T')[0].replace(/-/g, '');
      return `${sanitizedUrl}-${datestamp}.md`;
    }
  • Helper function to sanitize URL into a valid filename by removing protocol and replacing special chars.
    function sanitizeFilename(url: string): string {
      // Remove protocol, replace non-alphanumeric chars with dash
      return url
        .replace(/^https?:\/\//, '')
        .replace(/[^a-z0-9]/gi, '-')
        .toLowerCase();
    }
Install Server

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/dazeb/markdown-downloader'

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