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
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | URL страницы |
Implementation Reference
- src/connectors/web-service.ts:24-75 (handler)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}`); } }
- src/connectors/web-service.ts:4-10 (schema)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'], }, },
- src/server.ts:205-208 (handler)Dispatch handler in main MCP server CallToolRequestSchema that invokes WebService.fetchPage.case 'web_fetch': return { content: await this.webService.fetchPage(args.url as string) };
- src/transports/http-transport.ts:152-162 (registration)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'] } },