read_webpage
Extract text content from any webpage by providing its URL. This tool fetches and processes web content for analysis or information retrieval.
Instructions
Fetch and extract text content from a webpage
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | URL of the webpage to read |
Implementation Reference
- src/index.ts:175-220 (handler)Handler for the 'read_webpage' tool: validates input, fetches URL with axios, parses HTML with cheerio, extracts title and cleaned body text, returns structured JSON content.
} else if (request.params.name === 'read_webpage') { if (!isValidWebpageArgs(request.params.arguments)) { throw new McpError( ErrorCode.InvalidParams, 'Invalid webpage arguments' ); } const { url } = request.params.arguments; try { const response = await axios.get(url); const $ = cheerio.load(response.data); // Remove script and style elements $('script, style').remove(); const content: WebpageContent = { title: $('title').text().trim(), text: $('body').text().trim().replace(/\s+/g, ' '), url: url, }; return { content: [ { type: 'text', text: JSON.stringify(content, null, 2), }, ], }; } catch (error) { if (axios.isAxiosError(error)) { return { content: [ { type: 'text', text: `Webpage fetch error: ${error.message}`, }, ], isError: true, }; } throw error; } } - src/index.ts:109-122 (registration)Tool registration in ListTools response, defining name, description, and input schema for 'read_webpage'.
{ name: 'read_webpage', description: 'Fetch and extract text content from a webpage', inputSchema: { type: 'object', properties: { url: { type: 'string', description: 'URL of the webpage to read', }, }, required: ['url'], }, }, - src/index.ts:44-49 (schema)Runtime validation function for 'read_webpage' input arguments (schema enforcement).
const isValidWebpageArgs = ( args: any ): args is { url: string } => typeof args === 'object' && args !== null && typeof args.url === 'string'; - src/index.ts:30-34 (helper)Type definition for the structured output of the 'read_webpage' tool.
interface WebpageContent { title: string; text: string; url: string; }