Weather CLI is a command-line tool and server application that provides real-time weather information for any location globally. It integrates with the Model Control Protocol (MCP) to offer a standardized service interface, making it easy to deploy and integrate with other systems. The tool uses the wttr.in API to fetch weather data and supports both command-line and server modes.
Model Control Protocol (MCP) is a lightweight service protocol designed for building and deploying machine learning model services. In this project, MCP is used to:
- Provide standardized service interfaces.
- Support asynchronous operations.
- Facilitate integration with other systems.
- Support multiple transport protocols (stdio, TCP, WebSocket, etc.).
To install the Weather CLI, follow these steps:
# Clone the repository
git clone https://github.com/liye71023326/weather-cli.git
cd weather-cli
# Install using uv (recommended)
uv pip install -e .
# Or install using pip
pip install -e .
Use the weather-cli
command to fetch weather data:
# Fetch weather for Beijing (default)
weather-cli forecast
# Fetch weather for Shanghai
weather-cli forecast --latitude 31.2304 --longitude 121.4737
# Fetch weather for Guangzhou
weather-cli forecast --latitude 23.1291 --longitude 113.2644
# Method 1: Run directly using Python
python run_server.py
# Method 2: Run using MCP CLI tool
mcp run weather
In another terminal:
# Fetch weather for Beijing (default coordinates)
mcp call weather get_forecast
# Fetch weather for a specific location
mcp call weather get_forecast --latitude 31.2304 --longitude 121.4737
get_forecast
Endpointlatitude
: Latitude, range -90 to 90 (default: 39.9042, Beijing).longitude
: Longitude, range -180 to 180 (default: 116.4074, Beijing).Returns: Weather information string, including:
get_alerts
Endpoint
state
: Region code.Here are the coordinates for some commonly searched cities:
- Beijing: 39.9042, 116.4074 (default)
- Shanghai: 31.2304, 121.4737
- Guangzhou: 23.1291, 113.2644
- Shenzhen: 22.5431, 114.0579
- Chengdu: 30.5728, 104.0668
- Wuhan: 30.5928, 114.3055
- Xi'an: 34.3416, 108.9398
- Hangzhou: 30.2741, 120.1551
httpx
: For asynchronous HTTP requests.mcp[cli]
: MCP protocol implementation.weather-cli/
├── weather/
│ ├── __init__.py # MCP server implementation and weather API integration
│ └── cli.py # Command-line interface implementation
├── run_server.py # MCP server startup script
├── pyproject.toml # Project configuration
├── .gitignore # Git ignore configuration
└── README.md # This file
You can extend the project by:
1. Adding new weather data sources.
2. Implementing additional weather-related features (e.g., future forecasts).
3. Supporting additional transport protocols.
4. Implementing data caching mechanisms.
5. Adding weather alert functionality.
6. Including more default city coordinates.
Contributions are welcome! Please submit issues and pull requests to improve the project.
This project is licensed under the MIT License.