Weather MCP Server
by suryatc547
README.md
# Weather Intelligence Assistant
An AI-powered weather assistant built with a standalone Python **[FastMCP](https://gofastmcp.com/)** server backed by **[Open-Meteo](https://open-meteo.com/)** (via async **HTTPX**) and a **[Google ADK](https://google.github.io/adk-docs/)** (`LlmAgent` + `McpToolset`) client application communicating over **Streamable HTTP**.
---
## Key Features
- **Decoupled MCP Architecture:** `weather_mcp_server` exposes weather capabilities independently over Streamable HTTP; `weather_adk_agent` consumes them solely through `McpToolset` and never calls Open-Meteo directly.
- **Dynamic Geocoding & Disambiguation:** Resolves city names dynamically via Open-Meteo Geocoding (no hardcoded coordinates) and surfaces multiple matching locations instead of silently guessing.
- **Current, Daily & Hourly Weather:** Supports current conditions, 1–7 day daily forecasts, and 1–168 hour hourly forecasts using `timezone=auto` and human-readable WMO weather code descriptions.
- **Resilient Async HTTP Layer:** Uses `httpx.AsyncClient` with explicit 10s timeouts, bounded exponential backoff on transient failures (`429`, 5xx, timeouts), 15-minute geocoding TTL cache, and `None`-vs-`0` preservation.
- **Safe Error Handling:** Masks internal exception details (`mask_error_details=True`) while returning clear, actionable `ToolError` messages for invalid bounds, unknown cities, or ambiguous locations.
- **Cross-Agent Repository Instructions:** Includes `AGENTS.md`, `.github/copilot-instructions.md`, scoped `.github/instructions/`, and `.agents/skills/` for Antigravity, GitHub Copilot, and OpenCode.
---
## Architecture
```text
User Question
│
▼
Google ADK LlmAgent (Gemini)
weather_adk_agent/
│
▼
McpToolset (StreamableHTTPConnectionParams)
│ Streamable HTTP (http://localhost:8080/mcp)
▼
Weather MCP Server (FastMCP)
weather_mcp_server/
├── search_location
├── get_current_weather
├── get_weather_forecast
└── get_hourly_forecast
│
▼
Async Service Layer (HTTPX + WMO mapping + TTL cache)
├── Open-Meteo Geocoding API
└── Open-Meteo Forecast API
```
---
## Project Structure
```text
weather-intelligence/
├── weather_mcp_server/
│ ├── __init__.py
│ ├── server.py # FastMCP initialization & Streamable HTTP entrypoint
│ ├── tools/
│ │ ├── _common.py # Shared error translation & read-only annotations
│ │ ├── location.py # search_location tool
│ │ ├── current_weather.py # get_current_weather tool
│ │ └── forecast.py # get_weather_forecast & get_hourly_forecast tools
│ ├── services/
│ │ ├── errors.py # Domain exception hierarchy
│ │ ├── http_client.py # Async HTTPX client with timeout & bounded retries
│ │ ├── geocoding.py # Open-Meteo Geocoding client, cache & disambiguation
│ │ └── weather_api.py # Current, daily & hourly normalization
│ └── utils/
│ └── weather_codes.py # WMO weather code -> readable condition mapping
├── weather_adk_agent/
│ ├── __init__.py # Exports agent module for ADK CLI/Web discovery
│ ├── agent.py # LlmAgent + McpToolset (StreamableHTTPConnectionParams)
│ └── prompts.py # System instructions separated from agent wiring
├── tests/
│ ├── test_location.py # Geocoding, disambiguation & WMO code unit tests
│ ├── test_current_weather.py # Current weather normalization & null-vs-zero tests
│ ├── test_forecast.py # Daily/hourly forecast & bounds validation tests
│ ├── test_mcp_server.py # FastMCP in-memory Client tool & error tests
│ └── test_adk_agent.py # ADK root_agent & McpToolset wiring tests
├── .agents/skills/ # Installed skills.sh & project-local Agent Skills
├── .github/ # VS Code Copilot instructions & scoped rules
├── AGENTS.md # Universal instructions for Antigravity, Copilot & OpenCode
├── .env.example # Environment variable template (no real secrets)
├── pyproject.toml # uv project manifest & pytest config
├── uv.lock # Locked dependencies
└── LICENSE # MIT License
```
For the full design roadmap, see [weather_mcp_google_adk_integration_plan.md](./weather_mcp_google_adk_integration_plan.md).
---
## MCP Tools Reference
All four tools are annotated as read-only (`readOnlyHint=True`, `destructiveHint=False`, `idempotentHint=True`, `openWorldHint=True`).
| Tool | Parameters | Validation / Bounds | Returns |
| :--- | :--- | :--- | :--- |
| `search_location` | `city` (required), `country` (optional) | Non-empty `city` | `matches` list with `name`, `country`, `latitude`, `longitude`, `timezone`, and optional `admin1`/`country_code` |
| `get_current_weather` | `city` (required), `country` (optional) | Non-empty `city`; disambiguates multiple exact matches | `location`, `country`, `temperature`, `feels_like`, `humidity`, `wind_speed`, `precipitation`, `weather_condition`, `timezone`, `observed_at`, `units` |
| `get_weather_forecast` | `city` (required), `days` (`5`), `country` (optional) | `1 <= days <= 7` | `location`, `country`, `timezone`, `forecast[]` (`date`, `temperature_max`, `temperature_min`, `precipitation_probability`, `weather_condition`), `units` |
| `get_hourly_forecast` | `city` (required), `hours` (`12`), `country` (optional) | `1 <= hours <= 168` | `location`, `country`, `timezone`, `hourly_forecast[]` (`time`, `temperature`, `precipitation_probability`, `weather_condition`), `units` |
<details>
<summary>Example tool payload (<code>get_current_weather</code>)</summary>
```json
{
"location": "Bengaluru",
"country": "India",
"temperature": 27.4,
"feels_like": 27.5,
"humidity": 45,
"wind_speed": 8.8,
"precipitation": 0.0,
"weather_condition": "Clear sky",
"timezone": "Asia/Kolkata",
"observed_at": "2026-11-28T16:30",
"admin1": "Karnataka",
"units": {
"temperature": "°C",
"feels_like": "°C",
"humidity": "%",
"wind_speed": "km/h",
"precipitation": "mm"
}
}
```
</details>
---
## Prerequisites & Installation
- **Python** `>= 3.14`
- **[uv](https://docs.astral.sh/uv/)** package manager
- A **Gemini API key** (`GOOGLE_API_KEY`) for running the Google ADK agent (Open-Meteo public endpoints require no API key)
1. **Clone and install dependencies:**
```bash
git clone https://github.com/suryatc547/weather-mcp-google-adk.git
cd weather-mcp-google-adk
uv sync
```
2. **Configure environment variables:**
```bash
cp .env.example .env
```
Edit `.env` and set your `GOOGLE_API_KEY`.
### Environment Variables
| Variable | Default | Purpose |
| :--- | :--- | :--- |
| `GOOGLE_API_KEY` | — | Required by Gemini / Google ADK |
| `GEMINI_MODEL` | `gemini-2.5-flash` | Gemini model ID used by `root_agent` |
| `MCP_SERVER_URL` | `http://localhost:8080/mcp` | Streamable HTTP URL consumed by `McpToolset` |
| `WEATHER_API_BASE_URL` | `https://api.open-meteo.com/v1/forecast` | Open-Meteo Forecast API endpoint |
| `GEOCODING_API_BASE_URL` | `https://geocoding-api.open-meteo.com/v1/search` | Open-Meteo Geocoding API endpoint |
| `MCP_HOST` | `0.0.0.0` | Host interface bound by the FastMCP server |
| `PORT` / `MCP_PORT` | `8080` | Port bound by the FastMCP server (`PORT` takes precedence) |
| `MCP_PATH` | `/mcp` | Streamable HTTP mount path |
---
## Running the Application
### 1. Start the Weather MCP Server
```bash
uv run python -m weather_mcp_server.server
```
The server starts on `http://localhost:8080/mcp` using Streamable HTTP transport.
### 2. Test the MCP Server Independently (FastMCP CLI)
In a second terminal:
```bash
# List all registered tools
uv run python -m fastmcp.cli list http://localhost:8080/mcp --auth none
# Call tools directly
uv run python -m fastmcp.cli call http://localhost:8080/mcp search_location city=Bengaluru country=India --auth none
uv run python -m fastmcp.cli call http://localhost:8080/mcp get_current_weather city=Bengaluru country=India --auth none
uv run python -m fastmcp.cli call http://localhost:8080/mcp get_weather_forecast city=Chennai country=India days=5 --auth none
uv run python -m fastmcp.cli call http://localhost:8080/mcp get_hourly_forecast city=Mumbai country=India hours=12 --auth none
```
### 3. Run the Google ADK Agent
With the MCP server still running in Terminal 1, launch the ADK CLI or Web UI in Terminal 2:
```bash
# Interactive terminal session
uv run python -m google.adk.cli run weather_adk_agent
# Browser developer UI
uv run python -m google.adk.cli web .
```
**Example prompts to try:**
- *"What's the weather in Bengaluru right now?"*
- *"Give me a 5-day forecast for Chennai."*
- *"Will it rain in Mumbai over the next 12 hours?"*
- *"Compare the current weather in Bengaluru and Hyderabad, India."*
> **Windows note:** If Windows Application Control (`os error 4551`) blocks `.venv\Scripts\*.exe` wrappers (`adk`, `fastmcp`, `pytest`), invoke them via `uv run python -m ...` as shown above.
---
## Testing
Run the offline unit and in-memory FastMCP integration suite (uses mocked HTTPX transports so tests run deterministically without network calls):
```bash
uv run python -m pytest -v
```
Run with coverage reporting:
```bash
uv run --with pytest-cov python -m pytest --cov=weather_mcp_server --cov=weather_adk_agent --cov-report=term-missing -v
```
---
## AI Coding Agent Support
This repository includes shared instructions and portable [Agent Skills](https://skills.sh/) so **Antigravity**, **VS Code Copilot**, and **OpenCode** follow the same architecture and engineering rules automatically:
- [AGENTS.md](./AGENTS.md) — Universal instructions for Antigravity, OpenCode, and Copilot.
- [.github/copilot-instructions.md](./.github/copilot-instructions.md) & [.github/instructions/](./.github/instructions/) — Repository-wide and path-scoped Copilot rules.
- [.agents/skills/](./.agents/skills/) (tracked in [skills-lock.json](./skills-lock.json)) — `adk-agent-builder`, `adk-debug`, `fastmcp-server`, `fastmcp-client-cli`, `mcp-builder`, `uv`, and the project-specific `weather-open-meteo` skill.
---
## License
This project is licensed under the [MIT License](./LICENSE).
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues