Skip to main content
Glama

get_historical_weather

Retrieve past weather conditions from Japan Meteorological Agency stations by specifying a station code and datetime within the last 1-2 weeks.

Instructions

Get historical weather data for a specific date and time.

Data is available for approximately the past 1-2 weeks.

Args: station_code: Station code (e.g., '44132' for Tokyo) target_datetime: Target datetime in ISO format (e.g., '2025-12-01T12:00:00') or 'YYYY-MM-DD HH:MM' format. Time is in JST.

Returns: Weather data for the specified time

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
station_codeYes
target_datetimeYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The MCP tool handler for get_historical_weather. Parses the target_datetime, fetches historical data using fetch_historical_amedas_data, adds station information, and returns the result. Also serves as registration via @mcp.tool() decorator.
    @mcp.tool()
    async def get_historical_weather(
        station_code: str,
        target_datetime: str,
    ) -> dict:
        """Get historical weather data for a specific date and time.
    
        Data is available for approximately the past 1-2 weeks.
    
        Args:
            station_code: Station code (e.g., '44132' for Tokyo)
            target_datetime: Target datetime in ISO format (e.g., '2025-12-01T12:00:00')
                             or 'YYYY-MM-DD HH:MM' format. Time is in JST.
    
        Returns:
            Weather data for the specified time
        """
        try:
            if "T" in target_datetime:
                target_time = datetime.fromisoformat(target_datetime.replace("Z", "+00:00"))
            else:
                for fmt in ["%Y-%m-%d %H:%M", "%Y-%m-%d %H:%M:%S", "%Y/%m/%d %H:%M"]:
                    try:
                        target_time = datetime.strptime(target_datetime, fmt)
                        break
                    except ValueError:
                        continue
                else:
                    raise ValueError(f"Could not parse datetime: {target_datetime}")
    
            if target_time.tzinfo is None:
                target_time = target_time.replace(tzinfo=JST)
    
        except Exception as e:
            return {
                "error": f"Invalid datetime format: {e}",
                "hint": "Use ISO format (e.g., '2025-12-01T12:00:00') or 'YYYY-MM-DD HH:MM'",
            }
    
        historical_data = await fetch_historical_amedas_data(station_code, target_time)
    
        station_info = get_station(station_code)
        if station_info:
            historical_data["station_info"] = station_info
    
        return historical_data
  • Helper function that performs the core logic: rounds time to 10-min interval, fetches JSON data from JMA AMeDAS API, parses the station data using _parse_station_data, and formats the response.
    async def fetch_historical_amedas_data(
        station_code: str,
        target_time: datetime
    ) -> dict[str, Any]:
        """
        Fetch historical AMeDAS data for a specific time.
    
        Args:
            station_code: Station code (e.g., '44132' for Tokyo)
            target_time: Target datetime (available for approximately past 1-2 weeks)
    
        Returns:
            Dictionary with observation data for the specified time
        """
        # Round to 10-minute intervals
        target_time = target_time.replace(
            minute=(target_time.minute // 10) * 10,
            second=0,
            microsecond=0
        )
    
        time_str = format_time_for_api(target_time)
        url = f'https://www.jma.go.jp/bosai/amedas/data/map/{time_str}.json'
    
        async with httpx.AsyncClient() as client:
            response = await client.get(url, timeout=30.0)
            response.raise_for_status()
            raw_data = response.json()
    
        station_data = raw_data.get(station_code)
        if station_data is None:
            return {
                "error": f"No data found for station {station_code} at {target_time.isoformat()}",
                "observation_time": target_time.isoformat()
            }
    
        result = {
            "observation_time": target_time.isoformat(),
            "observation_time_jst": target_time.strftime('%Y-%m-%d %H:%M JST'),
            "station_code": station_code,
            "data": _parse_station_data(station_code, station_data)
        }
    
        return result
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It adds useful context about data availability ('past 1-2 weeks') and timezone information ('Time is in JST'), but doesn't mention important behavioral aspects like rate limits, authentication requirements, error conditions, or what specific weather data fields are returned.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (purpose statement, data availability note, Args, Returns) and uses bullet-like formatting. It's appropriately sized with no wasted sentences, though the 'Returns' section could be more informative given the output schema exists.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has an output schema (which handles return values), 2 parameters with good description coverage in the text, and moderate complexity, the description is reasonably complete. It covers purpose, data constraints, parameter details, and basic return information, though it could benefit from more behavioral context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description provides excellent parameter semantics beyond the schema, which has 0% description coverage. It explains 'station_code' with an example ('e.g., '44132' for Tokyo') and 'target_datetime' with format details and timezone clarification. This fully compensates for the schema's lack of descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose as 'Get historical weather data for a specific date and time', which is a specific verb+resource combination. However, it doesn't explicitly differentiate from sibling tools like 'get_current_weather' or 'get_weather_time_series', which likely serve related but distinct purposes.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides some context with 'Data is available for approximately the past 1-2 weeks', which implies when to use this tool (for recent historical data). However, it doesn't explicitly state when to use alternatives like 'get_current_weather' for current data or 'get_weather_time_series' for multiple time points, leaving usage guidance incomplete.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/koizumikento/jma-data-mcp'

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