A Model Context Protocol (MCP) server built with FastAPI that provides weather information using the National Weather Service API. Features Azure OAuth 2.0 authentication and streamable HTTP transport for real-time communication with MCP Inspector.
- FastAPI Framework: Modern, fast web framework for building APIs
- Azure OAuth 2.0 Authentication: Secure authentication using Microsoft Azure AD
- MCP Protocol Compliance: Full support for JSON-RPC 2.0 MCP protocol
- Streamable HTTP Transport: HTTP-based streaming for MCP Inspector connectivity
- JWT Token Management: Secure token-based authentication and authorization
- Weather Tools:
get_alerts
: Get weather alerts for any US stateget_forecast
: Get 5-day weather forecast for any location (latitude/longitude)
- Sample Resources: Basic resource handling demonstration
- Azure App Service Deployment: Ready for production deployment on Azure
- Virtual Environment: Properly isolated Python environment
- Auto-reload: Development server with automatic reloading
- National Weather Service API: Real-time weather data from official US government source
- Python 3.8+
- pip (Python package installer)
- Azure account (for OAuth setup and deployment)
- Azure CLI (for deployment)
- Clone and navigate to the project
- Set up Azure OAuth (see AUTH_SETUP.md for detailed instructions)
- Create environment file (copy from .env.example)
- Install and run locally (see Local Development section below)
Follow the instructions in DEPLOY.md to deploy your own instance to Azure.
-
Create and activate virtual environment:
python -m venv venv .\venv\Scripts\Activate.ps1
-
Install dependencies:
pip install -r requirements.txt
-
Start the server:
.\start_server.ps1
Or manually:
.\venv\Scripts\python.exe -m uvicorn main:app --host 0.0.0.0 --port 8000 --reload
-
Start the MCP server (it will run on http://localhost:8000)
-
In MCP Inspector v0.13.0:
- Add a new server connection
- Use HTTP transport type
- URL:
http://localhost:8000/mcp/stream
-
Configuration file (
mcp-config.json
):{ "mcpServers": { "weather-mcp-server-local": { "transport": { "type": "http", "url": "http://localhost:8000/mcp/stream" }, "name": "Weather MCP Server (Local)", "description": "MCP Server with weather forecast and alerts tools running locally" } } }
If you deploy your own instance to Azure, use this configuration:
Configuration for MCP Inspector:
{
"mcpServers": {
"weather-mcp-server-azure": {
"transport": {
"type": "http",
"url": "https://<YOUR-APP-SERVICE-NAME>.azurewebsites.net/mcp/stream"
},
"name": "Weather MCP Server (Azure)",
"description": "MCP Server with weather forecast and alerts tools hosted on Azure"
}
}
}
Visit http://localhost:8000/test (local) or https://.azurewebsites.net/test (Azure) to use the built-in web interface for testing HTTP connectivity.
- GET /health: Server health check
- POST /mcp/stream: Main MCP endpoint with streamable HTTP
- GET /mcp/capabilities: Get server capabilities
- GET /test: Web-based HTTP test interface
- POST /mcp: HTTP MCP endpoint (legacy)
pip install -r requirements.txt
python main.py
The server will start on http://localhost:8000
{
"jsonrpc": "2.0",
"method": "initialize",
"params": {},
"id": 1
}
{
"jsonrpc": "2.0",
"method": "tools/list",
"params": {},
"id": 2
}
{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "get_alerts",
"arguments": {
"state": "CA"
}
},
"id": 3
}
{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "get_forecast",
"arguments": {
"latitude": 37.7749,
"longitude": -122.4194
}
},
"id": 4
}
.\venv\Scripts\python.exe test_http_client.py # Streamable HTTP client
Open http://localhost:8000/test in your browser
-
get_alerts: Get weather alerts for a US state
{ "name": "get_alerts", "arguments": { "state": "CA" } }
- Parameter:
state
(string) - Two-letter US state code (e.g., CA, NY, TX) - Returns: Active weather alerts including severity, description, and instructions
- Parameter:
-
get_forecast: Get weather forecast for a location
{ "name": "get_forecast", "arguments": { "latitude": 37.7749, "longitude": -122.4194 } }
- Parameters:
latitude
(number) - Latitude coordinatelongitude
(number) - Longitude coordinate
- Returns: 5-day weather forecast with temperature, wind, and detailed conditions
- Parameters:
This server uses the National Weather Service (NWS) API, which provides:
- Real-time weather alerts and warnings
- Detailed weather forecasts
- Official US government weather data
- No API key required
- High reliability and accuracy
- mcp://server/sample: Sample resource for demonstration
- Ensure the server is running on http://localhost:8000
- Verify MCP endpoint is accessible: http://localhost:8000/mcp/stream
- Check capabilities endpoint: http://localhost:8000/mcp/capabilities
- Try the web test interface first: http://localhost:8000/test
- Port already in use: Change the port in startup commands
- Virtual environment not activated: Run
.\venv\Scripts\Activate.ps1
- Dependencies missing: Run
pip install -r requirements.txt