Skip to main content
Glama
agentventure

Weather MCP Server

by agentventure

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.

Related MCP server: WeatherMCP

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.

Available Tools

2 tools
get_alertsA

Get weather alerts for a US state.

Args:
    state: Two-letter US state code (e.g. CA, NY)
ParametersJSON Schema
NameRequiredDescriptionDefault
stateYes

TDQS

A4/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, and the description does not disclose behavioral traits such as data source freshness, authentication requirements, rate limits, or error handling for invalid states. The agent is left uninformed about important runtime behaviors.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise (two lines) with the purpose front-loaded. Every sentence adds value: the first states the action, the second clarifies the parameter. No wasted words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple one-parameter tool with no output schema, the description is largely complete. It explains what the tool does and how to specify the input. However, it does not mention what the return value contains (e.g., alert details, count), which could be useful for an agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description adds crucial meaning by specifying the parameter format ('Two-letter US state code') and providing examples (CA, NY). This adequately compensates for the missing schema descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Get') and resource ('weather alerts') with a specific scope ('for a US state'). It is unambiguous and distinguishes the tool's function even without sibling tools present.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies when to use the tool (when needing weather alerts for a US state) but does not provide explicit exclusions or alternatives. Since there are no sibling tools, this is acceptable but could be more prescriptive about valid state codes.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

get_forecastB

Get weather forecast for a location.

Args:
    latitude: Latitude of the location
    longitude: Longitude of the location
ParametersJSON Schema
NameRequiredDescriptionDefault
latitudeYes
longitudeYes

TDQS

B3/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It states what the tool does but doesn't describe any behavioral traits - no information about rate limits, authentication needs, whether this is a read-only operation, what format the forecast returns, or any side effects. This is inadequate for a tool with zero annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized with a clear purpose statement followed by parameter documentation. The two-sentence structure is efficient, though the parameter documentation could be integrated more seamlessly rather than as a separate 'Args:' section. Every sentence serves a purpose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations, no output schema, and a simple 2-parameter tool, the description is incomplete. It doesn't explain what the forecast returns (format, time range, metrics), any limitations (e.g., historical vs. future forecasts), or behavioral constraints. For a weather API tool, users need to know what data they'll receive.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage and 2 parameters, the description compensates well by explicitly listing both parameters ('latitude' and 'longitude') and providing basic semantic context ('Latitude of the location', 'Longitude of the location'). This adds meaningful information beyond the bare schema, though it doesn't specify format constraints or valid ranges.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with 'Get weather forecast for a location' - a specific verb ('Get') and resource ('weather forecast') with scope ('for a location'). However, it doesn't differentiate from sibling tools like 'get_alerts' which might also relate to weather, so it doesn't reach the highest score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. There's no mention of when-not scenarios, prerequisites, or comparison with sibling tools like 'get_alerts' (which might provide weather alerts instead of forecasts). The agent must infer usage from the name alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 2 tool updates
    • First observedget_alerts
    • First observedget_forecast

TDQS

B3.1/5.0

Scored across 2 tools

Disambiguation5/5

The two tools have clearly distinct purposes: get_alerts retrieves alerts for US states, while get_forecast provides forecasts for geographic coordinates. There is no overlap in functionality or ambiguity about which tool to use for each task.

Naming Consistency5/5

Both tools follow a consistent verb_noun naming pattern (get_alerts, get_forecast) with identical verb usage and snake_case formatting. The naming is perfectly predictable and uniform across the tool set.

Tool Count2/5

With only two tools, this server feels under-scoped for a weather domain. While alerts and forecasts are core functions, there are obvious gaps like current conditions, historical data, or radar imagery that would make the tool set more complete and useful.

Completeness2/5

The tool set is severely incomplete for a weather server. It lacks basic operations like getting current weather conditions, historical data, or radar information. The two tools provided create dead ends for common agent workflows that require more comprehensive weather data.

Maintenance

ActivityInactive
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers