Skip to main content
Glama

web_fetch

Retrieve and clean web page content for AI analysis and operational tasks, enabling secure access to online information within developer workflows.

Instructions

Получить содержимое веб-страницы

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesURL страницы

Implementation Reference

  • Core handler implementing web_fetch: fetches URL with axios, parses HTML using cheerio, extracts title, clean text, and links, with host validation.
    async fetchPage(url: string): Promise<WebPage> {
      try {
        console.log(`🌐 Получение страницы: ${url}`);
        
        // Проверяем разрешенные хосты
        this.validateUrl(url);
        
        // Получаем страницу
        const response = await axios.get(url, {
          headers: {
            'User-Agent': this.userAgent,
          },
          timeout: 10000, // 10 секунд таймаут
        });
        
        // Парсим HTML
        const $ = cheerio.load(response.data);
        
        // Извлекаем основную информацию
        const title = $('title').first().text().trim() || 'Без заголовка';
        
        // Убираем скрипты, стили и другие ненужные элементы
        $('script, style, noscript, iframe, img, svg').remove();
        
        // Получаем чистый текст
        const text = $('body').text()
          .replace(/\s+/g, ' ')
          .trim();
        
        // Получаем ссылки
        const links = $('a[href]')
          .map((_, el) => $(el).attr('href'))
          .get()
          .filter(href => href && href.startsWith('http'))
          .slice(0, 20); // Ограничиваем количество ссылок
        
        const page: WebPage = {
          url,
          title,
          content: response.data,
          text: text.substring(0, 5000), // Ограничиваем размер текста
          links,
        };
        
        console.log(`✅ Страница получена: ${title} (${text.length} символов, ${links.length} ссылок)`);
        
        return page;
      } catch (error) {
        console.error('Ошибка получения страницы:', error);
        throw new Error(`Ошибка получения страницы: ${error}`);
      }
    }
  • Output schema/interface for the web page data returned by the handler.
    export interface WebPage {
      url: string;
      title: string;
      content: string;
      text: string;
      links: string[];
    }
  • src/server.ts:118-131 (registration)
    Registration of web_fetch tool in MCP server's ListTools handler, including name, description, and input schema.
    {
      name: 'web_fetch',
      description: 'Получить содержимое веб-страницы',
      inputSchema: {
        type: 'object',
        properties: {
          url: {
            type: 'string',
            description: 'URL страницы',
          },
        },
        required: ['url'],
      },
    },
  • Dispatch handler in main MCP server CallToolRequestSchema that invokes WebService.fetchPage.
    case 'web_fetch':
      return {
        content: await this.webService.fetchPage(args.url as string)
      };
  • Registration of web_fetch tool in HTTP transport's /tools endpoint.
    {
      name: 'web_fetch',
      description: 'Получить содержимое веб-страницы',
      inputSchema: {
        type: 'object',
        properties: {
          url: { type: 'string', description: 'URL страницы' }
        },
        required: ['url']
      }
    },

Tool Definition Quality

Score is being calculated. Check back soon.

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/Galiusbro/MCP'

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