National Weather Service MCP server

Integrates with the National Weather Service API to provide real-time weather alerts and detailed forecasts for US locations using latitude and longitude coordinates.
Back to servers
Setup instructions
Provider
Jack Kuo
Release date
Mar 17, 2025
Language
Python

The Weather MCP Server provides weather information through the National Weather Service (NWS) API using the Model Context Protocol (MCP). It allows you to retrieve weather alerts for US states and get weather forecasts for specific locations using latitude and longitude coordinates.

Requirements

  • Python 3.10+
  • FastMCP
  • httpx

Installation

To install the Weather MCP Server:

  1. Clone the repository
  2. Set up a virtual environment:
python -m venv .venv
source .venv/bin/activate  # On Windows, use `.venv\Scripts\activate`
  1. Install the required packages using uv:
uv add "mcp[cli]" httpx

Configuration

The server uses a configuration file config.py with the following settings:

  • NWS_API_BASE: Base URL for the National Weather Service API
  • USER_AGENT: User-Agent string for NWS API requests
  • LOG_LEVEL: Logging level (e.g., "INFO", "DEBUG")
  • LOG_FORMAT: Format string for log messages
  • REQUEST_TIMEOUT: Timeout for API requests in seconds

You can modify these settings in the config.py file to customize the server behavior.

Usage

Running the Server Standalone

To run the server on its own:

  1. Activate the virtual environment if not already activated:
source .venv/bin/activate  # On Windows, use `.venv\Scripts\activate`
  1. Run the server:
python weather.py

Using with Cline

The Weather MCP Server can be integrated with Cline:

  • Ensure that Cline is properly set up and running
  • The Weather MCP Server will be available as a tool named "weather"
  • Available tools:
    • get_alerts(state: str): Get weather alerts for a US state (use two-letter state code, e.g., "CA" for California)
    • get_forecast(latitude: float, longitude: float): Get weather forecast for a specific location

Example usage in Cline:

# Get alerts for California
result = await mcp.call_tool("weather.get_alerts", state="CA")
print(result)

# Get forecast for San Francisco (approximate coordinates)
result = await mcp.call_tool("weather.get_forecast", latitude=37.7749, longitude=-122.4194)
print(result)

Note: The exact syntax for calling MCP tools may vary depending on your Cline setup.

Error Handling and Logging

The server includes error handling for API requests and logging. If an error occurs during a request, the server will log the error and return an appropriate error message. Logs are printed to the console with the configured log level and format.

Testing

Manual Testing

You can manually test the server using the MCP client to call the provided tools:

# Get alerts for California
result = await mcp.call_tool("get_alerts", state="CA")
print(result)

# Get forecast for San Francisco (approximate coordinates)
result = await mcp.call_tool("get_forecast", latitude=37.7749, longitude=-122.4194)
print(result)

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "weather" '{"command":"python","args":["weather.py"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "weather": {
            "command": "python",
            "args": [
                "weather.py"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "weather": {
            "command": "python",
            "args": [
                "weather.py"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later