一个可靠的模型上下文协议(MCP)服务器,用于通过SerpAPI Google Flights引擎搜索航班。该服务器提供了一次性和往返航班的实时搜索能力。 与Claude AI桌面版兼容良好
mkdir -p ~/tools/flightsearch
# 将flight_search_server.py复制到~/tools/flightsearch/
pip install requests
在您的MCP客户端配置中添加以下内容:
{
"flightsearch": {
"command": "python3",
"args": [
"/path/to/your/tools/flightsearch/flight_search_server.py",
"--connection_type",
"stdio"
],
"env": {
"SERP_API_KEY": "your_serpapi_key_here"
}
}
}
对于Claude Desktop,在您的claude_desktop_config.json中添加以下内容:
{
"mcpServers": {
"flightsearch": {
"command": "python3",
"args": [
"/Users/yourusername/tools/flightsearch/flight_search_server.py",
"--connection_type",
"stdio"
],
"env": {
"SERP_API_KEY": "your_serpapi_key_here"
}
}
}
}
search_flights搜索机场之间的航班。
参数:
origin(必需):出发机场代码(例如:"JFK","LAX")destination(必需):到达机场代码(例如:"JFK","LAX")outbound_date(必需):出发日期,格式为YYYY-MM-DDreturn_date(可选):往返航班的返回日期,格式为YYYY-MM-DD示例:
# 单程航班
search_flights(origin="JFK", destination="LAX", outbound_date="2_25-07-01")
# 往返航班
search_flights(origin="JFK", destination="LAX", outbound_date="2025-07-01", return_date="2025-07-08")
server_status检查航班搜索服务器是否正在运行。
参数: 无
{
"status": "success",
"origin": "JFK",
"destination": "LAX",
"outbound_date": "2025-07-01",
"return_date": null,
"trip_type": "one_way",
"flights": [
{
"price": 199,
"departure_time": "2025-07-01 08:40",
"arrival_time": "2025-07-01 11:45",
"airline": "Delta",
"duration": 365,
"stops": 0
},
{
"price": 204,
"departure_time": "2025-07-01 09:00",
"arrival_time": "2025-07-01 12:00",
"airline": "JetBlue",
"duration": 360,
"stops": 0
}
]
}
直接测试服务器:
# 设置环境变量
export SERP_API_KEY="your_api_key"
# 运行服务器
python3 flight_search_server.py --connection_type stdio
服务器实现了JSON-RPC 2.0,并支持以下方法:
initialize - 初始化MCP连接tools/list - 列出可用工具tools/call - 执行工具ping - 健康检查notifications/initialized - 初始化通知服务器将日志记录到stderr以供调试:
# 运行时查看日志
python3 flight_search_server.py --connection_type stdio 2>debug.log
1. "API请求失败:400客户端错误"
2. "未设置SERP_API_KEY环境变量"
SERP_API_KEY3. "JSON-RPC模式验证错误"
4. 未找到航班
启用调试日志记录:
# 添加到flight_search_server.py顶部
logging.basicConfig(level=logging.DEBUG, stream=sys.stderr)
# 克隆仓库
git clone https://github.com/yourusername/flight-search-mcp.git
cd flight-search-mcp
# 安装依赖项
pip install requests
# 运行测试
python3 test_mcp_protocol.py
python3 test_flight_search.py
本项目根据MIT许可发布 - 详见LICENSE文件。
由❤️为MCP社区制作