Skip to main content
Glama
code-alchemist01

Development Tools MCP Server

scrape_by_selector

Extract specific webpage content using CSS selectors for static or dynamic elements to support development workflows.

Instructions

Scrape content using CSS selector

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesURL to scrape
selectorYesCSS selector
useBrowserNoUse browser for dynamic content

Implementation Reference

  • Core handler function that fetches the HTML using axios, parses it with cheerio, and extracts trimmed text from all elements matching the CSS selector.
    async scrapeBySelector(config: ScrapingConfig, selector: string): Promise<string[]> {
      if (!Validators.isValidSelector(selector)) {
        throw new Error('Invalid CSS selector');
      }
    
      const validation = Validators.validateScrapingConfig(config);
      if (!validation.valid) {
        throw new Error(`Invalid scraping config: ${validation.errors.join(', ')}`);
      }
    
      try {
        const response = await axios.get(config.url, {
          headers: config.headers || {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
          },
          timeout: config.timeout || 30000,
        });
    
        const $ = cheerio.load(response.data);
        const results: string[] = [];
    
        $(selector).each((_, element) => {
          const text = $(element).text().trim();
          if (text) {
            results.push(text);
          }
        });
    
        return results;
      } catch (error) {
        throw new Error(`Failed to scrape: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • Registers the 'scrape_by_selector' tool in the webScrapingTools array, including name, description, and input schema.
    {
      name: 'scrape_by_selector',
      description: 'Scrape content using CSS selector',
      inputSchema: {
        type: 'object',
        properties: {
          url: {
            type: 'string',
            description: 'URL to scrape',
          },
          selector: {
            type: 'string',
            description: 'CSS selector',
          },
          useBrowser: {
            type: 'boolean',
            description: 'Use browser for dynamic content',
            default: false,
          },
        },
        required: ['url', 'selector'],
      },
    },
  • Tool handler case in handleWebScrapingTool that dispatches to staticScraper.scrapeBySelector for non-browser scraping or returns a stub for browser mode.
    case 'scrape_by_selector': {
      const selector = params.selector as string;
      if (config.useBrowser) {
        // For browser, we'd need to use page.evaluate
        await dynamicScraper.scrapeDynamicContent(config);
        // Simplified - would extract by selector in real implementation
        return { message: 'Selector extraction with browser requires page.evaluate', selector };
      } else {
        return await staticScraper.scrapeBySelector(config, selector);
      }
    }
  • JSON schema defining the input parameters for the scrape_by_selector tool.
    inputSchema: {
      type: 'object',
      properties: {
        url: {
          type: 'string',
          description: 'URL to scrape',
        },
        selector: {
          type: 'string',
          description: 'CSS selector',
        },
        useBrowser: {
          type: 'boolean',
          description: 'Use browser for dynamic content',
          default: false,
        },
      },
      required: ['url', 'selector'],
    },
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions the action ('scrape') but doesn't specify what happens—e.g., whether it returns text, HTML, or structured data, if it handles errors, requires authentication, or has rate limits. This leaves significant gaps for an agent to understand the tool's behavior.

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 a single, efficient sentence with no wasted words. It is front-loaded with the core purpose, making it easy to parse quickly, though it could benefit from more detail given the lack of annotations and output schema.

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?

Given the complexity of a scraping tool with no annotations, no output schema, and multiple parameters, the description is incomplete. It doesn't explain what the tool returns, how errors are handled, or any behavioral nuances, leaving the agent with insufficient context for reliable use.

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 fully documents the parameters (url, selector, useBrowser). The description adds no additional meaning beyond the schema, such as explaining selector syntax or useBrowser implications. Baseline 3 is appropriate when the schema does all the work.

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 clearly states the action ('scrape content') and the method ('using CSS selector'), which is specific and distinguishes it from generic scraping tools. However, it doesn't explicitly differentiate from sibling tools like 'scrape_html' or 'scrape_dynamic_content', which likely have overlapping purposes but different approaches.

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?

The description provides no guidance on when to use this tool versus alternatives. With sibling tools like 'scrape_dynamic_content' and 'scrape_html' available, there is no indication of scenarios where CSS selector-based scraping is preferred or when other methods might be more appropriate.

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/code-alchemist01/development-tools-mcp-Server'

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