web_fetch
Retrieve and clean web page content for developer operational tasks, enabling secure access to external information sources within AI workflows.
Instructions
Получить содержимое веб-страницы
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | URL страницы |
Implementation Reference
- src/connectors/web-service.ts:24-75 (handler)Core handler function that implements the web_fetch tool logic: validates URL, fetches page with axios, parses HTML with cheerio, extracts title, clean text, and links.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}`); } }
- src/server.ts:118-131 (schema)Input schema for web_fetch tool registered in MCP ListToolsRequestSchema handler.{ name: 'web_fetch', description: 'Получить содержимое веб-страницы', inputSchema: { type: 'object', properties: { url: { type: 'string', description: 'URL страницы', }, }, required: ['url'], }, },
- src/server.ts:205-208 (registration)Registration and dispatching of web_fetch tool call in MCP CallToolRequestSchema handler.case 'web_fetch': return { content: await this.webService.fetchPage(args.url as string) };
- Input schema for web_fetch tool in HTTP transport's tools list.{ name: 'web_fetch', description: 'Получить содержимое веб-страницы', inputSchema: { type: 'object', properties: { url: { type: 'string', description: 'URL страницы' } }, required: ['url'] } },
- src/transports/http-transport.ts:242-244 (registration)Dispatching of web_fetch tool call in HTTP transport's handleCallTool method.case 'web_fetch': result = await this.webService.fetchPage(args.url); break;