Skip to main content
Glama
isdaniel

Weather MCP Server

get_weather_details

Retrieve structured weather data for programmatic analysis by specifying a city name. Provides current conditions and optional 24-hour forecast in JSON format.

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
NameRequiredDescriptionDefault
cityYesThe 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_forecastNoWhether to include forecast data (next 24 hours)

Implementation Reference

  • The `run_tool` method of `GetWeatherDetailsToolHandler` that executes the tool logic: validates input, fetches current weather data (and optional forecast), formats as JSON, handles errors.
    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) ) ]
  • The `get_tool_description` method defining the tool's metadata, description, and input schema requiring 'city' (string) and optional 'include_forecast' (boolean).
    def get_tool_description(self) -> Tool: """ Return the tool description for detailed weather lookup. """ return Tool( name=self.name, description="""Get detailed weather information for a specified city as structured JSON data. This tool provides raw weather data for programmatic analysis and processing.""", 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"] } )
  • Registration of the `GetWeatherDetailsToolHandler` instance in the `register_all_tools` function via `add_tool_handler`.
    add_tool_handler(GetWeatherDetailsToolHandler())
  • Constructor of `GetWeatherDetailsToolHandler` setting the tool name to 'get_weather_details' and initializing WeatherService.
    def __init__(self): super().__init__("get_weather_details") self.weather_service = WeatherService()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/isdaniel/mcp_weather_server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server