天气MCP

一种基于模型控制协议(MCP)的服务,允许用户通过坐标查询天气预报,并接收美国各州的天气警报。

weather-servicesapp-automation

765 查看 · 2026-07-07 更新

简介

一种基于模型控制协议(MCP)的服务,允许用户通过坐标查询天气预报,并接收美国各州的天气警报。

简介

一种基于模型控制协议(MCP)的服务,允许用户通过坐标查询天气预报,并接收美国各州的天气警报。

Weather MCP Service

A weather information service based on the Model Control Protocol (MCP), providing functions for weather forecasts and alert queries.

Features

  • Fetch weather alerts for U.S. states (get_alerts)
  • Query weather forecasts by latitude and longitude (get_forecast)

Tech Stack

  • Python 3.11+
  • MCP (Model Control Protocol)
  • FastMCP Server
  • LangGraph + LangChain
  • SSE (Server-Sent Events) for transmission

Installation

  1. Clone the repository: bash git clone https://github.com/haichaozheng/weather-mcp.git cd weather-mcp

  2. Create a virtual environment: bash

    Using Python's standard library

    python -m venv weather_venv

    Activate the virtual environment (Windows)

    weather_venv\Scripts\activate

    Activate the virtual environment (Linux/Mac)

    source weather_venv/bin/activate

  3. Install dependencies: bash pip install -r requirements.txt

  4. Configure environment variables:

    • Create a .env file, following the format of .env.example
    • Add necessary API keys

Usage

  1. Start the Weather server: bash python weather/weather.py

    The server will start at http://localhost:8000, using SSE for transmission.

  2. In another terminal window, run the client: bash python weather/mcp_client.py

    The client will connect to the server and perform a series of weather query tests.

API Functions

Weather Alert Query

python get_alerts(state: str) -> str

  • state: Two-letter U.S. state code (e.g., CA, NY)
  • Returns: A list of active weather alerts for that state

Weather Forecast Query

python get_forecast(latitude: float, longitude: float) -> str

  • latitude: Latitude of the location
  • longitude: Longitude of the location
  • Returns: The weather forecast for that location

Project Structure

weather-mcp/ ├── weather/ │ ├── weather.py # Main server file │ ├── mcp_client.py # Client test file ├── requirements.txt # Project dependencies ├── .env.example # Example environment variables └── README.md # This document

Environment Variable Configuration

The project uses a .env file to store environment variables and sensitive information. Please follow these steps to set it up:

  1. Copy the environment variable template file: bash cp .env.example .env

  2. Edit the .env file, filling in your actual configurations:

    MOONSHOT_API_KEY=your_actual_api_key

  3. Ensure that the .env file is not committed to version control.

来源