一个基于 Model Context Protocol (MCP) 的生产级搜索服务器,通过 SearchAPI.io 提供全面的搜索功能。使 AI 助手能够搜索 Google、地图、航班、酒店等,内置缓存、重试逻辑和熔断器。
</div>最快的方式是使用 uvx:
# 设置你的 API 密钥
export SEARCHAPI_API_KEY="your_api_key_here"
# 直接使用 uvx 运行(无需安装)
uvx --from git+https://github.com/RmMargt/searchAPI-mcp.git mcp-server-searchapi
UV 是最快且最方便的方法:
# 如果尚未安装,请安装 uv
curl -LsSf https://astral.sh/uv/install.sh | sh
# 克隆仓库
git clone https://github.com/RmMargt/searchAPI-mcp.git
cd searchAPI-mcp
# 安装依赖项
uv pip install -r requirements.txt
# 克隆仓库
git clone https://github.com/RmMargt/searchAPI-mcp.git
cd searchAPI-mcp
# 创建并激活虚拟环境
python -m venv venv
source venv/bin/activate # 在 Windows 上:.\venv\Scripts\activate
# 安装依赖项
pip install -r requirements.txt
git clone https://github.com/RmMargt/searchAPI-mcp.git
cd searchAPI-mcp
# 使用 uv
uv pip install httpx fastmcp python-dotenv pydantic pydantic-settings
# 或者使用 pip
pip install httpx fastmcp python-dotenv pydantic pydantic-settings
在项目根目录创建一个 .env 文件:
# 必需
SEARCHAPI_API_KEY=your_api_key_here
# 可选 - API 配置
SEARCHAPI_API_URL=https://www.searchapi.io/api/v1/search
TIMEOUT=30.0
MAX_RETRIES=3
RETRY_BACKOFF=1.0
# 可选 - 缓存配置
ENABLE_CACHE=true
CACHE_TTL=3600
CACHE_MAX_SIZE=1000
# 可选 - 连接池
POOL_CONNECTIONS=10
POOL_MAXSIZE=10
# 可选 - 监控
ENABLE_METRICS=true
LOG_LEVEL=INFO
添加到你的 Claude Desktop 配置文件中:
位置:
~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.json~/.config/Claude/claude_desktop_config.json使用 UV(推荐):
{
"mcpServers": {
"searchapi": {
"command": "uvx",
"args": [
"--directory",
"/absolute/path/to/searchAPI-mcp",
"python",
"mcp_server_refactored.py"
],
"env": {
"SEARCHAPI_API_KEY": "your_api_key_here"
}
}
}
}
直接使用 Python:
{
"mcpServers": {
"searchapi": {
"command": "python",
"args": [
"/absolute/path/to/searchAPI-mcp/mcp_server_refactored.py"
],
"env": {
"SEARCHAPI_API_KEY": "your_api_key_here"
}
}
}
}
使用虚拟环境:
{
"mcpServers": {
"searchapi": {
"command": "/absolute/path/to/searchAPI-mcp/venv/bin/python",
"args": [
"/absolute/path/to/searchAPI-mcp/mcp_server_refactored.py"
],
"env": {
"SEARCHAPI_API_KEY": "your_api_key_here"
}
}
}
}
添加到 .vscode/mcp.json 中或使用“MCP: 打开用户配置”命令:
{
"servers": {
"searchapi": {
"command": "python",
"args": [
"/absolute/path/to/searchAPI-mcp/mcp_server_refactored.py"
],
"env": {
"SEARCHAPI_API_KEY": "your_api_key_here"
}
}
}
}
使用 UV:
{
"servers": {
"searchapi": {
"command": "uvx",
"args": [
"--directory",
"/absolute/path/to/searchAPI-mcp",
"python",
"mcp_server_refactored.py"
],
"env": {
"SEARCHAPI_API_KEY": "your_api_key_here"
}
}
}
}
添加到 ~/.config/zed/settings.json:
{
"context_servers": {
"searchapi": {
"command": {
"path": "python",
"args": [
"/absolute/path/to/searchAPI-mcp/mcp_server_refactored.py"
],
"env": {
"SEARCHAPI_API_KEY": "your_api_key_here"
}
}
}
}
}
在 Cline 设置中添加到 MCP 服务器:
{
"mcpServers": {
"searchapi": {
"command": "python",
"args": [
"/absolute/path/to/searchAPI-mcp/mcp_server_refactored.py"
],
"env": {
"SEARCHAPI_API_KEY": "your_api_key_here"
}
}
}
}
对于任何兼容 MCP 的客户端:
# 使用 stdio 传输(默认)
python /path/to/searchAPI-mcp/mcp_server_refactored.py
# 使用环境变量
SEARCHAPI_API_KEY=your_key python mcp_server_refactored.py
health_check检查 SearchAPI 服务的健康状况和性能。
返回值:
示例:
{
"api_status": {
"status": "healthy",
"latency_ms": 145.23,
"circuit_breaker": "closed"
},
"cache_stats": {
"size": 42,
"max_size": 1000,
"ttl": 3600
},
"metrics": {
"request_count": 156,
"error_count": 2,
"cache_hit_rate": 0.67
}
}
get_current_time获取当前时间和旅行日期建议。对于航班和酒店预订至关重要。
参数:
format - 日期格式:"iso", "slash", "chinese", "timestamp", "full"days_offset - 从今天起的天数(可以是负数)return_future_dates - 返回未来日期数组future_days - 未来日期的数量(如果 return_future_dates=true)示例:
# 获取今天的日期,ISO 格式
get_current_time(format="iso")
# 返回:{"date": "2025-11-16", "now": {...}, "travel_dates": {...}}
# 获取 7 天后的时间以及未来日期数组
get_current_time(days_offset=7, return_future_dates=True, future_days=30)
search_google搜索 Google 的网页结果、知识图谱和答案框。
参数:
q (必需) - 搜索查询location - 地点名称(例如,“纽约,纽约”)gl - 国家代码(默认:"us")hl - 语言代码(默认:"en")time_period - 时间筛选:"last_hour", "last_day", "last_week", "last_month", "last_year"num - 每页结果数量(默认:"10")safe - 安全搜索:"off", "active"示例:
search_google(
q="Python 编程教程",
location="旧金山, 加利福尼亚州",
time_period="last_month",
num="20"
)
search_google_videos搜索 Google 视频内容。
参数: 类似于 search_google,但有视频特定的筛选条件
q (必需) - 搜索查询time_period - 按上传时间筛选device - "desktop" 或 "mobile"示例:
search_google_videos(
q="机器学习教程",
time_period="last_week",
num="10"
)
search_google_ai_mode使用 AI 生成的概述和引用来源进行搜索。
参数:
q - 搜索查询(除非提供 url,否则必需)url - 图像 URL 以进行搜索location - 本地化结果的位置返回值:
示例:
search_google_ai_mode(
q="机器学习是如何工作的?",
location="美国"
)
search_google_maps搜索地点、企业和服务。
参数:
query (必需) - 搜索查询location_ll - 经纬度坐标(格式:"@lat,lng,zoom")示例:
search_google_maps(
query="中央公园附近的咖啡馆",
location_ll="@40.7829,-73.9654,15z"
)
search_google_maps_place获取特定地点的详细信息。
参数:
place_id (如果没有 data_id,则必需) - Google 地图地点 IDdata_id - 替代地点标识符google_domain - Google 域名(默认:"google.com")hl - 语言代码(默认:"en")示例:
search_google_maps_place(
place_id="ChIJN1t_tDeuEmsRUsoyG83frY4"
)
search_google_maps_reviews获取特定地点的评论。
参数:
place_id (如果没有 data_id,则必需) - Google 地图地点 IDdata_id - 替代地点标识符sort_by - "most_relevant", "newest", "highest_rating", "lowest_rating"rating - 按评分筛选:"1"-"5"示例:
search_google_maps_reviews(
place_id="ChIJN1t_tDeuEmsRUsoyG83frY4",
sort_by="newest",
rating="5"
)
search_google_events搜索活动、音乐会、会议和活动。
参数:
q (必需) - 搜索查询(例如,“纽约市音乐会”,“科技会议”)location - 用于本地化结果的地点名称chips - 日期筛选("today", "tomorrow", "week", "weekend", "month")或活动类型gl - 国家代码(默认:"us")hl - 语言代码(默认:"en")page - 页码(默认:"1")示例:
search_google_events(
q="奥斯汀音乐节",
chips="weekend",
location="奥斯汀, 德克萨斯州"
)
search_google_flights搜索航班,带有综合筛选。
参数:
departure_id (必需) - 机场代码(例如,“JFK”)arrival_id (必需) - 机场代码(例如,“LAX”)outbound_date (必需) - 出发日期(YYYY-MM-DD)flight_type - "one_way", "round_trip", "multi_city"return_date - 回程日期(往返行程必需)travel_class - "economy", "premium_economy", "business", "first"stops - "0"(直飞),"1","2"adults - 成人人数currency - 货币代码(例如,“USD”)示例:
search_google_flights(
departure_id="JFK",
arrival_id="LAX",
outbound_date="2025-12-15",
return_date="2025-12-22",
flight_type="round_trip",
travel_class="economy",
stops="0",
adults="2"
)
search_google_flights_calendar获取价格日历,以便灵活规划日期。
参数:
flight_type (必需) - "one_way" 或 "round_trip"departure_id (必需) - 机场代码arrival_id (必需) - 机场代码outbound_date (必需) - 参考日期return_date - 往返行程必需示例:
search_google_flights_calendar(
flight_type="round_trip",
departure_id="SFO",
arrival_id="NYC",
outbound_date="2025-12-01",
return_date="2025-12-08"
)
search_google_flights_location_search搜索机场代码和地点。
参数:
q (必需) - 搜索查询(机场名称、城市或代码)gl - 国家代码(默认:"us")hl - 语言代码(默认:"en")示例:
search_google_flights_location_search(
q="东京"
)
search_google_travel_explore探索旅行目的地,寻找灵感。
参数:
departure_id (必需) - 出发机场代码或地点arrival_id - 目的地(默认为任何地方)time_period - 旅行期间(例如,“十二月两周的旅行”)interests - 按兴趣筛选:"popular", "outdoors", "beaches", "museums", "history", "skiing"travel_class - "economy", "premium_economy", "business", "first_class"adults - 成人人数(默认:"1")currency - 货币代码(默认:"USD")示例:
search_google_travel_explore(
departure_id="JFK",
interests="beaches",
time_period="two_week_trip_in_december"
)