mcp-server-weather-forecast
Get weather forecasts using an AI agent and an MCP server.
Documentation
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_weather` function retrieves weather forecast data for a specified latitude and longitude.
- Daily Summary: The `summarize_daily_timeseries_most_occurrences` function processes the raw forecast data to provide a concise daily summary, including:
- HTTP Requests: The `make_net_request` function handles asynchronous HTTP requests to the MET Norway API.
- Weather Symbol Mapping: The `map_weather_symbol` function translates weather symbol codes from the API into human-readable descriptions.
Dependencies
- Python 3.13+
- `collections`
- `datetime`
- `typing`
- `asyncio`
- `json`
- `httpx`
- `mcp.server.fastmcp`
Setup
1. Install Dependencies:
# Install MCP and other dependencies as needed (see MCP documentation)
2. **Obtain Coordinates:** You'll need the latitude and longitude for the location you want the weather forecast for.
## Usage
1. **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")
2. **Use the `get_weather` tool:**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.6761` and `12.5683` with 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
[MIT License](https://opensource.org/license/mit)Frequently asked questions
What is mcp-server-weather-forecast?
mcp-server-weather-forecast is Get weather forecasts using an AI agent and an MCP server.
How do I install mcp-server-weather-forecast?
Open the GitHub repository and follow its README. Most MCP servers are added to your client's MCP config, then called by your agent.
Is mcp-server-weather-forecast open source?
Yes — it is hosted on GitHub at https://github.com/hitechdk/mcp-server-weather-forecast and has 1 stars.
Related MCP tools
🙌 OpenHands: Code Less, Make More for the Model Context Protocol. Enhance AI assistants with powerful integrations. Python-based implementation.
Universal memory layer for AI Agents; Announcing OpenMemory MCP - local and secure memory management. Python-based implementation.
基于大模型搭建的聊天机器人,同时支持 微信公众号、企业微信应用、飞书、钉钉 等接入,可选择ChatGPT/Claude/DeepSeek/文心一言/讯飞星火/通义千问/ Gemini/GLM-4/Kimi/LinkAI,能处理文本、语音和图片,访问操作系统和互联网,支持基于自有知识库进行定制企业智能客服。
An LLM agent that conducts deep research (local and web) on any given topic and generates a long report with citations. Built for the Model Context Protocol to
🚀 The fast, Pythonic way to build MCP servers and clients Trusted by 19900+ developers. Trusted by 19900+ developers. Trusted by 19900+ developers.
🔥 MaxKB is an open-source platform for building enterprise-grade agents. MaxKB 是强大易用的开源企业级智能体平台。 for the Model Context Protocol. Enhance AI assistants with po
Run your own MCP server? See who uses it and what to fix.
Measure it with TrackMCP