Skip to main content
Glama

crawl_docs

Crawls enabled documentation sources, optionally forcing a full re-crawl to ignore previous crawl records.

Instructions

Start crawling enabled docs

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
forceNoWhether to force re-crawl all docs, ignoring previous crawl records

Implementation Reference

  • The crawlAndSaveDocs function that executes the crawl logic for 'crawl_docs'. It iterates over enabled docs, uses Puppeteer to navigate to each doc's crawlerStart URL, extracts all links matching the crawlerPrefix, scrapes content from each page (converting to Markdown), and saves them as .md files.
    async function crawlAndSaveDocs(force: boolean = false): Promise<void> {
      await fs.ensureDir(docDir);
      console.error('========== START CRAWLING ==========');
      for (const doc of docs) {
        if (!docConfig[doc.name]) {
          console.error(`Skipping doc ${doc.name} - not enabled`);
          continue;
        }
    
        // Skip if already crawled and not forcing re-crawl
        if (!force && await fs.pathExists(configPath)) {
          const config = await fs.readJson(configPath);
          if (config.crawledDocs && config.crawledDocs[doc.name]) {
            console.error(`Skipping doc ${doc.name} - already crawled at ${config.crawledDocs[doc.name]}`);
            continue;
          }
        }
    
        try {
          // Create doc directory - FIX: use the correct path from docDir parameter
          const docDirPath = path.join(docDir, doc.name);
          await fs.ensureDir(docDirPath);
    
          // Launch browser and open new page
          const browser = await puppeteer.launch({
            // WSL-friendly options to avoid GPU issues
            args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-gpu'],
            headless: true
          });
          
          try {
            const page = await browser.newPage();
            
            // Navigate to start page
            console.error(`Processing doc: ${doc.name}`);
            console.error(`Crawler start: ${doc.crawlerStart}, Crawler prefix: ${doc.crawlerPrefix}`);
            await page.goto(doc.crawlerStart, { waitUntil: 'networkidle2' });
    
            // Extract all links
            const links = Array.from(new Set(
              await page.evaluate((prefix) => {
                const anchors = Array.from(document.querySelectorAll('a[href]'));
                return anchors
                  .map(a => {
                    const href = a.getAttribute('href');
                    if (!href) return null;
                    try {
                      const url = new URL(href, window.location.origin);
                      return url.toString();
                    } catch (error) {
                      console.error(`Failed to parse href ${href}:`, error);
                      return null;
                    }
                  })
                  .filter(link => link && link.startsWith(prefix));
              }, doc.crawlerPrefix)
            ));
    
            if (links.length > 0) {
              console.error(`Found ${links.length} valid links to process`);
              
              for (const link of links) {
                if (!link) continue;
                
                try {
                  console.log(`Processing link: ${link}`);
                  const newPage = await browser.newPage();
                  await newPage.goto(link, { waitUntil: 'networkidle2' });
                  // Extract content as Markdown
                  const content = await newPage.evaluate(() => {
                    // Get page title
                    const title = document.title;
                    
                    // Find main content element
                    const main = document.querySelector('main') ||
                               document.querySelector('article') ||
                               document.querySelector('.main-content') ||
                               document.body;
    
                    // Convert content to Markdown
                    let markdown = `# ${title}\n\n`;
                    
                    // Convert headings
                    main.querySelectorAll('h1, h2, h3, h4, h5, h6').forEach(heading => {
                      const level = parseInt(heading.tagName[1]);
                      const text = heading.textContent?.trim();
                      if (text) {
                        markdown += '#'.repeat(level) + ' ' + text + '\n\n';
                      }
                    });
    
                    // Convert paragraphs
                    main.querySelectorAll('p').forEach(p => {
                      const text = p.textContent?.trim();
                      if (text) {
                        markdown += text + '\n\n';
                      }
                    });
    
                    // Convert code blocks
                    main.querySelectorAll('pre').forEach(pre => {
                      const text = pre.textContent?.trim();
                      if (text) {
                        markdown += '```\n' + text + '\n```\n\n';
                      }
                    });
    
                    // Convert lists
                    main.querySelectorAll('ul, ol').forEach(list => {
                      const isOrdered = list.tagName === 'OL';
                      list.querySelectorAll('li').forEach((li, index) => {
                        const text = li.textContent?.trim();
                        if (text) {
                          markdown += isOrdered ? `${index + 1}. ` : '- ';
                          markdown += text + '\n';
                        }
                      });
                      markdown += '\n';
                    });
    
                    return markdown.trim();
                  });
                  await newPage.close();
                  
                  // Save Markdown file
                  // Create safe file name from URL path
                  const url = new URL(link);
                  const pathParts = url.pathname.split('/').filter(part => part.length > 0);
                  let fileName = pathParts.join('_');
                  
                  // Add extension if not present
                  if (!fileName.endsWith('.md')) {
                    fileName += '.md';
                  }
                  // FIX: Use docDirPath instead of docDir
                  const filePath = path.join(docDirPath, fileName);
                  await fs.writeFile(filePath, content);
                  console.log(`Successfully saved ${filePath}`);
                  await updateCrawledDoc(doc.name);
                } catch (error) {
                  console.error(`Failed to process page ${link}:`, error);
                }
              }
            } else {
              console.error('No valid links found');
            }
          } finally {
            await browser.close();
          }
        } catch (error) {
          console.error(`Failed to process doc ${doc.name}:`, error);
        }
      }
    }
  • src/index.ts:435-447 (registration)
    Tool registration for 'crawl_docs' in the ListToolsRequestSchema handler. Defines name, description, and inputSchema (with optional 'force' boolean parameter).
    {
      name: "crawl_docs",
      description: "Start crawling enabled docs",
      inputSchema: {
        type: "object",
        properties: {
          force: {
            type: "boolean",
            description: "Whether to force re-crawl all docs, ignoring previous crawl records"
          }
        }
      }
    },
  • The switch case handler for 'crawl_docs' in the CallToolRequestSchema handler. Extracts the 'force' argument and calls crawlAndSaveDocs(force).
    case "crawl_docs": {
      const force = Boolean(request.params.arguments?.force);
      await crawlAndSaveDocs(force);
      return {
        content: [{
          type: "text",
          text: "Crawling completed"
        }]
      };
    }
Behavior2/5

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

No annotations are provided, so the description must carry the full burden. It simply says 'start crawling' without disclosing behavioral traits such as whether it is destructive, how long it takes, or if it modifies data beyond crawl records.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence with no wasted words, front-loading the action. It is appropriately sized but could include more detail without becoming verbose.

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

Completeness2/5

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

For a tool with one parameter and no output schema, the description is incomplete. It does not explain the crawling process, side effects, return values, or prerequisites like whether docs must be enabled first.

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% for the single parameter 'force'. The description adds no additional meaning beyond the schema's description of the force parameter. Baseline 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Start crawling enabled docs' clearly states the verb (Start crawling) and resource (enabled docs), specifying the scope. However, it does not differentiate from sibling tools like search_docs or list_enabled_docs, which could be confused.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives like build_index or search_docs. There are no exclusions or prerequisites mentioned.

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/askme765cs/open-docs-mcp'

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