Weather Forecast Tool

Weather Forecast Tool

site icon
2025.04.04 0
Python天气预测位置服务位置服务
mcp-server-weather-forecast 是一个基于 Python 的天气预测工具,利用 MET Norway API 获取指定位置的天气数据,并通过 FastMCP 框架进行工具注册和异步 HTTP 请求处理。该工具能够获取天气预测数据,并提供每日天气摘要,包括天气符号、最低和最高温度等信息。
View on GitHub

Overview

基本能力

产品定位

mcp-server-weather-forecast 是一个天气预测服务工具,主要用于获取和汇总指定位置的天气数据。

核心功能

  • 天气预测:通过 get_weather 函数获取指定经纬度的天气预测数据。
  • 每日摘要:通过 summarize_daily_timeseries_most_occurrences 函数处理原始预测数据,提供每日天气摘要,包括天气符号、最低和最高温度等信息。
  • HTTP 请求:通过 make_net_request 函数处理异步 HTTP 请求。
  • 天气符号映射:通过 map_weather_symbol 函数将天气符号代码转换为人类可读的描述。

适用场景

  • 需要获取特定位置天气预测数据的应用。
  • 需要每日天气摘要的应用。
  • 需要异步处理 HTTP 请求的应用。

工具列表

  • get_weather(latitude: float, longitude: float) -> str:获取并格式化指定位置的天气预测数据。

常见问题解答

  • 无特定常见问题解答。

使用教程

使用依赖

  • Python 3.13+
  • collections
  • datetime
  • typing
  • asyncio
  • json
  • httpx
  • mcp.server.fastmcp

安装教程

  1. 安装依赖# Install MCP and other dependencies as needed (see [MCP documentation](https://github.com/modelcontextprotocol/python-sdk))

  2. 获取坐标:需要获取目标位置的经纬度。

调试方式

  1. 导入模块: ```python 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") ```

  1. 使用 get_weather 工具: ```python async def main(): weather_data = await get_weather(55.6761, 12.5683) # Example: Copenhagen, Denmark print(weather_data)

if name == "main": asyncio.run(main()) `` 替换55.676112.5683` 为目标位置的经纬度。

许可证

该项目遵循 MIT 开源许可条款。