mcpField
N
news-search

news-search

github.com/brave生产力1921.7k 次安装11 周前更新
代码仓库

关于 news-search

news-search 是通过 Brave Search API 查询新闻文章的技能,适合新闻监测与研究。它支持时间范围筛选和 Goggles 来源排序规则。

主要功能

  1. 01按关键词搜索新闻
  2. 02按国家与语言筛选
  3. 03按时间或日期范围筛选
  4. 04用 Goggles 调整来源排序
  5. 05返回文章摘要与发布时间

适用场景

  1. 01追踪主题的最新报道
  2. 02限定日期范围进行新闻研究
  3. 03优先展示可信新闻来源

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/brave/brave-search-skills --skill news-search

安装后在 Claude Code 中输入/news-search确认已加载。

详细介绍

新闻搜索

需要 API 密钥:请访问 https://api.search.brave.com 获取

套餐:已包含在 Search 套餐中。请参阅 https://api-dashboard.search.brave.com/app/subscriptions/subscribe

快速入门(cURL)

基本搜索
curl -s "https://api.search.brave.com/res/v1/news/search?q=space+exploration" \
  -H "Accept: application/json" \
  -H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}"
最近新闻(过去 24 小时)
curl -s "https://api.search.brave.com/res/v1/news/search" \
  -H "Accept: application/json" \
  -H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}" \
  -G \
  --data-urlencode "q=cybersecurity" \
  --data-urlencode "country=US" \
  --data-urlencode "freshness=pd" \
  --data-urlencode "count=20"
日期范围筛选
curl -s "https://api.search.brave.com/res/v1/news/search" \
  -H "Accept: application/json" \
  -H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}" \
  -G \
  --data-urlencode "q=climate summit" \
  --data-urlencode "freshness=2026-01-01to2026-01-31"

端点

GET https://api.search.brave.com/res/v1/news/search
POST https://api.search.brave.com/res/v1/news/search

身份验证:X-Subscription-Token: <API_KEY> 请求头

注意:支持 GET 和 POST。对于较长的查询或复杂的 Goggles,使用 POST 更方便。

参数

参数类型必填默认值描述
qstring是-搜索查询(1-400 个字符,最多 50 个单词)
countrystring否US搜索国家(2 个字母的国家代码或 ALL)
search_langstring否en语言偏好(至少 2 个字符的语言代码)
ui_langstring否en-USUI 语言(例如,“en-US”)
countint否20结果数量(1-50)
offsetint否0页面偏移量(0-9)
safesearchstring否strict成人内容筛选(off/moderate/strict)
freshnessstring否-时间筛选(pd/pw/pm/py 或日期范围)
spellcheckbool否true自动更正查询
extra_snippetsbool否-每条结果最多提供 5 条额外摘录
gogglesstring 或 array否-自定义排序筛选器(URL 或内联内容;多个值请重复此参数)
operatorsbool否true应用搜索运算符
include_fetch_metadatabool否false在结果中包含获取时间戳
时效性取值
值描述
pd过去一天(24 小时)——适合突发新闻
pw过去一周(7 天)
pm过去一个月(31 天)
py过去一年(365 天)
YYYY-MM-DDtoYYYY-MM-DD自定义日期范围

响应格式

{
  "type": "news",
  "query": {
    "original": "space exploration"
  },
  "results": [
    {
      "type": "news_result",
      "title": "New Developments in Space Exploration",
      "url": "https://news.example.com/space-exploration",
      "description": "Recent missions have advanced our understanding of...",
      "age": "2 hours ago",
      "page_age": "2026-01-15T14:30:00",
      "page_fetched": "2026-01-15T15:00:00Z",
      "meta_url": {
        "scheme": "https",
        "netloc": "news.example.com",
        "hostname": "news.example.com",
        "favicon": "https://imgs.search.brave.com/favicon/news.example.com",
        "path": "/space-exploration"
      },
      "profile": {
        "name": "Example Outlet",
        "url": "https://news.example.com/space-exploration"
      },
      "thumbnail": {
        "src": "https://imgs.search.brave.com/..."
      }
    }
  ]
}

