Cover image
Try Now
2025-04-04

使用AI代理和MCP服务器获得天气预报。

3 years

Works with Finder

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_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:

    • 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_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

相关推荐

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • lumpenspace
  • Take an adjectivised noun, and create images making it progressively more adjective!

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Lists Tailwind CSS classes in monospaced font

  • tomoyoshi hirata
  • Sony α7IIIマニュアルアシスタント

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • apappascs
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • jae-jae
  • MCP服务器使用剧作《无头浏览器》获取网页内容。

  • HiveNexus
  • 一个适用于中小型团队的AI聊天机器人,支持DeepSeek,Open AI,Claude和Gemini等车型。 专为中小团队设计的ai聊天应用,支持deepSeek,打开ai,claude,双子座等模型。

  • ravitemer
  • 一个功能强大的Neovim插件,用于管理MCP(模型上下文协议)服务器

  • patruff
  • Ollama和MCP服务器之间的桥梁,使本地LLMS可以使用模型上下文协议工具

  • pontusab
  • 光标与风浪冲浪社区,查找规则和MCP

  • JackKuo666
  • 🔍使AI助手可以通过简单的MCP接口搜索和访问PYPI软件包信息。

  • av
  • 毫不费力地使用一个命令运行LLM后端,API,前端和服务。

    Reviews

    5 (1)
    Avatar
    user_ekqUts1L
    2025-04-17

    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!