Skip to main content
Glama
README.md3.19 kB
# Weather MCP Server A lightweight FastMCP service exposing National Weather Service alerts and forecasts via simple RPC-style "tools". ## Installation First, install [uv](https://github.com/astral-sh/uv) (a fast Python package manager) if you don't have it already: ```bash curl -LsSf https://astral.sh/uv/install.sh | sh ``` # Create virtual environment and activate it ```bash uv venv source .venv/bin/activate ``` # Install dependencies ```bash uv add "mcp[cli]" httpx ``` Then install from PyPI: ```bash pip install weather-mcp-server ``` Or install from source for development: ```bash git clone https://github.com/YourOrg/weather-mcp-server.git cd weather-mcp-server pip install -e ".[dev]" ``` ## Usage ### As a Python library ```python from weather.nws_client import NWSClient import asyncio async def main(): client = NWSClient() alerts = await client.get_alerts("CA") for alert in alerts: print(alert["headline"], alert["event"], alert["severity"]) asyncio.run(main()) ``` ### As a FastMCP server ```bash weather-mcp-server --transport stdio ``` Or ```bash uv run main.py ``` To run the MCP Inspector: ```bash npx @modelcontextprotocol/inspector ``` Copy the Session token and the Proxy server address (see example below). ```bash Proxy server listening on 127.0.0.1:6277 Session token: dc7a47f8b6b1a3eede7c507a8d1c9a7f7e6b3ff46c138f8480bbfbae3c45a9e4 ``` Open the MCP Inspector in your browser:http://127.0.0.1:6274, and in the Configuration, paste the values to the following fields below: ``` Command: uv Argument: run main.py Inspector Proxy Address: http://127.0.0.1:6274 Proxy Session Token: dc7a47f8b6b1a3eede7c507a8d1c9a7f7e6b3ff46c138f8480bbfbae3c45a9e4 ``` ## API Reference ### get_alerts Fetch formatted weather alerts for a given two-letter US state code. **Arguments:** - `state` (str): Two-letter uppercase state abbreviation (e.g. "CA"). **Returns:** - `str`: Formatted alerts separated by `---`, or an error message. ### get_forecast Fetch formatted weather forecast for a location. **Arguments:** - `latitude` (float): Latitude between -90 and 90. - `longitude` (float): Longitude between -180 and 180. **Returns:** - `str`: Forecast for up to next 5 periods or an error message. ### /health Health check endpoint. **HTTP GET** `/health` **Returns JSON:** - `{"status": "ok"}` ## Testing & Coverage - Tests use `pytest`, `pytest-asyncio`, and `pytest-cov`. - Network calls are monkeypatched for isolation in unit tests. - Run all tests with: ```sh pytest ``` - Generate an HTML coverage report with: ```sh pytest --cov=src --cov-report=html open htmlcov/index.html ``` ## Fixtures & Mocking - Test fixtures and monkeypatching are used to mock NWS API responses and isolate tests from network dependencies. - See `tests/conftest.py` for reusable fixtures. ## References * [https://medium.com/data-engineering-with-dremio/building-a-basic-mcp-server-with-python-4c34c41031ed](https://medium.com/data-engineering-with-dremio/building-a-basic-mcp-server-with-python-4c34c41031ed) * [https://modelcontextprotocol.io/quickstart/server](https://modelcontextprotocol.io/quickstart/server)

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jairosoft-com/mcp-server-python-template'

If you have feedback or need assistance with the MCP directory API, please join our Discord server