MCP Server
by aquental
This is a Weather MCP (Model Context Protocol) server implemented in Python. It provides an interface for accessing weather-related data.
View on GitHub
Last updated: N/A
MCP Server
Weather MCP server in python
# Create a new directory for our project
uv init
# Create virtual environment and activate it
uv venv
source .venv/bin/activate
# Install dependencies
uv add "mcp[cli]" httpx
# Create our server file
touch weather.py
Testing
This project includes a comprehensive test suite for the weather service API. The tests use pytest and pytest-asyncio to test the asynchronous functions that interact with the National Weather Service API.
Test Requirements
- Python 3.12+
- pytest
- pytest-asyncio
- pytest-cov
- httpx
Installing Development Dependencies
You can install all development dependencies using:
# Using uv
uv pip install -e ".[dev]"
# Or using pip
pip install -e ".[dev]"
Running the Tests
To run the tests:
# Run all tests
pytest
# Run with verbose output
pytest -v
# Run with code coverage
pytest --cov=weather
Test Coverage
The test suite covers:
-
Unit Tests for Helper Functions
format_alert
function for formatting alert data- Error handling in
make_nws_request
-
API Function Tests
get_alerts
: Testing successful retrieval, empty results, and API failuresget_forecast
: Testing successful forecast retrieval and error handling for both API endpoints
-
Mock Responses
- All HTTP requests are mocked using
httpx.AsyncMock
- Multiple test scenarios with different API responses
- All HTTP requests are mocked using
Continuous Integration
When adding new features to the weather service, please ensure all tests pass by running the test suite before submitting changes.