Alisherkotek/weather-mcp-server
If you are the rightful owner of weather-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
A Model Context Protocol (MCP) server that provides real-time weather information using the OpenWeatherMap API.
Weather MCP Server
A Model Context Protocol (MCP) server that provides real-time weather information using the OpenWeatherMap API.
Features
- Current Weather: Get real-time weather conditions for any city worldwide
- Weather Forecast: 3-day weather forecast with hourly details
- Weather Alerts: Simulated weather warnings based on current conditions
- Multi-location Support: Query weather for any city with optional country code
- Error Handling: Graceful handling of invalid locations and API failures
Prerequisites
- .NET 8.0 or later
- OpenWeatherMap API key (free tier available)
Setup Instructions
1. Get an OpenWeatherMap API Key
- Visit OpenWeatherMap
- Sign up for a free account
- Generate an API key from your account dashboard
2. Configure Environment Variable
Windows (PowerShell):
$env:OPENWEATHERMAP_API_KEY = "api_key"
Windows (Command Prompt):
set OPENWEATHERMAP_API_KEY=api_key
Linux/macOS:
export OPENWEATHERMAP_API_KEY="api_key"
3. Build and Run
cd WeatherMcpServer
dotnet restore
dotnet run
Available Tools
get_current_weather
Gets current weather conditions for a specified city.
Parameters:
city
(required): The cityy name to get weather forcountryCode
(optional): Country code (e.g., 'US', 'UK')
Example:
{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"get_current_weather","arguments":{"city":"London"}}}
get_weather_forecast
Gets weather forecast for the next 3 days.
Parameters:
city
(required): The cityy name to get forecast forcountryCode
(optional): Country code (e.g., 'US', 'UK')
Example:
{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"get_weather_forecast","arguments":{"city":"Tokyo"}}}
get_weather_alerts
Gets weather alerts and warnings for a location (simulated based on conditions).
Parameters:
city
(required): The city name to check for alertscountryCode
(optional): Country code (e.g., 'US', 'UK')
Example:
{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"get_weather_alerts","arguments":{"city":"Miami","countryCode":"US"}}}
Testing the Server
- Initialize the server:
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"1.0.0","capabilities":{},"clientInfo":{"name":"test-client","version":"1.0.0"}}}
- List available tools:
{"jsonrpc":"2.0","id":2,"method":"tools/list"}
- Call a tool:
{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"get_current_weather","arguments":{"city":"London"}}}
Local Development Configuration
To configure the server for local development in your IDE:
VS Code: Create .vscode/mcp.json
:
{
"servers": {
"WeatherMcpServer": {
"type": "stdio",
"command": "dotnet",
"args": [
"run",
"--project",
"C:/path/to/WeatherMcpServer"
]
}
}
}
Visual Studio: Create .mcp.json
in solution directory:
{
"servers": {
"WeatherMcpServer": {
"type": "stdio",
"command": "dotnet",
"args": [
"run",
"--project",
"WeatherMcpServer"
]
}
}
}
Project Structure
WeatherMcpServer/
āāā Program.cs # Entry point
āāā Services/
ā āāā WeatherService.cs # OpenWeatherMap API integration
āāā Tools/
ā āāā WeatherTools.cs # MCP tool implementations
āāā WeatherMcpServer.csproj # Project configuration
āāā .mcp/
ā āāā server.json # MCP server metadata
āāā README.md # This file
Implementation Details
- Uses metric units (Celsius, m/s) by default
- Weather alerts are simulated based on current conditions
- Forecast provides 3-day outlook with 3-hour intervals
- All responses include proper error handling for invalid inputs
Troubleshooting
401 Unauthorized Error:
- Verify your API key is correctly set as an environment variable
- Ensure you've restarted the server after setting the API key
- Check that your API key is active on OpenWeatherMap
City Not Found:
- Verify the city name spelling
- Try adding a country code for more specific results
- Use major city names for best results
Example Responses
Current Weather:
Current weather in London:
Temperature: 15.2°C (feels like 14.8°C)
Condition: light rain
Humidity: 82%
Wind: 4.1 m/s
Visibility: 10 km
Weather Forecast:
Weather forecast for London, GB:
Monday, January 20
Temperature: 8.5°C - 12.3°C
Condition: light rain
09:00 - 9.2°C, light rain
12:00 - 11.8°C, overcast clouds
15:00 - 12.1°C, light rain
Weather Alerts:
Weather alerts for Phoenix:
HEAT WARNING: Extreme temperatures expected. Stay hydrated and avoid prolonged sun exposure.