A production-ready Model Context Protocol (MCP) server built with FastAPI that provides weather information using the National Weather Service API. Features comprehensive API key authentication, role-based permissions, and streamable HTTP transport for real-time communication.
- Python 3.8+
- pip (Python package installer)
-
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
The server will start at
http://localhost:8000
with placeholder API keys for testing.
For production Azure deployment, see DEPLOY.md for complete instructions.
- Live Demo: https://
<YOUR-APP-SERVICE-NAME>
.azurewebsites.net/ - API Documentation: https://
<YOUR-APP-SERVICE-NAME>
.azurewebsites.net/docs - Interactive Testing: test_azure_web.html
- FastAPI Framework: Modern, fast web framework for building APIs
- MCP Protocol Compliance: Full support for JSON-RPC 2.0 MCP protocol
- Streamable HTTP Transport: HTTP-based streaming for MCP Inspector connectivity
- Weather Tools:
get_alerts
: Get weather alerts for any US stateget_forecast
: Get 5-day weather forecast for any location (latitude/longitude)
- API Key Authentication: Role-based access control with permissions
- Sample Resources: Basic resource handling demonstration
- Auto-reload: Development server with automatic reloading
- National Weather Service API: Real-time weather data from official US government source
This MCP server uses API key authentication for security.
- Server automatically uses placeholder keys:
<YOUR-DEMO-API-KEY>
and<YOUR-LIMITED-API-KEY>
- These placeholders are visible but will not work for actual requests
- Shows clear warnings in startup logs
For production deployment, you must provide real API keys via environment variables:
$env:MCP_API_KEYS = "your-secure-key:Client Name:tools,resources"
For complete authentication details, see API_KEY_CONFIGURATION.md
- tools: Access to weather tools (
get_alerts
,get_forecast
) - resources: Access to server resources
curl http://localhost:8000/health
curl -X GET "http://localhost:8000/tools" \
-H "Authorization: <YOUR-DEMO-API-KEY>"
curl -X POST "http://localhost:8000/tools/call" \
-H "Authorization: <YOUR-DEMO-API-KEY>" \
-H "Content-Type: application/json" \
-d '{"method": "tools/call", "params": {"name": "get_forecast", "arguments": {"latitude": 40.7128, "longitude": -74.0060}}}'
Note: These examples use placeholder keys. For actual testing, replace with your own API keys.
## Connecting to MCP Inspector
### Method 1: Azure-Hosted Server (No Setup Required)
Connect directly to the live Azure deployment:
**Configuration for MCP Inspector:**
```json
{
"mcpServers": {
"weather-mcp-server-azure": {
"transport": {
"type": "http",
"url": "https://your-app-name.azurewebsites.net/mcp/stream",
"headers": {
"Authorization": "<YOUR-DEMO-API-KEY>"
}
},
"name": "Weather MCP Server (Azure with Auth)",
"description": "MCP Server with weather forecast and alerts tools hosted on Azure with authentication"
}
}
}
-
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
- Add Authentication Header:
Authorization:<YOUR-DEMO-API-KEY>
-
Configuration file (
mcp-config.json
):{ "mcpServers": { "weather-mcp-server-local": { "transport": { "type": "http", "url": "http://localhost:8000/mcp/stream", "headers": { "Authorization": "<YOUR-DEMO-API-KEY>" } }, "name": "Weather MCP Server (Local with Auth)", "description": "MCP Server with weather forecast and alerts tools running locally with authentication" } } }
Visit http://localhost:8000/test (local) or https://<APP-SERVICE-NAME>
.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
}
To connect MCP Inspector to your local server:
-
Start the server (it will use placeholder keys automatically)
-
In MCP Inspector, add a new server connection:
- Transport: HTTP
- URL:
http://localhost:8000/mcp/stream
- Headers:
Authorization: <YOUR-DEMO-API-KEY>
-
Connect and test the weather tools
- Health Check:
GET /health
(no auth required) - API Documentation:
GET /docs
(no auth required) - Tools List:
GET /tools
(auth required) - Tool Execution:
POST /tools/call
(auth required) - MCP Stream:
POST /mcp/stream
(auth required) - Authentication Info:
GET /auth/info
(auth required)
Get weather alerts for any US state.
Parameters:
state
: Two-letter US state code (e.g., "CA", "TX", "NY")
Example:
curl -X POST "http://localhost:8000/tools/call" \
-H "Authorization: <YOUR-DEMO-API-KEY>" \
-H "Content-Type: application/json" \
-d '{"method": "tools/call", "params": {"name": "get_alerts", "arguments": {"state": "CA"}}}'
Get 5-day weather forecast for any location.
Parameters:
latitude
: Latitude coordinate (number)longitude
: Longitude coordinate (number)
Example:
curl -X POST "http://localhost:8000/tools/call" \
-H "Authorization: <YOUR-DEMO-API-KEY>" \
-H "Content-Type: application/json" \
-d '{"method": "tools/call", "params": {"name": "get_forecast", "arguments": {"latitude": 37.7749, "longitude": -122.4194}}}'
├── main.py # FastAPI server with MCP implementation
├── requirements.txt # Python dependencies
├── start_server.ps1 # PowerShell startup script
├── test_azure_auth.py # Authentication testing script
├── test_azure_web.html # Interactive web testing interface
├── mcp-config.json # MCP Inspector configuration
├── DEPLOY.md # Azure deployment guide
└── API_KEY_CONFIGURATION.md # Authentication implementation details
- Auto-reload: Server automatically restarts on code changes
- Interactive API docs: Available at
/docs
- Request logging: All authenticated requests are logged
- Health monitoring: Status endpoint at
/health
For production Azure deployment:
- Read DEPLOY.md for complete deployment instructions
- Configure real API keys via environment variables
- Deploy using Azure Developer CLI
- Authentication failures: Make sure you're using the correct API key format
- CORS errors: The server is configured for local development and Azure deployment
- Tool execution errors: Check that the National Weather Service API is accessible
- Environment variable issues: Restart the server after setting environment variables
# Check server health
curl http://localhost:8000/health
# Test authentication
curl -X GET "http://localhost:8000/auth/info" -H "Authorization: <YOUR-DEMO-API-KEY>"
# List available tools
curl -X GET "http://localhost:8000/tools" -H "Authorization: <YOUR-DEMO-API-KEY>"