Token导航 LogoToken导航TokenDH.com
LLM model weather info logo
AI代理未说明官方级别未说明来源级核验

LLM model weather info

MCP Server

一个基于MCP协议的天气数据服务,提供实时天气、天气预报和历史天气数据的查询功能。

工具数

2

提示词数

0

GitHub Stars

0

资源数

0
Jupyter Notebook历史数据天气预报位置天气实时数据

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

anuj-kumar-30

提供方

anuj-kumar-30

最后核验

2026/5/17 20:22

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

详细介绍

LLM_模型_死亡_信息

______________________________________________________________________

构建一个简单的MCP服务器,获取实时天气数据,为您提供最新预报,甚至允许您探索历史天气模式

______________________________________________________________________

备注
模型上下文协议(MCP)就像我们人工智能的USB端口。它允许我们的语言模型轻松插入现实世界的工具和API。
无论是获取天气数据、提取财务记录还是自动化任务管理,MCP都规范了LLM与这些工具的交互方式

______________________________________________________________________

分步教程

  1. 使用MCP设置python环境。
  2. 连接到天气API。
  3. 公开有用的工具,如当前天气、预报和历史数据。
  4. 使用MCP检查器测试和检查服务器。

1.建立环境

  • 创建 weather_mcp 说 。
  • cd 进入它
  • 创建 weather_server.py 文件。

2.编写MCP服务器代码

  • 天气MCP服务器将公开用于记录当前天气、预报天气和检索历史天气数据的工具。
from mcp.server.fastmcp import FastMCP
import requests
import json

# OpenWeatherMap API key
API_KEY = "162c5a92ddcc4822bfc66352c54b5deb"
BASE_URL = "http://api.openweathermap.org/data/3.0"

# Create an MCP server with a custom name
mcp = FastMCP("Weather Data Server")

# Function to fetch current weather data
@mcp.tool()
def get_current_weather(city: str) -> str:
    """
    Fetches the current weather for a given city
    """
    try:
        url = f"{BASE_URL}/weather?q={city}&appid={API_KEY}&units=metric"
        response = requests.get(url)
        data = response.json()
        if data.get("cod") != 200:
            return f"Error: {data.get('message')}"
        main_data = data['main']
        weather = data['weather'][0]['description']
        temperature = main_data['temp']
        humidity = main_data['humidity']
        return f"The current weather in {city} is {weather} with a temperature of {temperature}C and humidity of {humidity}%"

    except Exception as e:
        return f"Error fetching weather data: {str(e)}"
# Function to fetch historical weather data (last 5 days)
@mcp.tool()
def get_historical_waether(city: str):
    """
    Fetches historical weather data for a given city (last 5 days).
    """
    try:
        url = f"{BASE_URL}/forecast?q={city}&appid={API_KEY}&units=metric"
        response = requests.get(url)
        if data.get("cod") != "200":
            return f"Error: 

目录标签

目录标签

Jupyter Notebook历史数据天气预报位置天气实时数据本地部署天气查询MCP协议

接入字段

传输方式(transport,传输协议)

未说明

鉴权方式(authType,认证方式)

api-key

工具数量(toolCount,工具数)

2

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

未说明api-key部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

仍需确认:installCommand

来源信息

继续浏览同类 MCP