A simplified Model Context Protocol (MCP) server that provides weather data through integration with the National Weather Service API, designed to work with AI language models like Google's Gemini.
- Weather Forecasts: Get detailed weather forecasts for any location using latitude/longitude coordinates
- Weather Alerts: Retrieve active weather alerts for US states
- MCP Protocol: Implements JSON-RPC 2.0 based Model Context Protocol for AI integration
- Cross-platform: Works on Windows, macOS, and Linux
- No External Dependencies: Uses Python standard library only (urllib instead of external HTTP libraries)
weather_simple.py
- The MCP weather server implementationclient_simple.py
- Simplified MCP client with Gemini API integrationtest_simple.py
- Test script to verify server functionality
- Python 3.8 or higher
- Google Gemini API key (for client usage)
- Internet connection (for National Weather Service API access)
- Clone or download the project files
- No additional Python packages required - uses standard library only
- Set your Gemini API key:
export GEMINI_API_KEY="your-api-key-here"
First, test that the server works correctly:
python test_simple.py
Expected output:
✓ Server started successfully
✓ Server initialization successful
✓ Found 2 tools:
- get_alerts: Get weather alerts for a US state.
- get_forecast: Get weather forecast for a location.
Start the interactive client:
python client_simple.py
In the client interface:
simple-mcp> /connect weather python weather_simple.py
/connect <name> <command...>
- Connect to MCP server/disconnect <name>
- Disconnect from server/list <name>
- List available tools/call <name> <tool> <json_args>
- Call a specific tool/servers
- List connected servers/quit
- Exit client
simple-mcp> /call weather get_forecast {"latitude": 40.7128, "longitude": -74.0060}
simple-mcp> /call weather get_alerts {"state": "NY"}
Once connected, you can ask natural language questions:
simple-mcp> What's the weather forecast for New York City?
simple-mcp> Are there any weather alerts for California?
Gets weather forecast for a specific location.
Parameters:
latitude
(float): Latitude coordinatelongitude
(float): Longitude coordinate
Returns: Formatted weather forecast text
Gets active weather alerts for a US state.
Parameters:
state
(string): Two-letter US state code (e.g., "CA", "NY", "TX")
Returns: Formatted weather alerts text
This server uses the National Weather Service API, which provides:
- Free access to US weather data
- No API key required
- Reliable, official weather information
- Coverage for all US states and territories
The server implements a simplified version of the Model Context Protocol:
- JSON-RPC 2.0: Standard protocol for communication
- Stdio Transport: Communication via standard input/output
- Async Processing: Non-blocking request handling
- Error Handling: Graceful handling of network and API errors
- Ensure Python 3.8+ is installed
- Check that no other process is using the same ports
- Verify internet connectivity for NWS API access
- The server may take a few seconds to start
- Check firewall settings if running across network
- Ensure the server process hasn't crashed (check stderr output)
- NWS API may be temporarily unavailable
- Some coordinates may be outside NWS coverage area
- Invalid state codes will return no results
- Ensure GEMINI_API_KEY environment variable is set
- Check that Gemini API key is valid and has quota remaining
- Verify network connectivity for both NWS and Gemini APIs
- US Only: National Weather Service API only covers US locations
- Coordinate Precision: NWS API requires fairly precise coordinates
- Rate Limiting: NWS API has undocumented rate limits
- Forecast Range: Limited to 5-day forecast periods
To add new tools, follow this pattern in weather_simple.py
:
@server.tool("tool_name")
async def tool_function(param1: str, param2: float) -> str:
"""Tool description for AI context.
Args:
param1: Description of parameter
param2: Description of parameter
"""
# Implementation here
return "Result string"
The server implements standard JSON-RPC 2.0 over stdio, so you can create custom clients in any language. Key methods:
initialize
- Start sessiontools/list
- Get available toolstools/call
- Execute a tool
This project is provided as-is for educational and development purposes. The National Weather Service API is a public service provided by NOAA.