mcp-server-weather-forecast
Get weather forecasts using an AI agent and an MCP server.
1
Github Watches
0
Github Forks
0
Github Stars
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+
-
collections -
datetime -
typing -
asyncio -
json -
httpx -
mcp.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
相关推荐
I find academic articles and books for research and literature reviews.
Confidential guide on numerology and astrology, based of GG33 Public information
Advanced software engineer GPT that excels through nailing the basics.
Emulating Dr. Jordan B. Peterson's style in providing life advice and insights.
Your go-to expert in the Rust ecosystem, specializing in precise code interpretation, up-to-date crate version checking, and in-depth source code analysis. I offer accurate, context-aware insights for all your Rust programming questions.
Converts Figma frames into front-end code for various mobile frameworks.
Take an adjectivised noun, and create images making it progressively more adjective!
Discover the most comprehensive and up-to-date collection of MCP servers in the market. This repository serves as a centralized hub, offering an extensive catalog of open-source and proprietary MCP servers, complete with features, documentation links, and contributors.
The all-in-one Desktop & Docker AI application with built-in RAG, AI agents, No-code agent builder, MCP compatibility, and more.
Fair-code workflow automation platform with native AI capabilities. Combine visual building with custom code, self-host or cloud, 400+ integrations.
Micropython I2C-based manipulation of the MCP series GPIO expander, derived from Adafruit_MCP230xx
🧑🚀 全世界最好的LLM资料总结(Agent框架、辅助编程、数据处理、模型训练、模型推理、o1 模型、MCP、小语言模型、视觉语言模型) | Summary of the world's best LLM resources.
Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
Reviews
user_ekqUts1L
I've been using the mcp-server-weather-forecast by hitechdk, and it has been outstanding. It provides accurate and timely weather updates, making it an essential tool for planning my daily activities. The user-friendly interface and reliable performance make it a must-have for anyone interested in weather forecasting. Highly recommend!