Skip to main content
Glama
jumasheff

RAG Documentation MCP Server

by jumasheff

extract_urls

Extract and analyze all URLs from a webpage to discover related documentation pages, API references, or build a documentation graph. Handles various URL formats and validates links during extraction.

Instructions

Extract and analyze all URLs from a given web page. This tool crawls the specified webpage, identifies all hyperlinks, and optionally adds them to the processing queue. Useful for discovering related documentation pages, API references, or building a documentation graph. Handles various URL formats and validates links before extraction.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesThe complete URL of the webpage to analyze (must include protocol, e.g., https://). The page must be publicly accessible.
add_to_queueNoIf true, automatically add extracted URLs to the processing queue for later indexing. This enables recursive documentation discovery. Use with caution on large sites to avoid excessive queuing.

Implementation Reference

  • The ExtractUrlsHandler class implements the core execution logic for the 'extract_urls' tool. It uses browser automation to load the page, cheerio to parse HTML, extracts and filters links based on base path (e.g., for documentation sections), and optionally appends them to a queue file.
    export class ExtractUrlsHandler extends BaseHandler {
      async handle(args: any): Promise<McpToolResponse> {
        if (!args.url || typeof args.url !== 'string') {
          throw new McpError(ErrorCode.InvalidParams, 'URL is required');
        }
    
        await this.apiClient.initBrowser();
        const page = await this.apiClient.browser.newPage();
    
        try {
          const baseUrl = new URL(args.url);
          const basePath = baseUrl.pathname.split('/').slice(0, 3).join('/'); // Get the base path (e.g., /3/ for Python docs)
    
          await page.goto(args.url, { waitUntil: 'networkidle' });
          const content = await page.content();
          const $ = cheerio.load(content);
          const urls = new Set<string>();
    
          $('a[href]').each((_, element) => {
            const href = $(element).attr('href');
            if (href) {
              try {
                const url = new URL(href, args.url);
                // Only include URLs from the same documentation section
                if (url.hostname === baseUrl.hostname && 
                    url.pathname.startsWith(basePath) && 
                    !url.hash && 
                    !url.href.endsWith('#')) {
                  urls.add(url.href);
                }
              } catch (e) {
                // Ignore invalid URLs
              }
            }
          });
    
          const urlArray = Array.from(urls);
    
          if (args.add_to_queue) {
            try {
              // Ensure queue file exists
              try {
                await fs.access(QUEUE_FILE);
              } catch {
                await fs.writeFile(QUEUE_FILE, '');
              }
    
              // Append URLs to queue
              const urlsToAdd = urlArray.join('\n') + (urlArray.length > 0 ? '\n' : '');
              await fs.appendFile(QUEUE_FILE, urlsToAdd);
    
              return {
                content: [
                  {
                    type: 'text',
                    text: `Successfully added ${urlArray.length} URLs to the queue`,
                  },
                ],
              };
            } catch (error) {
              return {
                content: [
                  {
                    type: 'text',
                    text: `Failed to add URLs to queue: ${error}`,
                  },
                ],
                isError: true,
              };
            }
          }
    
          return {
            content: [
              {
                type: 'text',
                text: urlArray.join('\n') || 'No URLs found on this page.',
              },
            ],
          };
        } catch (error) {
          return {
            content: [
              {
                type: 'text',
                text: `Failed to extract URLs: ${error}`,
              },
            ],
            isError: true,
          };
        } finally {
          await page.close();
        }
      }
    }
  • The tool definition including name, description, and input schema (url required string, add_to_queue optional boolean) used when listing tools via MCP protocol.
    {
      name: 'extract_urls',
      description: 'Extract and analyze all URLs from a given web page. This tool crawls the specified webpage, identifies all hyperlinks, and optionally adds them to the processing queue. Useful for discovering related documentation pages, API references, or building a documentation graph. Handles various URL formats and validates links before extraction.',
      inputSchema: {
        type: 'object',
        properties: {
          url: {
            type: 'string',
            description: 'The complete URL of the webpage to analyze (must include protocol, e.g., https://). The page must be publicly accessible.',
          },
          add_to_queue: {
            type: 'boolean',
            description: 'If true, automatically add extracted URLs to the processing queue for later indexing. This enables recursive documentation discovery. Use with caution on large sites to avoid excessive queuing.',
            default: false,
          },
        },
        required: ['url'],
      },
    } as ToolDefinition,
  • Registers the ExtractUrlsHandler instance in the handlers Map under the key 'extract_urls' during setup.
    this.handlers.set('extract_urls', new ExtractUrlsHandler(this.server, this.apiClient));
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key behaviors: crawling webpages, identifying hyperlinks, optional queue addition with a caution note for large sites, handling various URL formats, and link validation. This covers mutation aspects (queue addition) and operational constraints, though it could mention performance or rate limits more explicitly.

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

Conciseness5/5

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

The description is appropriately sized and front-loaded, with the core purpose stated first. Each sentence adds value: the first defines the action, the second explains optional queue behavior, the third gives usage context, and the fourth covers technical handling. There is no wasted text, and the structure flows logically from general to specific details.

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

Completeness4/5

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

Given the tool's moderate complexity (2 parameters, no output schema, no annotations), the description is largely complete. It covers purpose, usage, behaviors, and parameters adequately. However, it could be more explicit about output (e.g., what the analysis returns) since there is no output schema, and it lacks details on error handling or authentication needs, leaving minor gaps in full contextual understanding.

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%, so the schema already documents both parameters thoroughly. The description adds marginal value by implying the 'url' parameter is for webpage analysis and hinting at the 'add_to_queue' parameter's purpose ('optionally adds them to the processing queue'), but it does not provide additional syntax or format details beyond what the schema specifies. Baseline 3 is appropriate when the schema does the heavy lifting.

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

Purpose5/5

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

The description clearly states the specific action ('extract and analyze all URLs') and resource ('from a given web page'), distinguishing it from sibling tools like clear_queue or search_documentation. It explicitly mentions the tool's scope (crawling, identifying hyperlinks, handling URL formats, validating links), which goes beyond a simple tautology of the name.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool ('useful for discovering related documentation pages, API references, or building a documentation graph'), but it does not explicitly state when not to use it or name specific alternatives among sibling tools. The guidance is helpful but lacks explicit exclusions or comparisons to tools like list_sources or run_queue.

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/jumasheff/mcp-ragdoc-fork'

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