Weather MCP Server
Fetch real-time weather alerts and forecasts for any location in the United States. Access detailed weather information effortlessly using state codes or geographic coordinates. Stay informed with structured logging and robust error handling for a seamless experience.
Installation
Installing for Claude Desktop
Option 1: One-Command Installation
npx mcpbar@latest install asifdotpy/MCP-Weather-Server -c claudeThis command will automatically install and configure the Weather MCP Server MCP server for your selected client.
Option 2: Manual Configuration
Run the command below to open your configuration file:
npx mcpbar@latest edit -c claudeAfter opening your configuration file, copy and paste this configuration:
View JSON configuration
{
"mcpServers": {
"Weather MCP Server": {
"command": "uvx",
"args": [
"weather"
],
"env": {}
}
}
}Weather Information Service
This project provides a service to fetch weather information, including alerts and forecasts, from the National Weather Service (NWS) API.
Project Structure
main.py: A simple entry point for the project. (Currently, it only prints a hello message).weather.py: This is the core of the project. It implements theWeatherServicewhich uses theFastMCPframework to expose tools for fetching weather data. It includes structured JSON logging and communicates with the NWS API.smithery.yaml: This is a configuration file for Smithery, a tool used to define how to run and interact with theWeatherService.Dockerfile: Suggests that the project can be containerized using Docker.pyproject.toml: Defines project metadata and dependencies for Python projects..gitignore: Specifies intentionally untracked files that Git should ignore..python-version: Specifies the Python version for the project (likely for use with tools likepyenv).uv.lock: A lock file generated by theuvPython package installer and resolver, ensuring reproducible builds.
(Further sections on WeatherService tools, running the project, and logging will be added in subsequent steps).
WeatherService Tools
The weather.py script provides a WeatherService with the following tools:
get_alerts(state: str) -> str
- Purpose: Fetches active weather alerts for a given US state.
- Arguments:
state(str): A two-letter US state code (e.g.,CA,NY).
- Output: A string containing formatted weather alerts, or a message if no alerts are found or an error occurs.
- Example (successful alert fetch):
Event: Special Weather Statement Area: San Francisco Bay Shoreline Severity: Minor Description: ... Instructions: ... --- Event: Coastal Flood Advisory Area: North Bay Interior Valleys Severity: Moderate Description: ... Instructions: ... - Example (no alerts):
No active alerts for this state. - Example (error):
Unable to fetch alerts or no alerts found.
- Example (successful alert fetch):
get_forecast(latitude: float, longitude: float) -> str
- Purpose: Fetches the weather forecast for a specific geographical location.
- Arguments:
latitude(float): The latitude of the location.longitude(float): The longitude of the location.
- Output: A string containing the formatted weather forecast for the next 5 periods, or a message if the forecast cannot be fetched.
- Example (successful forecast fetch):
Tonight: Temperature: 55°F Wind: 5 to 10 mph W Forecast: Mostly clear, with a low around 55. West wind 5 to 10 mph. --- Wednesday: Temperature: 70°F Wind: 5 to 15 mph W Forecast: Sunny, with a high near 70. West wind 5 to 15 mph, with gusts as high as 20 mph. ... (up to 5 periods) - Example (error):
Unable to fetch forecast data for this location.
- Example (successful forecast fetch):
Running the Project
The project is designed to be run as a service, likely using the FastMCP framework and the provided smithery.yaml configuration.
-
Prerequisites:
- Python 3.x
- The
httpxlibrary (and other dependencies as defined inpyproject.toml). You can typically install these using pip:pip install httpx # Or, if using a full project setup with pyproject.toml pip install .
-
Running the Service: The
weather.pyscript can be executed directly to start the service. Given thesmithery.yamlfile, the intended way to run this is likely:python weather.pyThis will start the
FastMCPserver, which will listen for requests (e.g., via stdio as configured insmithery.yaml).If you have Smithery installed, you might also be able to run it using Smithery commands, but running
weather.pydirectly should work for local development and testing.The
main.pyscript is a simple entry point and does not run the main weather service.
Logging
The WeatherService in weather.py uses structured JSON logging. This is particularly useful for production environments where logs might be ingested by log management systems.
Key features of the logging implementation:
- JSON Format (Production): When the
ENVenvironment variable is set toproduction, logs are output in JSON format. Each log entry includes:timestamplevel(e.g., INFO, ERROR)logger(logger name, e.g.,WeatherService)messagecorrelation_id(tracks a logical operation or flow)request_id(tracks individual requests)user_idfileandlineno(source of the log)function(function name where the log occurred)processandthreadenvironment(fromENVvariable)app_version(fromAPP_VERSIONvariable)host(fromHOSTNAMEvariable)duration(for operations, if applicable)error_details(stack trace if an exception occurred)
- Readable Format (Development): If
ENVis not set toproduction(or is set to something else likedevelopment), logs are output in a more human-readable, plain text format. - Configurable Log Level: The log level can be configured using the
LOG_LEVELenvironment variable (e.g.,INFO,DEBUG,ERROR). The default isINFO. - Contextual Information: Logging includes
correlation_id,request_id, anduser_idto help trace operations through the system.
Environment Variables for Logging:
LOG_LEVEL: Sets the logging verbosity (e.g.,DEBUG,INFO,WARNING,ERROR). Defaults toINFO.ENV: Set toproductionfor JSON logging. Defaults todevelopmentfor readable logs.APP_VERSION: Sets the application version in logs. Defaults to0.1.0.HOSTNAME: Sets the hostname in logs. Defaults tolocalhost.
Stars
0Forks
0Last commit
5 months agoRepository age
8 months
Auto-fetched from GitHub .
MCP servers similar to Weather MCP Server:
Stars
Forks
Last commit
Stars
Forks
Last commit
Stars
Forks
Last commit