Weather MCP Server

Weather MCP Server

Provides current weather conditions and 5-day forecasts for any location using the OpenWeatherMap API. Supports flexible location queries including city names, coordinates, and zip codes.

Category
访问服务器

README

Weather MCP Server

A Model Context Protocol (MCP) server that provides weather information using the OpenWeatherMap API. This server primarily runs in stdio mode (the standard for MCP servers) with an experimental HTTP API mode for testing.

Features

  • MCP Protocol Support: Full stdio mode support for MCP clients
  • HTTP API Mode: Experimental simple HTTP API for testing
  • Current Weather: Get current weather conditions for any location
  • Weather Forecast: Get weather forecasts up to 5 days ahead
  • Location Flexibility: Support for city names, coordinates (lat,lon), and zip codes
  • Docker Support: Containerized deployment with docker-compose
  • Configurable: YAML-based configuration with environment variable support
  • Well Tested: Comprehensive test suite with pytest

Prerequisites

  • Python 3.11 or higher
  • OpenWeatherMap API key (free tier available at OpenWeatherMap)
  • Docker (optional, for containerized deployment)

Installation

Using pip

# Clone the repository
git clone https://github.com/dangogh/weather-mcp.git
cd weather-mcp

# Install dependencies
pip install -r requirements.txt

# Install the package
pip install -e .

Using Docker

# Build the Docker image
docker build -t weather-mcp .

# Or use docker-compose (see Docker section below)

Configuration

The server uses a YAML configuration file (config.yaml) with the following structure:

server:
  mode: stdio  # or 'http'
  http:
    host: 0.0.0.0
    port: 8080

weather_api:
  provider: openweathermap
  base_url: https://api.openweathermap.org/data/2.5
  api_key: ${WEATHER_API_KEY}  # Set via environment variable
  units: metric  # or 'imperial' or 'standard'
  timeout: 10

logging:
  level: INFO
  format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s"

Environment Variables

  • WEATHER_API_KEY: Your OpenWeatherMap API key (required)
  • SERVER_MODE: Override server mode (optional, defaults to config file)

Usage

Running in stdio mode

# Set your API key
export WEATHER_API_KEY="your_api_key_here"

# Run the server
python -m weather_mcp

# Or use the CLI command
weather-mcp

Running in HTTP mode (Experimental)

Note: HTTP mode provides a simple REST API for testing. For production MCP usage, use stdio mode.

# Update config.yaml to set mode: http, or use environment variable
export WEATHER_API_KEY="your_api_key_here"
export SERVER_MODE=http

python -m weather_mcp

The HTTP server will start on http://localhost:8080 with the following endpoints:

  • GET /: Server information
  • GET /health: Health check
  • POST /weather/current: Get current weather (JSON: {"location": "London"})
  • POST /weather/forecast: Get forecast (JSON: {"location": "London", "days": 3})

Using with Docker

Stdio mode:

# Set your API key in .env file
echo "WEATHER_API_KEY=your_api_key_here" > .env

# Run with docker-compose
docker-compose --profile stdio run weather-mcp-stdio

HTTP mode:

# Run HTTP server
docker-compose --profile http up weather-mcp-http

# The server will be available at http://localhost:8080

Available Tools

get_current_weather

Get current weather conditions for a location.

Parameters:

  • location (string, required): City name, coordinates (lat,lon), or zip code

Example:

{
  "location": "London"
}

Response includes:

  • Temperature and "feels like" temperature
  • Weather description
  • Humidity percentage
  • Atmospheric pressure
  • Wind speed

get_weather_forecast

Get weather forecast for a location up to 5 days ahead.

Parameters:

  • location (string, required): City name, coordinates (lat,lon), or zip code
  • days (integer, optional): Number of days to forecast (1-5, default: 3)

Example:

{
  "location": "New York",
  "days": 3
}

Response includes:

  • Forecast data in 3-hour intervals
  • Same weather details as current weather for each interval

Development

Running Tests

# Install dev dependencies
pip install -r requirements-dev.txt

# Run tests
pytest

# Run with coverage
pytest --cov=src/weather_mcp --cov-report=html

Code Structure

weather-mcp/
├── src/
│   └── weather_mcp/
│       ├── __init__.py
│       ├── __main__.py       # Entry point
│       ├── config.py          # Configuration management
│       ├── server.py          # MCP server implementation
│       ├── weather_client.py  # Weather API client
│       └── http_server.py     # HTTP streaming server
├── tests/
│   ├── __init__.py
│   ├── test_config.py
│   ├── test_weather_client.py
│   └── test_server.py
├── config.yaml                # Configuration file
├── Dockerfile                 # Docker image definition
├── docker-compose.yml         # Docker compose configuration
├── requirements.txt           # Production dependencies
├── requirements-dev.txt       # Development dependencies
├── setup.py                   # Package setup
└── README.md                  # This file

API Reference

OpenWeatherMap API

This server uses the OpenWeatherMap API. Key features:

  • Free Tier: 60 calls/minute, 1,000,000 calls/month
  • Current Weather: Real-time weather data
  • 5-Day Forecast: Weather predictions in 3-hour intervals
  • Location Support: City names, coordinates, zip codes

Get your free API key at: https://openweathermap.org/api

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Troubleshooting

API Key Issues

If you see "API key not configured" errors:

  1. Ensure WEATHER_API_KEY environment variable is set
  2. Check that the key is valid and active on OpenWeatherMap
  3. Verify the key is not expired (free tier keys don't expire but can be revoked)

Connection Issues

If you encounter connection errors:

  1. Check your internet connection
  2. Verify OpenWeatherMap API is accessible from your location
  3. Check if you've exceeded rate limits (60 calls/minute for free tier)

Docker Issues

If Docker containers fail to start:

  1. Ensure Docker and docker-compose are installed
  2. Check that port 8080 is not already in use (for HTTP mode)
  3. Verify the API key is properly set in the environment

Support

For issues and questions:

  • Open an issue on GitHub: https://github.com/dangogh/weather-mcp/issues
  • Check existing issues for solutions

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选