search_swiss_news
Search Swiss news headlines from SRF by keyword to find relevant articles across all categories.
Instructions
Search Swiss news headlines from SRF by keyword. Searches across all available news categories and returns matching articles.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search keyword or phrase to find in news articles | |
| limit | No | Maximum number of results to return (default: 5, max: 20) |
Implementation Reference
- src/modules/news.ts:125-178 (handler)The implementation of the `handleSearchSwissNews` function which fetches RSS feeds and filters articles by keyword.
export async function handleSearchSwissNews(args: { query: string; limit?: number; }): Promise<string> { const query = args.query.toLowerCase().trim(); const limit = Math.min(args.limit ?? 5, 20); if (!query) { throw new Error("query parameter is required and cannot be empty"); } // Search across all available feeds const allArticles: (NewsArticle & { category: string })[] = []; await Promise.all( Object.entries(FEED_IDS).map(async ([cat, feedId]) => { try { const xml = await fetchFeed(feedId); const items = parseRssItems(xml); for (const item of items) { allArticles.push({ ...item, category: cat }); } } catch { // Skip unavailable feeds silently } }) ); // Filter by query (title or description) const matched = allArticles.filter( (a) => a.title.toLowerCase().includes(query) || a.description.toLowerCase().includes(query) ); // Deduplicate by link const seen = new Set<string>(); const unique = matched.filter((a) => { if (seen.has(a.link)) return false; seen.add(a.link); return true; }); const results = unique.slice(0, limit); const result = { query: args.query, count: results.length, articles: results, source: "srf.ch", }; return JSON.stringify(result, null, 2); } - src/modules/news.ts:207-224 (registration)The registration of the `search_swiss_news` tool within the MCP server using zod for schema validation.
server.tool( "search_swiss_news", "Search Swiss news headlines from SRF by keyword. Searches across all available news categories and returns matching articles.", { query: z.string().min(1).describe("Search keyword or phrase to find in news articles"), limit: z .number() .int() .min(1) .max(20) .optional() .describe("Maximum number of results to return (default: 5, max: 20)"), }, async (args) => { const text = await handleSearchSwissNews(args); return { content: [{ type: "text", text }] }; } );