网页/新闻/财经/视频/地图/酒店/航班搜索工具,基于 SearchAPI(Google)。支持多种搜索类型,适合 Agent 实时获取网络信息。
基于 SearchAPI (Google) 的多类型搜索工具,适合 Agent 获取实时网络信息。
bash
# 复制 tools/websearchapi 目录到你的项目
# 配置 API Key
cd tools/websearchapi
node websearchapi.js config set-key YOUR_API_KEY
API Key 获取: https://searchapi.io (免费注册)
使用 exec 工具调用:
bash
node <path>/websearchapi.js <命令> [关键词] [选项]
类型命令说明网页s 或 search通用网页搜索新闻news最新新闻视频video视频搜索财经finance股票/金融信息地图maps地点/商户酒店hotels酒店搜索航班flights航班搜索
选项说明默认值--num结果数量5--lang语言zh-CN--gl地区cn--jsonJSON 格式输出文本
bash
# 网页搜索
node websearchapi.js s "MCP 协议"
# 新闻搜索
node websearchapi.js news "人工智能"
# 财经搜索 (用股票代码)
node websearchapi.js finance "AAPL"
# JSON 格式 (推荐,便于解析)
node websearchapi.js s "关键词" --json
JSON 模式返回:
json
{
"success": true,
"query": "关键词",
"type": "google",
"count": 5,
"results": [
{
"title": "结果标题",
"link": "链接地址",
"snippet": "摘要内容",
"source": "来源"
}
],
"metadata": {
"totalResults": 数量,
"timeTaken": 耗时,
"engine": "google"
}
}
bash
node websearchapi.js config
bash
node websearchapi.js config set-key YOUR_API_KEY
bash
node websearchapi.js config set-num 10 # 默认结果数
node websearchapi.js config set-lang en # 默认语言
node websearchapi.js config set-gl us # 默认地区
node websearchapi.js config set-retry 5 # 重试次数
将整个 tools 目录复制到新机器:
bash
# 复制到新机器
scp -r ./tools/websearchapi user@new-server:/path/to/tools/
# 配置 API Key
cd /path/to/tools/websearchapi
node websearchapi.js config set-key YOUR_API_KEY
# 测试
node websearchapi.js test
node websearchapi.js configfinance "AAPL"finance "Tesla stock"config set-retry 5