使用说明
旅行计划MCP服务器
一个多智能体旅行计划系统 谷歌代理开发工具包(ADK) 它通过 模型上下文协议(MCP).
该系统使用 根剂 有两个 分代理 --气象代理和旅行计划代理——创建天气感知的3天旅行行程。这些工具也通过MCP服务器公开,使任何符合MCP的客户端都可以访问它们。
建筑
┌─────────────────────────────────────────────────┐
│ Root Agent │
│ (travel_planner) │
│ │
│ Orchestrates the travel planning workflow: │
│ gather info → check weather → create plan │
│ │
│ ┌─────────────────┐ ┌──────────────────────┐ │
│ │ Weather Agent │ │ Travel Plan Agent │ │
│ │ │ │ │ │
│ │ get_weather() │ │ create_travel_plan()│ │
│ │ (Open-Meteo API)│ │ (itinerary builder) │ │
│ └─────────────────┘ └──────────────────────┘ │
└─────────────────────────────────────────────────┘
▼ exposed via ▼
┌─────────────────────────────────────────────────┐
│ MCP Server (stdio) │
│ │
│ Wraps ADK FunctionTools and exposes them as │
│ MCP tools accessible to any MCP client │
│ │
│ Tools: get_weather, create_travel_plan │
└─────────────────────────────────────────────────┘
项目结构
travel-planner-mcp-server/
├── travel_planner/ # ADK multi-agent package
│ ├── __init__.py
│ ├── agent.py # Root agent (orchestrator with sub-agents)
│ ├── sub_agents/
│ │ ├── __init__.py
│ │ ├── weather_agent.py # Weather specialist sub-agent
│ │ └── travel_plan_agent.py # Travel planning specialist sub-agent
│ └── tools/
│ ├── __init__.py
│ ├── weather_tools.py # Open-Meteo API weather tool
│ └── travel_tools.py # Travel plan generation tool
├── mcp_server.py # MCP server exposing ADK tools
├── adk_client_agent/ # Example ADK agent consuming the MCP server
│ └── mcp_travel_client/
│ ├── __init__.py
│ └── agent.py
├── pyproject.toml
├── requirements.txt
├── .env.example
└── README.md
先决条件
- Python 3.10+
- Google API密钥(用于Gemini模型访问)
设置
-
克隆存储库:
git clone <repo-url> cd travel-planner-mcp-server -
安装依赖项:
pip install -r requirements.txt -
配置环境:
cp .env.example .env # Edit .env and add your Google API key
用法
选项1:直接运行ADK多代理系统
这通过ADK web UI使用根代理及其子代理:
adk web
# Select "travel_planner" in the browser UI
根代理将:
- 询问您的目的地和旅行日期
- 代表到 气象员 获取预报
- 代表到 旅行计划代理 创建行程
- 提出一个全面的3天旅行计划
选项2:运行MCP服务器
这将通过MCP协议公开工具,供任何MCP客户端使用:
python mcp_server.py
MCP服务器公开了两个工具:
get_weather-使用Open-Meteo API获取位置的3天天气预报create_travel_plan--生成结构化的3天旅行行程模板
选项3:运行MCP客户端代理
这演示了使用MCP服务器的ADK代理:
cd adk_client_agent
adk web
# Select "mcp_travel_client" in the browser UI
选项4:从任何MCP客户端连接
添加到您的MCP客户端配置中(例如,Claude Desktop、Cursor等):
{
"mcpServers": {
"travel-planner": {
"command": "python3",
"args": ["/path/to/mcp_server.py"]
}
}
}
工具
get_weather
使用以下工具获取3天天气预报 开放气象API (免费,不需要API密钥)。
参数:
| 参数 | 类型 | 说明 |
|---|---|---|
location |
string | 城市或地名(例如“巴黎”、“东京”) |
date |
string | YYYY-MM-DD格式的开始日期 |
退货: 3天的温度(C/F)、条件、降水量、风速和紫外线指数。
create_travel_plan
生成结构化的3天旅行行程模板。
参数:
| 参数 | 类型 | 说明 |
|---|---|---|
location |
string | 目的地城市或地点 |
start_date |
string | 行程开始日期(YYYY-MM-DD) |
weather_summary |
string | 天气状况摘要 |
interests |
string | 旅游兴趣(默认:“一般观光”) |
退货: 每日行程结构,包括时间段、餐食和提示。
运作原理
该项目展示了 模式2 来自ADK文档: 使用ADK工具构建MCP服务器.
- 腺苷酸激酶
FunctionTool包装Python工具函数 adk_to_mcp_tool_type()将ADK工具模式转换为MCP格式- MCP服务器通过以下方式发布工具
list_tools并通过以下方式执行它们call_tool - 任何MCP客户端都可以通过标准协议发现和调用这些工具
许可证
麻省理工学院