Weather MCP Server

Weather MCP Server

An MCP server that provides weather information and alerts for US locations using the National Weather Service API, enabling retrieval of weather forecasts and active weather alerts.

Category
访问服务器

README

Weather MCP Server

A Model Context Protocol (MCP) server that provides weather information and alerts using the National Weather Service (NWS) API. This server offers tools for retrieving weather forecasts and active weather alerts for locations in the United States.

About This Project

This project is based on the Model Context Protocol (MCP) Getting Started Tutorial for server developers. The tutorial provides a comprehensive guide for building MCP servers and integrating them with clients like Claude for Desktop.

The original code sample for this weather server can be found in the MCP Quickstart Resources repository.

Features

  • Weather Alerts: Get active weather alerts for any US state using two-letter state codes
  • Weather Forecasts: Retrieve detailed weather forecasts for specific coordinates
  • Real-time Data: Uses the official National Weather Service API for accurate, up-to-date information
  • Easy Integration: Simple MCP server that can be integrated with any MCP-compatible client

Installation

Prerequisites

  • Python 3.8 or higher
  • uv package manager (recommended) or pip

Setup

  1. Clone the repository:
git clone https://github.com/agentventure/mcp_server_python_getting_started.git
cd mcp_server_python_getting_started
  1. Install dependencies using uv:
uv sync

Or using pip:

pip install -r requirements.txt

Usage

Running the Server

Start the MCP server:

uv run weather.py

The server will start and communicate via stdio, ready to handle requests from MCP clients.

Available Tools

1. Get Weather Alerts (get_alerts)

Retrieve active weather alerts for a US state.

Parameters:

  • state (string): Two-letter US state code (e.g., "CA", "NY", "TX")

Example:

# Get alerts for California
alerts = await get_alerts("CA")

Response Format:

Event: Severe Thunderstorm Warning
Area: Northern California
Severity: Severe
Description: Severe thunderstorm warning in effect...
Instructions: Take shelter immediately...

---

Event: Flood Watch
Area: Central Valley
Severity: Moderate
Description: Flood watch in effect...
Instructions: Monitor weather conditions...

2. Get Weather Forecast (get_forecast)

Get detailed weather forecast for a specific location.

Parameters:

  • latitude (float): Latitude coordinate of the location
  • longitude (float): Longitude coordinate of the location

Example:

# Get forecast for San Francisco (37.7749, -122.4194)
forecast = await get_forecast(37.7749, -122.4194)

Response Format:

Tonight:
Temperature: 55°F
Wind: 10 mph NW
Forecast: Clear skies with light winds. Low around 55.

---

Tomorrow:
Temperature: 68°F
Wind: 15 mph W
Forecast: Sunny with increasing clouds in the afternoon. High near 68.

---

Tomorrow Night:
Temperature: 52°F
Wind: 8 mph NW
Forecast: Partly cloudy with light winds. Low around 52.

API Information

This server uses the National Weather Service API, which provides:

  • No API Key Required: Free access to weather data
  • Real-time Updates: Data is updated frequently throughout the day
  • Comprehensive Coverage: Covers all US states and territories
  • Reliable Service: Official government weather service

Data Sources

  • Alerts: Active weather alerts from the NWS
  • Forecasts: Detailed weather forecasts including temperature, wind, and conditions
  • Geographic Data: Point-based weather information for any US location

Error Handling

The server includes robust error handling for:

  • Network connectivity issues
  • Invalid coordinates or state codes
  • API service unavailability
  • Timeout conditions

When errors occur, the server returns informative error messages to help with debugging.

Development

Project Structure

weather/
├── weather.py          # Main MCP server implementation
├── main.py            # Entry point for running the server
├── pyproject.toml     # Project configuration and dependencies
├── README.md          # This file
└── .gitignore         # Git ignore rules

Dependencies

  • mcp: Model Context Protocol server framework
  • httpx: Async HTTP client for API requests
  • fastmcp: FastMCP server implementation

Adding New Features

To add new weather-related tools:

  1. Create a new async function in weather.py
  2. Decorate it with @mcp.tool()
  3. Add proper type hints and docstrings
  4. Implement error handling using the existing make_nws_request helper

Contributing

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

License

This project is open source and available under the MIT License.

Support

For issues or questions:

  1. Check the National Weather Service API documentation
  2. Review the MCP documentation at modelcontextprotocol.io
  3. Open an issue in this repository

Note: This server is designed for educational and development purposes. For production use, consider implementing rate limiting and additional error handling based on your specific requirements.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选