Token导航 LogoToken导航TokenDH.com
Flight Search logo
AI代理stdio官方级别未说明来源级核验

Flight Search

MCP Server

一个基于SerpAPI Google Flights引擎的可靠MCP协议服务器,提供实时航班搜索功能,支持单程和往返航班查询。

工具数

2

提示词数

0

GitHub Stars

2

资源数

0
旅行规划PythonClaudeAPI集成Claude

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

random-robbie

提供方

random-robbie

最后核验

2026/5/17 20:21

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

pip install requests

详细介绍

航班搜索MCP服务器

一个可靠的模型上下文协议(MCP)服务器,用于使用SerpAPI Google flights引擎搜索航班。该服务器为单程和往返航班提供实时航班搜索功能。 与claude ai桌面配合良好

✈️ 特性

  • 实时航班搜索 使用SerpAPI谷歌航班
  • 单程和往返 飞行支援
  • 多种航班选择 包括定价、时间和航空公司详细信息
  • 符合JSON-RPC 2.0标准 MCP协议实现
  • 易于集成 与Claude和其他MCP客户
  • 稳健的错误处理 以及日志记录

🚀 快速开始

先决条件

  • Python 3.7或更高版本
  • SerpAPI帐户和API密钥(在这里买一个)
  • MCP兼容客户端(Claude等)

安装

  1. 克隆或下载 服务器文件:
mkdir -p ~/tools/flightsearch
# Copy flight_search_server.py to ~/tools/flightsearch/
  1. 安装依赖项:
pip install requests
  1. 获取您的SerpAPI密钥:

- 注册地址: SerpAPI - 从仪表板获取API密钥

配置

将以下内容添加到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_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-DD格式的出发日期
  • return_date (可选):往返航班的返回日期,格式为YYYY-MM-DD

示例:

# One-way flight
search_flights(origin="JFK", destination="LAX", outbound_date="2025-07-01")

# Round-trip flight  
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
    }
  ]
}

🔧 发展

运行测试

直接测试服务器:

# Set environment variable
export SERP_API_KEY="your_api_key"

# Run the server  
python3 flight_search_server.py --connection_type stdio

协议测试

服务器实现JSON-RPC 2.0并支持以下方法:

  • initialize -初始化MCP连接
  • tools/list -列出可用工具
  • tools/call -执行工具
  • ping -健康检查
  • notifications/initialized -初始化通知

日志记录

服务器登录到stderr进行调试:

# View logs while running
python3 flight_search_server.py --connection_type stdio 2>debug.log

🐛 故障排除

常见问题

1.“API请求失败:400客户端错误”

  • 验证您的SerpAPI密钥是否有效
  • 检查机场代码是否正确(使用IATA代码,如“JFK”、“LAX”)
  • 确保日期格式为YYYY-MM-DD

2.“未设置SERP_API_KEY环境变量”

  • 确保在MCP配置中正确设置了API密钥
  • 验证环境变量名称是否准确 SERP_API_KEY

3.“JSON-RPC模式验证错误”

  • 重新启动MCP客户端以重新加载服务器
  • 检查您是否使用的是最新版本的服务器

4.未找到航班

  • 尝试不同的机场代码或日期
  • 某些路线可能在所选日期不可用
  • 查看SerpAPI文档以了解支持的机场

调试模式

启用调试日志记录:

# Add to the top of flight_search_server.py
logging.basicConfig(level=logging.DEBUG, stream=sys.stderr)

📝 API限制

  • SerpAPI速率限制:检查您的SerpAPI计划以了解请求限制
  • 飞行数据:结果取决于谷歌航班数据的可用性
  • 日期范围:仅限未来日期(无法搜索过去的航班)
  • 机场代码:必须使用有效的IATA机场代码

🤝 贡献

  1. 分叉存储库
  2. 创建要素分支
  3. 进行更改
  4. 如果适用,添加测试
  5. 提交拉取请求

开发设置

# Clone the repo
git clone https://github.com/yourusername/flight-search-mcp.git
cd flight-search-mcp

# Install dependencies
pip install requests

# Run tests
python3 test_mcp_protocol.py
python3 test_flight_search.py

📄 许可证

此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。

🙏 致谢

  • SerpAPI 用于提供Google Flights API
  • Anthropic 用于MCP协议规范
  • 开源社区提供灵感和反馈

📞 支持

______________________________________________________________________

由以下材料制成❤️ 对于MCP社区

目录标签

目录标签

旅行规划PythonClaudeAPI集成航班搜索本地部署实时数据MCP协议

支持客户端

Claude

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

none

工具数量(toolCount,工具数)

2

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdionone部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP