快速航班MCP服务器
MCP(模型上下文协议)服务器,用于封装 fast-flights 图书馆为人工智能代理提供强大的航班搜索和分析功能。
特性
此MCP服务器为AI代理提供了以下工具:
- 搜索航班:查找特定日期机场之间的可用航班
- 寻找最优价格:确定路线中最便宜的航班选项
- 查找最短持续时间:找到最快的航班选项
- 比较航班:对所有航班选项进行全面分析
- 筛选航班:应用自定义标准(价格、持续时间、止损)以缩小结果范围
快速开始
安装
# Install uv package manager (if not already installed)
curl -LsSf https://astral.sh/uv/install.sh | sh
# Install dependencies
uv sync
# Test the server
uv run python src/main.py局部测试
# Test the server configuration
uv run python test_mcp_server.py
# Run functional tests (searches real flights)
uv run python tests/test_server.py备注:跑步 uv run main 直接显示JSON-RPC错误-这是意料之中的!MCP服务器通过JSON-RPC通信,需要由MCP客户端(如Claude Desktop或Dedalus)运行,而不是直接从终端运行。
可用工具
1.探照灯
搜索特定日期两个机场之间的航班。
参数:
date(必填):YYYY-MM-DD格式的航班日期(例如“2025-01-01”)from_airport(必填):出发机场代码(例如“LAX”、“JFK”、“TPE”)to_airport(必填):抵达机场代码(例如“SFO”、“LHR”、“MYJ”)adults(可选):成年乘客人数(默认值:1)children(可选):儿童乘客数量(默认值:0)infants_in_seat(可选):座位上的婴儿数量(默认值:0)infants_on_lap(可选):腿上的婴儿数量(默认值:0)max_results(可选):返回的最大航班数(默认值:10)
退货: 航班搜索结果,包括价格、持续时间、停靠站等。
2.查找_测试_价格
查找路线和日期的最便宜航班选项。
参数: 同 search_flights (除 max_results)
退货: 最便宜航班的详细信息和价格比较。
3.查找_最短_持续时间
找到旅行时间最短的航班。
参数: 同 search_flights (除 max_results)
退货: 最快飞行的详细信息和持续时间比较。
4.比较飞行选项
全面比较所有可用的航班选项。
参数: 同 search_flights (除 max_results)
退货: 分析包括:
- 最便宜的航班
- 最快飞行
- 推荐选项(被搜索引擎标记为“最佳”)
- 统计数据(平均价格、平均持续时间、价格范围)
- 直达航班可用性
5.过滤器_照明_按标准
根据特定条件过滤航班。
参数:
- 所有参数来自
search_flights加上: max_price(可选):每人最高价格max_duration(可选):最长持续时间(分钟)max_stops(可选):最大停车次数direct_only(可选):仅显示直达航班(默认值:False)
退货: 符合您条件的筛选航班结果。
用法示例
示例1:基本航班搜索
from dedalus_labs import AsyncDedalus, DedalusRunner
async def search_example():
client = AsyncDedalus(api_key="your-api-key")
runner = DedalusRunner(client)
result = await runner.run(
input="Find flights from LAX to SFO on 2025-01-15 for 2 adults",
model="claude-3-5-sonnet-20241022",
mcp_servers=["your-org/fast-flights-mcp"]
)
print(result.final_output)示例2:寻找最优价格
result = await runner.run(
input="What's the cheapest flight from New York (JFK) to London (LHR) on March 1st, 2025?",
model="openai/gpt-4",
mcp_servers=["your-org/fast-flights-mcp"]
)示例3:比较选项
result = await runner.run(
input="Compare all flight options from TPE to MYJ on 2025-01-01. Show me the cheapest, fastest, and recommended flights.",
model="claude-3-5-sonnet-20241022",
mcp_servers=["your-org/fast-flights-mcp"]
)示例4:筛选航班
result = await runner.run(
input="Find direct flights from LAX to JFK on 2025-02-14 under $300 per person",
model="openai/gpt-4",
mcp_servers=["your-org/fast-flights-mcp"]
)项目结构
fast-flights-mcp/
├── main.py # Entry point for Dedalus
├── pyproject.toml # Package configuration
├── requirements.txt # Dependencies
├── src/
│ ├── __init__.py # Package marker
│ └── main.py # MCP server implementation
└── tests/
└── test_server.py # Test script使用Claude Desktop(本地测试)
使用Claude Desktop测试您的MCP服务器:
- 查找您的Claude Desktop配置文件:
- macOS: ~/Library/Application Support/Claude/claude_desktop_config.json - 窗户: %APPDATA%\Claude\claude_desktop_config.json
- 添加服务器配置:
{
"mcpServers": {
"fast-flights": {
"command": "uv",
"args": ["run", "main"],
"cwd": "/Users/mikey/repos/fast-flights-mcp"
}
}
}- 重新启动克劳德桌面
- 你应该看到一个🔌 指示MCP服务器已连接的图标
- 试着问克劳德:
- “为我找到1月20日从洛杉矶国际机场到旧金山国际机场最便宜的航班” - “3月1日从纽约到伦敦最快的航班是什么?” - “比较从TPE到MYJ的航班选项”
部署到Dedalus
先决条件
- 安装Dedalus命令行界面:
pip install dedalus-labs- 身份验证:
dedalus login部署
# Deploy to Dedalus
dedalus deploy . --name "fast-flights-mcp"使用已部署的服务器
from dedalus_labs import AsyncDedalus, DedalusRunner
async def main():
client = AsyncDedalus(api_key="your-api-key")
runner = DedalusRunner(client)
result = await runner.run(
input="Find me the cheapest flight from LAX to NYC on January 20th",
model="claude-3-5-sonnet-20241022",
mcp_servers=["your-org/fast-flights-mcp"]
)
print(result.final_output)运作原理
- AI代理请求:您的AI代理收到关于航班的自然语言请求
- 工具选择:MCP框架确定了使用哪种航班搜索工具
- API调用:服务器调用
fast-flights具有适当参数的库 - 数据处理:对结果进行格式化和分析
- 响应:结构化飞行数据返回给AI代理
- 自然语言:人工智能将结果格式化为用户友好的响应
飞行数据字段
结果中的每个航班包括:
name:航空公司和航班号departure:出发时间arrival:到达时间departure_time_ahead:出发前的时间(如有)arrival_time_ahead:到达前的时间(如有)duration:总飞行时间(分钟)stops:停车次数(0=直达)price:每人价格is_best:此航班是否标记为推荐选项delay:延迟信息(如有)
机场代码
使用国际航空运输协会标准机场代码:
- 洛杉矶国际机场 -洛杉矶国际
- 约翰·F·肯尼迪 -约翰·肯尼迪国际(纽约)
- 旧金山国际机场 -旧金山国际
- 左心室 -伦敦希思罗机场
- TPE -台湾桃园国际
- MYJ -松山机场(日本)
完整列表:https://en.wikipedia.org/wiki/IATA_airport_code
故障排除
问题:“未找到航班”
- 检查机场代码是否为有效的IATA代码
- 验证日期是否为未来日期,并采用YYYY-MM-DD格式
- 确保路线得到普遍服务
问题:服务器无法启动
- 确保安装了所有依赖项:
uv sync - 检查Python版本:
python --version(要求3.10+) - 验证
fast-flights图书馆正在工作:uv run python -c "import fast_flights; print('OK')"
问题:部署失败
- 确保
pyproject.toml已正确配置 - 检查一下
main.py存在于根级别 - 验证是否列出了所有依赖项
requirements.txt
高级用法
多阶段飞行计划
# Stage 1: Find cheapest option
result1 = await runner.run(
input="Find the cheapest flight from LAX to NYC on Jan 20",
model="openai/gpt-4o-mini",
mcp_servers=["your-org/fast-flights-mcp"]
)
# Stage 2: Compare with fastest option
result2 = await runner.run(
input=f"Based on this cheapest option: {result1.final_output}, now compare it with the fastest flight for the same route and date",
model="claude-3-5-sonnet-20241022",
mcp_servers=["your-org/fast-flights-mcp"]
)
# Stage 3: Make recommendation
result3 = await runner.run(
input=f"Based on these options: {result2.final_output}, recommend the best choice for a business traveler who values time over cost",
model="openai/gpt-4"
)批处理
routes = [
("LAX", "JFK", "2025-01-20"),
("LAX", "SFO", "2025-01-21"),
("JFK", "LHR", "2025-01-22")
]
tasks = []
for from_airport, to_airport, date in routes:
task = runner.run(
input=f"Find best price from {from_airport} to {to_airport} on {date}",
model="openai/gpt-4o-mini",
mcp_servers=["your-org/fast-flights-mcp"]
)
tasks.append(task)
results = await asyncio.gather(*tasks)贡献
欢迎投稿!请随时提交拉取请求。
许可证
麻省理工学院
资源
支持
对于问题或疑问:
- 在GitHub上打开一个问题
- 查看快速航班文件
- 查看MCP服务器示例
______________________________________________________________________
内置❤️ 使用模型上下文协议
