Skip to main content
Glama
isdaniel

Weather MCP Server

get_weather_byDateTimeRange

Retrieve weather data for any city across a specified date range to plan activities or analyze historical conditions.

Instructions

Get weather information for a specified city between start and end dates.

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.
end_dateYesEnd date in format YYYY-MM-DD , please follow ISO 8601 format
start_dateYesStart date in format YYYY-MM-DD, please follow ISO 8601 format

Implementation Reference

  • The `run_tool` method of `GetWeatherByDateRangeToolHandler` that implements the core logic of the `get_weather_byDateTimeRange` tool. It validates arguments, fetches weather data for the specified city and date range using `WeatherService`, formats the response, and returns it as text content.
    async def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]: """ Execute the weather date range tool. """ try: self.validate_required_args(args, ["city", "start_date", "end_date"]) city = args["city"] start_date = args["start_date"] end_date = args["end_date"] logger.info(f"Getting weather for {city} from {start_date} to {end_date}") # Get weather data from service weather_data = await self.weather_service.get_weather_by_date_range( city, start_date, end_date ) # Format the response for analysis formatted_response = self.weather_service.format_weather_range_response(weather_data) return [ TextContent( type="text", text=formatted_response ) ] except ValueError as e: logger.error(f"Weather service error: {str(e)}") return [ TextContent( type="text", text=f"Error: {str(e)}" ) ] except Exception as e: logger.exception(f"Unexpected error in get_weather_by_date_range: {str(e)}") return [ TextContent( type="text", text=f"Unexpected error occurred: {str(e)}" ) ]
  • The `get_tool_description` method defines the tool's metadata, including the input schema requiring `city`, `start_date`, and `end_date` parameters with their types and descriptions.
    def get_tool_description(self) -> Tool: """ Return the tool description for weather date range lookup. """ return Tool( name=self.name, description="""Get weather information for a specified city between start and end dates.""", 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." }, "start_date": { "type": "string", "description": "Start date in format YYYY-MM-DD, please follow ISO 8601 format" }, "end_date": { "type": "string", "description": "End date in format YYYY-MM-DD , please follow ISO 8601 format" } }, "required": ["city", "start_date", "end_date"] } )
  • The `register_all_tools` function instantiates `GetWeatherByDateRangeToolHandler` (line 87) and registers it via `add_tool_handler`, making the tool available to the MCP server.
    def register_all_tools() -> None: """ Register all available tool handlers. This function serves as the central registry for all tools. New tool handlers should be added here for automatic registration. """ # Weather tools add_tool_handler(GetCurrentWeatherToolHandler()) add_tool_handler(GetWeatherByDateRangeToolHandler()) add_tool_handler(GetWeatherDetailsToolHandler()) # Time tools add_tool_handler(GetCurrentDateTimeToolHandler()) add_tool_handler(GetTimeZoneInfoToolHandler()) add_tool_handler(ConvertTimeToolHandler()) # Air quality tools add_tool_handler(GetAirQualityToolHandler()) add_tool_handler(GetAirQualityDetailsToolHandler()) logger.info(f"Registered {len(tool_handlers)} tool handlers")

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