An AI agent that uses Model Context Protocol (MCP) to connect to a live weather data source, retrieves structured meteorological data, and uses Google ADK (Agent Development Kit) + Gemini 2.0 Flash to generate human-friendly weather reports.
User Request
│
▼
FastAPI Server (main.py)
│
▼
Google ADK LlmAgent ←──── Gemini 2.0 Flash (LLM)
│
│ MCP stdio transport
▼
Weather MCP Server (mcp_server/weather_mcp_server.py)
│
│ HTTP (httpx)
▼
Open-Meteo API ──→ Geocoding API
──→ Forecast API (current + 5-day)
| Component | Role |
|---|---|
| Google ADK | Orchestrates the agent loop, manages tool calls |
| MCP Server | Exposes get_weather tool via stdio transport |
| Open-Meteo | Free, no-API-key weather data (global coverage) |
| FastAPI | REST API + web UI server |
| Cloud Run | Serverless Google Cloud deployment |
weather-mcp-agent/
├── main.py # FastAPI server + API endpoints
├── agent/
│ └── weather_agent.py # Google ADK agent definition
├── mcp_server/
│ └── weather_mcp_server.py # MCP server exposing get_weather tool
├── static/
│ └── index.html # Frontend web UI
├── requirements.txt
├── Dockerfile
├── deploy.sh # One-command Cloud Run deploy
├── .env.example # Environment variable template
└── .gitignore
- Python 3.11 or 3.12
- VS Code with Python extension
- A Google API Key (for Gemini / ADK)
Open the weather-mcp-agent/ folder in VS Code:
File → Open Folder → weather-mcp-agent/
Open the VS Code terminal (Ctrl+`` ``) and run:
python -m venv .venvActivate it:
- Windows:
.venv\Scripts\activate - Mac/Linux:
source .venv/bin/activate
VS Code should auto-detect the venv. If prompted, click "Yes" to use it as the workspace interpreter.
pip install -r requirements.txtcp .env.example .envEdit .env and set your key:
GOOGLE_API_KEY=AIza...your-key-hereGet a key at: https://aistudio.google.com/app/apikey (free tier works)
python main.pyOr use the VS Code Run button if you have a launch config. The server starts on http://localhost:8080
Visit http://localhost:8080 in your browser — you'll see the WeatherWise UI.
Or test via curl:
curl -X POST http://localhost:8080/api/weather \
-H "Content-Type: application/json" \
-d '{"city": "Bengaluru"}'Create .vscode/launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Run WeatherWise",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/main.py",
"envFile": "${workspaceFolder}/.env",
"console": "integratedTerminal"
}
]
}Run the agent from the CLI (bypasses FastAPI):
python agent/weather_agent.py "Tokyo"
python agent/weather_agent.py "London"Test raw weather data (no LLM required):
curl http://localhost:8080/api/raw-weather/Mumbai- Google Cloud account with a project
gcloudCLI installed: https://cloud.google.com/sdk/docs/install- Docker installed (for local builds) or Cloud Build enabled
export GOOGLE_CLOUD_PROJECT=your-project-id
export GOOGLE_API_KEY=your-google-api-key
export GOOGLE_CLOUD_REGION=us-central1 # or asia-south1 for Indiagcloud auth login
gcloud config set project $GOOGLE_CLOUD_PROJECTchmod +x deploy.sh
./deploy.shThis script automatically:
- Enables required Google Cloud APIs
- Builds the Docker image via Cloud Build
- Pushes to Google Container Registry
- Deploys to Cloud Run with your API key
- Prints the live Cloud Run URL
# Replace with your actual Cloud Run URL
curl -X POST https://weatherwise-agent-xxxx-uc.a.run.app/api/weather \
-H "Content-Type: application/json" \
-d '{"city": "Bengaluru"}'# Build image
gcloud builds submit --tag gcr.io/$GOOGLE_CLOUD_PROJECT/weatherwise-agent .
# Deploy
gcloud run deploy weatherwise-agent \
--image gcr.io/$GOOGLE_CLOUD_PROJECT/weatherwise-agent \
--platform managed \
--region us-central1 \
--allow-unauthenticated \
--memory 512Mi \
--set-env-vars "GOOGLE_API_KEY=$GOOGLE_API_KEY"The MCP server exposes one tool:
| Parameter | Type | Required | Description |
|---|---|---|---|
city |
string | ✅ | City name (e.g. "Bengaluru", "Tokyo") |
Returns:
{
"location": { "city": "Bengaluru", "country": "India", "latitude": 12.97, "longitude": 77.59 },
"current": {
"temperature_c": 24.5,
"feels_like_c": 25.1,
"humidity_pct": 68,
"wind_speed_kmh": 12.4,
"wind_direction_deg": 270,
"precipitation_mm": 0.0,
"pressure_hpa": 1013.2,
"uv_index": 6,
"condition": "Partly cloudy"
},
"forecast_5_days": [...]
}| Method | Endpoint | Description |
|---|---|---|
GET |
/ |
Web UI |
GET |
/health |
Health check |
POST |
/api/weather |
AI-generated weather report |
GET |
/api/raw-weather/{city} |
Raw weather data (no LLM) |
- Agent startup:
MCPToolsetlaunches the MCP server as a subprocess via stdio - Tool discovery: ADK queries the MCP server for available tools (
list_tools) - LLM decides: Gemini sees the tool schema and decides to call
get_weather - Tool call: ADK sends the call via MCP protocol → server fetches from Open-Meteo
- Response: Structured JSON weather data flows back to the agent
- Report: Gemini uses the data to craft a detailed, friendly weather report
- Implemented using Google ADK
- Uses MCP to connect to one tool (Weather via Open-Meteo)
- Retrieves structured data (current conditions + 5-day forecast)
- Uses retrieved data to generate the final response
- Deployable to Google Cloud Run
- Runnable locally in VS Code
- Go to https://aistudio.google.com/app/apikey
- Click "Create API Key"
- Copy the key and paste it into
.env
The free tier includes generous Gemini 2.0 Flash usage.
MIT — feel free to use and extend.