search-news
Search for The Verge news articles by keyword to find relevant content from the past 30 days.
Instructions
Search for news articles from The Verge by keyword
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| keyword | Yes | Keyword to search for in news articles | |
| days | No | Number of days to look back (default: 30) |
Implementation Reference
- src/index.ts:226-254 (handler)The main handler function for the 'search-news' tool. It fetches the latest news from The Verge RSS feed, filters articles by the specified number of days and keyword (in title or content), formats them into brief summaries (limited to 10 items), and returns the result as structured text content or an error response.async ({ keyword, days = 30 }) => { try { const allNews = await fetchVergeNews(); const filteredByDate = filterNewsByDate(allNews, days); const filteredByKeyword = filterNewsByKeyword(filteredByDate, keyword); const formattedNews = formatNewsItems(filteredByKeyword); const newsText = formatNewsAsBriefSummary(formattedNews, 10); // Use brief summary format with limit of 10 return { content: [ { type: "text", text: `# The Verge - Search Results for "${keyword}"\n\n${newsText}` } ] }; } catch (error) { console.error("Error in search-news:", error); return { content: [ { type: "text", text: `Error searching news: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } }
- src/index.ts:222-225 (schema)Zod input schema defining the parameters for the 'search-news' tool: required 'keyword' string and optional 'days' number.{ keyword: z.string().describe("Keyword to search for in news articles"), days: z.number().optional().describe("Number of days to look back (default: 30)") },
- src/index.ts:219-225 (registration)MCP server tool registration call for 'search-news', specifying the tool name, description, and input schema. The handler function follows immediately after.server.tool( "search-news", "Search for news articles from The Verge by keyword", { keyword: z.string().describe("Keyword to search for in news articles"), days: z.number().optional().describe("Number of days to look back (default: 30)") },
- src/index.ts:50-59 (helper)Helper function used by the search-news handler to filter news items containing the keyword in title or content (case-insensitive).function filterNewsByKeyword(items: Parser.Item[], keyword: string) { const lowerKeyword = keyword.toLowerCase(); return items.filter((item) => { const title = (item.title || "").toLowerCase(); const content = (item.contentSnippet || item.content || "").toLowerCase(); return title.includes(lowerKeyword) || content.includes(lowerKeyword); }); }
- src/index.ts:14-22 (helper)Core helper function that fetches and parses the RSS feed from The Verge, returning the list of news items. Used by the search-news handler.async function fetchVergeNews() { try { const feed = await parser.parseURL(VERGE_RSS_URL); return feed.items; } catch (error) { console.error("Error fetching RSS feed:", error); throw new Error("Failed to fetch news from The Verge"); } }