Overview
File:src/tools/GetWeatherTool.ts
The Weather Tool demonstrates external API integration using the free Open-Meteo API (no API key required).
What It Does
- Fetches real-time weather for any city worldwide
- Two-step process: geocoding + weather data
- Error handling for invalid cities
- No API key or authentication required
Complete Code
Key Concepts
1. Two-Step API Call
Why? Weather APIs need coordinates, but users provide city names.2. URL Encoding
Always encode user input in URLs:3. Error Handling
Check if city exists before proceeding:4. Structured Return
Return organized data, not raw API response:Testing
London- Should workTokyo- Should workNew York- Should workXYZ123- Should fail gracefully
Customization Ideas
Add Temperature Units
Add Weather Recommendations
Add Forecast
What You’ll Learn
External APIs
How to call external REST APIs
Error Handling
Graceful error messages
Data Transformation
Converting API responses to clean output
URL Encoding
Safely encoding user input in URLs

