{"url_pattern":"^https?://(www\\.)?bbc\\.com(/.*)?$","site_name":"bbc","allowed_domains":["bbc.co.uk","bbc.com","feeds.bbci.co.uk"],"tools":[{"name":"bbc_news","description":"BBC News headlines (RSS) or search","inputSchema":{"type":"object","properties":{"query":{"type":"string","description":"Search query. If omitted, returns top headlines from RSS feed"},"count":{"type":"string","description":"Max results to return (default 20)"}},"required":null},"handler":"(params) => {\n  const run = async function(args) {\n\n      const count = Math.min(parseInt(args.count) || 20, 50);\n\n      // If no query, fetch top headlines via RSS\n      if (!args.query) {\n        const rssUrl = 'https://feeds.bbci.co.uk/news/rss.xml';\n        const resp = await fetch(rssUrl);\n        if (!resp.ok) return {error: 'HTTP ' + resp.status, hint: 'Failed to fetch BBC RSS feed'};\n        const xml = await resp.text();\n        const parser = new DOMParser();\n        const doc = parser.parseFromString(xml, 'text/xml');\n        const items = doc.querySelectorAll('item');\n        const headlines = [];\n        items.forEach((item, i) => {\n          if (i >= count) return;\n          const title = item.querySelector('title')?.textContent?.trim() || '';\n          const description = item.querySelector('description')?.textContent?.trim() || '';\n          const link = item.querySelector('link')?.textContent?.trim() || '';\n          const pubDate = item.querySelector('pubDate')?.textContent?.trim() || '';\n          headlines.push({title, description, url: link, pubDate});\n        });\n        return {source: 'BBC News RSS', count: headlines.length, headlines};\n      }\n\n      // Search mode: fetch BBC search page and parse HTML\n      const searchUrl = 'https://www.bbc.co.uk/search?q=' + encodeURIComponent(args.query);\n      const resp = await fetch(searchUrl, {credentials: 'include'});\n      if (!resp.ok) return {error: 'HTTP ' + resp.status, hint: 'Failed to fetch BBC search results'};\n      const html = await resp.text();\n      const parser = new DOMParser();\n      const doc = parser.parseFromString(html, 'text/html');\n\n      const results = [];\n\n      // BBC search results use various selectors; try common patterns\n      // Pattern 1: search result links with data attributes or structured containers\n      const links = doc.querySelectorAll('a[href]');\n      const seen = new Set();\n      links.forEach(a => {\n        if (results.length >= count) return;\n        const href = a.getAttribute('href') || '';\n        // Only keep bbc.co.uk/news or bbc.com/news article links\n        if (!(href.includes('/news/') || href.includes('/sport/') || href.includes('/reel/'))) return;\n        if (!href.startsWith('http')) return;\n        if (seen.has(href)) return;\n\n        // Look for a heading or substantial text inside the anchor\n        const heading = a.querySelector('h1, h2, h3, h4, span, p');\n        const title = heading ? heading.textContent.trim() : a.textContent.trim();\n        if (!title || title.length < 5) return;\n\n        seen.add(href);\n\n        // Try to find a sibling or parent description\n        let description = '';\n        const parent = a.closest('li, div, article');\n        if (parent) {\n          const pTags = parent.querySelectorAll('p');\n          for (const p of pTags) {\n            const txt = p.textContent.trim();\n            if (txt.length > 20 && txt !== title) {\n              description = txt.substring(0, 300);\n              break;\n            }\n          }\n        }\n\n        results.push({title, description, url: href});\n      });\n\n      return {query: args.query, count: results.length, results};\n  };\n  return run(params || {});\n}"}]}