Build weather alerts tool with FastMCP and Claude Desktop for real-time US weather updates
The MCP Weather Alerts Server utilizes the Model Context Protocol (MCP) to construct a specialized tool that serves real-time weather alerts for U.S. states. This server, which leverages the FastMCP Python SDK and integrates with Claude Desktop, enables AI applications to retrieve detailed meteorological notifications swiftly. By implementing FastMCP
, this project streamlines the process of fetching up-to-date information from the api.weather.gov
API and returning structured data tailored for practical use.
The core features of our MCP Weather Alerts Server encompass both the technical implementation details and how it integrates seamlessly with various AI clients. The server employs asynchronous HTTP requests via httpx
, ensuring fast response times and efficient usage of resources. Structured information such as event, severity, description, and instructions are returned for each weather alert, making it easy for developers to process and implement within their applications.
MCP Capabilities:
api.weather.gov
API to fetch live weather alerts based on specified U.S. states.The architecture of the MCP Weather Alerts Server is built on a modular approach that adheres strictly to the MCP protocol. It integrates FastMCP
for server functions and uses httpx
for HTTP requests. The tools are managed using uv
, a modern package manager in Python.
The following diagram illustrates the flow of data and protocol interactions within our setup.
graph TD
A[AI Application] -->|MCP Client| B[MCP Protocol]
B --> C[MCP Server]
C --> D[Data Source/Tool]
style A fill:#e1f5fe
style C fill:#f3e5f5
style D fill:#e8f5e8
To begin using the MCP Weather Alerts Server, follow these steps to ensure a smooth setup process. This guide provides detailed instructions for installing the necessary tools and configuring your environment.
Firstly, install uv
if you haven't already:
pipx install uv
To initialize a new project using uv
, execute the following command in your terminal:
uv init mcpcrashcourse
cd mcpcrashcourse
Next, add the required dependencies for our server tool logic with uv
:
uv add "mcp[cli]" httpx
Place the Python script that implements your get_alerts
function in a file under server/
, e.g., weather.py
. This module contains the server's primary logic for fetching and processing weather alerts.
from fastmcp import mcp, tool
@tool
async def get_alerts(state: str) -> list[dict]:
# Fetch weather alerts for a given U.S. state (e.g., 'CA')
url = "https://api.weather.gov/alerts/active"
params = {"area": state.upper()}
async with httpx.AsyncClient() as client:
response = await client.get(url, params=params)
data = response.json()
return [
{
"event": alert.get("event"),
"severity": alert.get("severity"),
"description": alert.get("description"),
"instruction": alert.get("instruction"),
}
for alert in data.get("features", [])
if alert.get("properties")
]
The MCP Weather Alerts Server serves as a critical component for developers creating applications that require real-time weather updates. Here are two practical use cases:
For disaster response teams, the server can provide timely warnings and detailed instructions about ongoing weather events. This information is vital for formulating immediate responses or evacuation plans.
In smart home systems, the alerts can trigger automated actions such as turning off outdoor lights during power outages due to storms or adjusting thermostat settings based on extreme temperatures.
To integrate this server with an AI client like Claude Desktop, follow these steps:
claude_desktop_config.json
:{
"mcpServers": {
"weather": {
"command": "uv",
"args": [
"run",
"--with",
"mcp[cli]",
"mcp",
"run",
"<your-project-directory>/server/weather.py"
]
}
}
}
Restart Claude Desktop: Ensure the application picks up the new configuration and starts using the MCP server for weather data.
Invoke Tool:
Prompt your AI client with:
What are the weather alerts for Texas?
The compatibility of our Weather Alerts Server is paramount, ensuring seamless interactions across various AI clients. The following table details the current status and compatibility level of each client.
MCP Client | Resources | Tools | Prompts | Status |
---|---|---|---|---|
Claude Desktop | ❌ | ✅ | ✅ | Full Support |
Continue | ✔️ | ✅ | ✅ | Full Support |
Cursor | ❌ | ✅ | ❌ | Tools Only |
Security measures are crucial for protecting against unauthorized access and data breaches. Here's how you can secure your setup:
For advanced users who wish to customize their experience further:
API_KEY="your-secure-api-key"
uv run mcp dev server/weather.py --env-file .env
A: The server integrates by defining an MCP endpoint that can be invoked through claude_desktop_config.json
. This setup ensures Claude Desktop can seamlessly access real-time weather alerts.
A: While our focus is on compatibility with Claude Desktop and Continue, the codebase and documentation can serve as a foundation for similar integrations with other clients that support MCP.
weather.py
to prevent API overuse?A: Implement rate limit checks within your server logic. For instance:
import time
RATE_LIMIT = 10 # API calls per minute
def enforce_rate_limit():
global last_call_time
current_time = int(time.time())
time_since_last_call = current_time - last_call_time
if time_since_last_call < RATE_LIMIT:
sleep_time = (time_since_last_call + 60 / RATE_LIMIT) - current_time
time.sleep(sleep_time)
else:
last_call_time = current_time
A: The server runs on any machine compatible with Python and uv
. Basic configuration is straightforward, but optimizing performance may require a higher-spec machine due to asynchronous operations.
A: Use the MCP Inspector tool provided by FastMCP. Running:
uv run mcp dev server/weather.py
Opens an interactive interface where you can test your tools in real-time, ensuring they function correctly before deployment.
Contributions are welcome! To contribute to the project, ensure your code adheres to best practices and follow these steps:
git clone https://github.com/your-username/mcpcrashcourse.git
Develop & Test: Make necessary changes, test thoroughly, and commit them with clear messages.
Submit PR: After testing locally, submit a pull request detailing the changes made.
Explore additional resources within the Model Context Protocol ecosystem:
By leveraging the MCP Weather Alerts Server, developers can build robust applications that provide real-time weather alerts using a standardized protocol. This server enhances AI integrations, ensuring reliable data delivery across various platforms while catering to specific user needs through structured output.
AI Vision MCP Server offers AI-powered visual analysis, screenshots, and report generation for MCP-compatible AI assistants
Analyze search intent with MCP API for SEO insights and keyword categorization
Learn how to use MCProto Ruby gem to create and chain MCP servers for custom solutions
Next-generation MCP server enhances documentation analysis with AI-powered neural processing and multi-language support
Expose Chicago Public Schools data with a local MCP server accessing SQLite and LanceDB databases
Connects n8n workflows to MCP servers for AI tool integration and data access