Skip to content

Avishek-7/weather_mcp_server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Weather

A Model Context Protocol (MCP) server for retrieving weather alerts and forecasts using the National Weather Service (NWS) API.

Features

  • Get Weather Alerts: Retrieve active weather alerts for any US state
  • Get Weather Forecast: Obtain weather forecasts for specific geographic coordinates
  • MCP Integration: Built with FastMCP for seamless integration with AI assistants
  • Async Support: Non-blocking asynchronous API calls for efficient performance

Requirements

  • Python >= 3.13
  • httpx >= 0.28.1
  • mcp[cli] >= 1.25.0

Installation

  1. Clone the repository:
git clone <repository-url>
cd weather
  1. Install dependencies:
pip install -e .

Or using uv:

uv sync

Usage

Running the Server

python main.py

Available Tools

get_alerts(state: str) -> str

Get weather alerts for a US state.

Parameters:

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

Example:

result = await get_alerts("CA")

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

Get weather forecast for a specific location.

Parameters:

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

Example:

result = await get_forecast(40.7128, -74.0060)

Architecture

The project uses the FastMCP framework to create a Model Context Protocol server that exposes weather-related tools. All API requests go through the National Weather Service API with proper error handling and timeout management.

Components

  • weather.py: Main server implementation with tool definitions
  • main.py: Entry point for running the server
  • pyproject.toml: Project configuration and dependencies

API Information

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

  • Free to use
  • Public data
  • No authentication required
  • Covers the United States and its territories

Error Handling

The server includes comprehensive error handling for:

  • Network timeouts (30-second limit)
  • Invalid API responses
  • Missing or unavailable data

Development

To modify or extend the tools:

  1. Edit the tool definitions in weather.py
  2. Add new async functions with the @mcp.tool() decorator
  3. Include proper docstrings with argument descriptions
  4. Test with the running server

License

Add license information here.

Contributing

Contributions are welcome! Please feel free to submit a pull request.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages