Weather Forecast Tool
Get weather forecasts using an AI agent and an MCP server.
hitechdk
README
Weather Forecast Tool
Description
This Python code provides a tool to fetch and summarize weather forecasts for a given location using the MET Norway API. It leverages the FastMCP framework for tool registration and uses httpx for asynchronous HTTP requests.
Features
-
Weather Forecast: The
get_weatherfunction retrieves weather forecast data for a specified latitude and longitude. -
Daily Summary: The
summarize_daily_timeseries_most_occurrencesfunction processes the raw forecast data to provide a concise daily summary, including:- Most frequent weather symbols for night, morning, afternoon, and evening.
- Minimum and maximum temperatures for the day.
- The forecast will be returned in local time.
-
HTTP Requests: The
make_net_requestfunction handles asynchronous HTTP requests to the MET Norway API. -
Weather Symbol Mapping: The
map_weather_symbolfunction translates weather symbol codes from the API into human-readable descriptions.
Dependencies
- Python 3.13+
collectionsdatetimetypingasynciojsonhttpxmcp.server.fastmcp
Setup
-
Install Dependencies:
Install MCP and other dependencies as needed (see MCP documentation)
-
Obtain Coordinates: You'll need the latitude and longitude for the location you want the weather forecast for.
Usage
-
Import: Import the necessary modules and initialize the FastMCP server.
from collections import Counter from datetime import datetime, timezone, timedelta from mcp.server.fastmcp import FastMCP from typing import Any import asyncio import json import httpx mcp = FastMCP("weather") -
Use the
get_weathertool:async def main(): weather_data = await get_weather(55.6761, 12.5683) # Example: Copenhagen, Denmark print(weather_data) if __name__ == "__main__": asyncio.run(main())Replace
55.6761and12.5683with the desired latitude and longitude.
Tool Definition
* get_weather(latitude: float, longitude: float) -> str
* Retrieves and formats the weather forecast for a given location.
* Arguments:
* latitude (float): The latitude of the location.
* longitude (float): The longitude of the location.
* Returns:
* str: A formatted string containing the daily weather forecast.
MCP
The code uses the FastMCP framework. Please refer to the FastMCP documentation for details on how to set up and run the server.
License
Recommended Servers
Sequential Thinking MCP Server
This server facilitates structured problem-solving by breaking down complex issues into sequential steps, supporting revisions, and enabling multiple solution paths through full MCP integration.
mixpanel
Connect to your Mixpanel data. Query events, retention, and funnel data from Mixpanel analytics.
Crypto Price & Market Analysis MCP Server
A Model Context Protocol (MCP) server that provides comprehensive cryptocurrency analysis using the CoinCap API. This server offers real-time price data, market analysis, and historical trends through an easy-to-use interface.
MCP PubMed Search
Server to search PubMed (PubMed is a free, online database that allows users to search for biomedical and life sciences literature). I have created on a day MCP came out but was on vacation, I saw someone post similar server in your DB, but figured to post mine.
dbt Semantic Layer MCP Server
A server that enables querying the dbt Semantic Layer through natural language conversations with Claude Desktop and other AI assistants, allowing users to discover metrics, create queries, analyze data, and visualize results.
Vectorize
Vectorize MCP server for advanced retrieval, Private Deep Research, Anything-to-Markdown file extraction and text chunking.
Nefino MCP Server
Provides large language models with access to news and information about renewable energy projects in Germany, allowing filtering by location, topic (solar, wind, hydrogen), and date range.
MATLAB MCP Server
Integrates MATLAB with AI to execute code, generate scripts from natural language, and access MATLAB documentation seamlessly.
Macrostrat MCP Server
Enables Claude to query comprehensive geologic data from the Macrostrat API, including geologic units, columns, minerals, and timescales through natural language.
MCP Word Counter
A Model Context Protocol server that provides tools for analyzing text documents, including counting words and characters. This server helps LLMs perform text analysis tasks by exposing simple document statistics functionality.