get-weekly-news
Retrieve news articles from The Verge published in the past seven days to stay informed about technology and culture developments.
Instructions
Get the latest news from The Verge for the past week
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:184-215 (handler)The core handler logic for the 'get-weekly-news' tool. It fetches the latest RSS feed from The Verge, filters articles from the past 7 days, randomly selects 10 articles, formats them into brief summaries, and returns the result as structured text content. Includes error handling with console logging and error response.async () => { try { const allNews = await fetchVergeNews(); const weeklyNews = filterNewsByDate(allNews, 7); // Last 7 days // Randomly select 10 news items from the past week const randomWeeklyNews = getRandomNewsItems(weeklyNews, 10); const formattedNews = formatNewsItems(randomWeeklyNews); const newsText = formatNewsAsBriefSummary(formattedNews); return { content: [ { type: "text", text: `# The Verge - Random Weekly News\n\n${newsText}` } ] }; } catch (error) { console.error("Error in get-weekly-news:", error); return { content: [ { type: "text", text: `Error fetching weekly news: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } }
- src/index.ts:179-216 (registration)The registration of the 'get-weekly-news' tool using McpServer.tool(). Specifies the tool name, description, empty input schema ({}), and references the inline handler function.// Register tool for weekly news server.tool( "get-weekly-news", "Get the latest news from The Verge for the past week", {}, async () => { try { const allNews = await fetchVergeNews(); const weeklyNews = filterNewsByDate(allNews, 7); // Last 7 days // Randomly select 10 news items from the past week const randomWeeklyNews = getRandomNewsItems(weeklyNews, 10); const formattedNews = formatNewsItems(randomWeeklyNews); const newsText = formatNewsAsBriefSummary(formattedNews); return { content: [ { type: "text", text: `# The Verge - Random Weekly News\n\n${newsText}` } ] }; } catch (error) { console.error("Error in get-weekly-news:", error); return { content: [ { type: "text", text: `Error fetching weekly news: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } } );
- src/index.ts:101-125 (helper)Helper utility specifically used by get-weekly-news to randomly select 10 news items from the filtered weekly news list, ensuring no duplicates.function getRandomNewsItems(items: Parser.Item[], count: number = 10) { if (items.length <= count) { return items; // Return all items if there are fewer than requested } // Create a copy of the array to avoid modifying the original const itemsCopy = [...items]; const result: Parser.Item[] = []; // Randomly select 'count' items for (let i = 0; i < count; i++) { if (itemsCopy.length === 0) break; // Get a random index const randomIndex = Math.floor(Math.random() * itemsCopy.length); // Add the randomly selected item to the result result.push(itemsCopy[randomIndex]); // Remove the selected item to avoid duplicates itemsCopy.splice(randomIndex, 1); } return result; }