get_weather_details
Retrieve current weather data and optional 24-hour forecast for any city in structured JSON format for programmatic analysis and processing.
Instructions
Get detailed weather information for a specified city as structured JSON data. This tool provides raw weather data for programmatic analysis and processing.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| city | Yes | The name of the city to fetch weather information for, PLEASE NOTE English name only, if the parameter city isn't English please translate to English before invoking this function. | |
| include_forecast | No | Whether to include forecast data (next 24 hours) |
Implementation Reference
- The run_tool method of GetWeatherDetailsToolHandler that executes the tool logic: fetches current weather data for the city, optionally includes 24h forecast, returns structured JSON or error.async def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]: """ Execute the detailed weather tool. """ try: self.validate_required_args(args, ["city"]) city = args["city"] include_forecast = args.get("include_forecast", False) logger.info(f"Getting detailed weather for: {city} (forecast: {include_forecast})") # Get current weather data weather_data = await self.weather_service.get_current_weather(city) # If forecast is requested, get the next 24 hours if include_forecast: from datetime import datetime, timedelta today = datetime.now().strftime("%Y-%m-%d") tomorrow = (datetime.now() + timedelta(days=1)).strftime("%Y-%m-%d") forecast_data = await self.weather_service.get_weather_by_date_range( city, today, tomorrow ) weather_data["forecast"] = forecast_data["weather_data"] return [ TextContent( type="text", text=json.dumps(weather_data, indent=2) ) ] except ValueError as e: logger.error(f"Weather service error: {str(e)}") return [ TextContent( type="text", text=json.dumps({"error": str(e)}, indent=2) ) ] except Exception as e: logger.exception(f"Unexpected error in get_weather_details: {str(e)}") return [ TextContent( type="text", text=json.dumps({"error": f"Unexpected error occurred: {str(e)}"}, indent=2) ) ]
- Input schema definition in get_tool_description: object with required 'city' (string) and optional 'include_forecast' (boolean, default false).inputSchema={ "type": "object", "properties": { "city": { "type": "string", "description": "The name of the city to fetch weather information for, PLEASE NOTE English name only, if the parameter city isn't English please translate to English before invoking this function." }, "include_forecast": { "type": "boolean", "description": "Whether to include forecast data (next 24 hours)", "default": False } }, "required": ["city"] }
- src/mcp_weather_server/server.py:88-88 (registration)The add_tool_handler call in register_all_tools() that registers the GetWeatherDetailsToolHandler instance with the server's tool registry.add_tool_handler(GetWeatherDetailsToolHandler())
- src/mcp_weather_server/server.py:30-30 (registration)Import of GetWeatherDetailsToolHandler from tools_weather.py in server.py.GetWeatherDetailsToolHandler,