Skip to main content
Glama

read_webpage

Extract text content from any webpage by providing its URL, enabling users to access and process web information without manual browsing.

Instructions

Fetch and extract text content from a webpage

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesURL of the webpage to read

Implementation Reference

  • Handler for the 'read_webpage' tool: validates arguments, fetches the webpage with axios, parses content using cheerio (removing scripts/styles), extracts title and cleaned body text, returns structured JSON or error response.
    } 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)
    Registration of the 'read_webpage' tool in the ListTools handler, including name, description, and input schema requiring a 'url' string.
    { 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'], }, },
  • Type guard function for validating input arguments to the 'read_webpage' tool, ensuring it has a 'url' string property.
    const isValidWebpageArgs = ( args: any ): args is { url: string } => typeof args === 'object' && args !== null && typeof args.url === 'string';
  • TypeScript interface defining the structure of the webpage content returned by the tool.
    interface WebpageContent { title: string; text: string; url: string; }

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/pgzhang/mcp2'

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