Skip to main content
Glama

get_webpage_source

Fetch raw HTML source code and page information from any webpage by providing a valid URL. This tool enables web scraping and content extraction without requiring official APIs.

Instructions

Fetch the raw HTML source code and page information of a webpage.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesThe URL of the webpage to get source from. Must be a valid HTTP/HTTPS link.

Implementation Reference

  • The main handler function for the 'get_webpage_source' tool. Validates the input URL, imports and calls the SearchService to scrape the webpage, and returns structured data including title, description, keywords, extracted text content, links, and timestamp.
    async function handleGetWebpageSource(args) {
      const { url } = args;
      
      if (!url || typeof url !== 'string') {
        throw new Error('URL parameter is required and must be a string');
      }
    
      try {
        new URL(url);
      } catch (error) {
        throw new Error('Invalid URL format');
      }
    
      const searchService = (await import('../services/searchService.js')).default;
      const result = await searchService.scrapeWebpage(url);
    
      return {
        tool: 'get_webpage_source',
        url,
        title: result.title,
        description: result.description,
        keywords: result.keywords,
        content: result.content,
        links: result.links,
        timestamp: result.timestamp
      };
    }
  • Input schema definition for the 'get_webpage_source' tool, specifying the required 'url' parameter as a string.
      name: 'get_webpage_source',
      description: 'Fetch the raw HTML source code and page information of a webpage.',
      inputSchema: {
        type: 'object',
        properties: {
          url: {
            type: 'string',
            description: 'The URL of the webpage to get source from. Must be a valid HTTP/HTTPS link.'
          }
        },
        required: ['url']
      }
    },
  • Tool dispatch/registration in the CallToolRequestSchema handler switch statement, routing calls to 'get_webpage_source' to the handleGetWebpageSource function.
    case 'get_webpage_source':
      result = await handleGetWebpageSource(args);
      break;
  • Supporting utility method in SearchService class that fetches raw HTML with axios, parses with cheerio, extracts title, meta tags, truncated body text, and links. Called by the tool handler to perform the actual scraping.
    async scrapeWebpage(url) {
      try {
        const response = await axios.get(url, {
          headers: {
            'User-Agent': this.getRandomUserAgent(),
            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
            'Accept-Language': 'en-US,en;q=0.5',
            'Accept-Encoding': 'gzip, deflate',
            'Connection': 'keep-alive'
          },
          timeout: 15000
        });
    
        const $ = cheerio.load(response.data);
    
        // Extract page info
        const title = $('title').text().trim();
        const description = $('meta[name="description"]').attr('content') || '';
        const keywords = $('meta[name="keywords"]').attr('content') || '';
    
        // Extract main content
        const content = $('body').text()
          .replace(/\s+/g, ' ')
          .trim()
          .substring(0, 2000); // limit content length
    
        // Extract links
        const links = [];
        $('a[href]').each((index, element) => {
          if (index < 50) { // limit number of links
            const href = $(element).attr('href');
            const text = $(element).text().trim();
            if (href && text && href.startsWith('http')) {
              links.push({ url: href, text });
            }
          }
        });
    
        logger.info(`Webpage scraped successfully: ${url}`);
    
        return {
          url,
          title,
          description,
          keywords,
          content,
          links,
          timestamp: new Date().toISOString()
        };
    
      } catch (error) {
        logger.error(`Webpage scraping error for ${url}:`, error);
        throw new Error(`Failed to scrape webpage: ${error.message}`);
      }
    }
  • Registration for listing tools via ListToolsRequestSchema, which returns the tools array including 'get_webpage_source' schema from generateTools().
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: generateTools()
      };
    });
Behavior2/5

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

With no annotations provided, the description carries full burden but lacks behavioral details. It doesn't mention error handling, timeouts, authentication needs, rate limits, or what 'page information' includes. The description is minimal beyond the basic operation.

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?

Single sentence, front-loaded with the core purpose, zero wasted words. Every part of the description earns its place by specifying what's fetched and from where.

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

Completeness3/5

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

For a simple single-parameter tool with no annotations and no output schema, the description is minimally adequate. It covers the basic purpose but lacks details about return format, error conditions, or behavioral traits that would help an agent use it effectively.

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 the single 'url' parameter thoroughly. The description adds no additional parameter context beyond what's in the schema, meeting the baseline for high schema coverage.

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 ('Fetch'), resource ('raw HTML source code and page information'), and target ('webpage'). It distinguishes from potential siblings by specifying 'raw HTML source code' rather than processed content or search results.

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 explicit guidance on when to use this tool versus alternatives like 'get_webpage_content' or 'batch_webpage_scrape'. The description implies it's for raw source code, but doesn't clarify use cases or exclusions compared to siblings.

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/yc9yc/spider-mcp'

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