响应字段

字段类型描述
typestring始终为 "news"
query.originalstring原始搜索查询
query.alteredstring?拼写检查修正后的查询(如有更改)
query.cleanedstring?拼写检查器清理/规范化后的查询
query.spellcheck_offbool?是否已禁用拼写检查
query.show_strict_warningbool?如果严格安全搜索屏蔽了结果,则为 True
query.search_operatorsobject?已应用的搜索运算符
query.search_operators.appliedbool是否已应用运算符
query.search_operators.cleaned_querystring?运算符处理后的查询
query.search_operators.siteslist[str]?来自 site: 运算符的域名
results[].typestring始终为 "news_result"
results[].titlestring文章标题
results[].urlstring文章来源 URL
results[].descriptionstring?文章描述/摘要
results[].agestring?易读的时长(例如 "2 hours ago")
results[].page_agestring?来源中的发布日期(ISO datetime)
results[].page_fetchedstring?页面上次抓取时间(ISO datetime)
results[].fetched_content_timestampint?抓取时间戳(仅在 include_fetch_metadata=true 时提供)
results[].meta_url.schemestring?URL 协议方案
results[].meta_url.netlocstring?网络位置
results[].meta_url.hostnamestring?转为小写的域名
results[].meta_url.faviconstring?网站图标 URL
results[].meta_url.pathstring?URL 路径
results[].thumbnail.srcstring提供的缩略图 URL
results[].thumbnail.originalstring?原始缩略图 URL
results[].extra_snippetslist[str]?每条结果最多 5 条额外摘录
results[].profile.namestring?网站名称
results[].profile.urlstring?个人资料所在的原始 URL
results[].profile.long_namestring?网站全名
results[].profile.imgstring?代表个人资料的图片 URL

Goggles(自定义排名)——Brave 独有

Goggles 可让你重新排列新闻结果——提升可信媒体的排名,或降低不需要的来源的排名。

方法示例
托管--data-urlencode "goggles=https://raw.githubusercontent.com/brave/goggles-quickstart/main/goggles/hacker_news.goggle"
内联--data-urlencode 'goggles=$discard\n$site=example.com'

托管 Goggles 必须位于 GitHub/GitLab 上,包含 ! name:、! description:、! author: 标头,并在 https://search.brave.com/goggles/create 注册。内联规则无需注册。

语法:规则以 $ 开头,后接以逗号分隔的选项。操作(任选其一):discard、boost[=N]、downrank[=N]——N 为 1–10 的整数。站点筛选器:site=DOMAIN。示例:$site=example.com,boost=3。规则之间用 \n(%0A)分隔。

允许列表:$discard\n$site=docs.python.org\n$site=developer.mozilla.org — 屏蔽列表:$discard,site=pinterest.com\n$discard,site=quora.com

资源:发现 · 语法 · 快速入门

搜索运算符

使用搜索运算符来优化结果:

  • site:local-paper.com - 限定为特定新闻网站
  • "exact phrase" - 匹配确切短语
  • -exclude - 排除词语

设置 operators=false 可禁用运算符解析。

使用场景

  • 突发新闻监测:使用 freshness=pd 获取某个主题的最新文章。
  • 借助 Goggles 创建自定义新闻订阅源:提高可信来源的权重并剔除其他来源,这是 Brave 独有的功能。
  • 历史新闻研究:使用 freshness=YYYY-MM-DDtoYYYY-MM-DD 查找特定时间段内的文章。
  • 多语言新闻:结合使用 country、search_lang 和 ui_lang,获取跨地区结果。
  • 数据流水线:设置 include_fetch_metadata=true,为每条结果获取 fetched_content_timestamp。

注意事项

  • SafeSearch:默认值为 strict
  • 分页:将 offset(0-9)与 count 配合使用
  • 额外摘要:设置 extra_snippets=true 时,最多可获取 5 条额外摘录

评论

支持 Markdown