udayauma/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.
The Weather MCP Server is a simple Model Context Protocol server that provides weather information and demonstrates the core concepts of building MCP servers.
get_weather
Get current weather for any location
get_weather_forecast
Get weather forecast for a location
Weather MCP Server
A simple Model Context Protocol (MCP) server that provides weather information and demonstrates the core concepts of building MCP servers.
Features
This MCP server demonstrates:
- Resources: Weather data for different locations (New York, London, Tokyo)
- Tools: Functions to get current weather and forecasts
- Prompts: Templates for weather reports and comparisons
Installation
- Install the required dependencies:
pip3 install -r requirements.txt
- (Optional) Create a
.env
file for configuration:
WEATHER_API_KEY=your_weather_api_key_here
SERVER_NAME=weather-mcp-server
SERVER_VERSION=1.0.0
LOG_LEVEL=INFO
Running the Server
Run the server directly:
python3 weather_mcp_server.py
Available Resources
The server provides weather resources for:
weather://new_york
- Weather for New York, NYweather://london
- Weather for London, UKweather://tokyo
- Weather for Tokyo, Japan
Available Tools
-
get_weather: Get current weather for any location
- Parameters:
location
(string, required)
- Parameters:
-
get_weather_forecast: Get weather forecast for a location
- Parameters:
location
(string, required),days
(integer, 1-7, default: 3)
- Parameters:
Available Prompts
-
weather_report: Generate a detailed weather report
- Parameters:
location
(string, required)
- Parameters:
-
weather_comparison: Compare weather between two locations
- Parameters:
location1
(string, required),location2
(string, required)
- Parameters:
Testing the Server
You can test the server using the MCP inspector tool or integrate it with an MCP-compatible client.
Example Usage
This is a mock implementation that uses sample data. In a real-world scenario, you would:
- Replace the mock data with actual weather API calls
- Add authentication and error handling
- Implement caching for better performance
- Add more detailed weather information
MCP Protocol Overview
This server implements the Model Context Protocol, which consists of:
- Resources: Static or dynamic data sources that can be read
- Tools: Functions that can be called to perform actions
- Prompts: Template messages for LLM interactions
The server communicates via JSON-RPC over stdio, making it easy to integrate with various MCP clients.
Extending the Server
To add new functionality:
- Add new tools: Define new functions in the
handle_call_tool
method - Add new resources: Update the
handle_list_resources
andhandle_read_resource
methods - Add new prompts: Update the
handle_list_prompts
andhandle_get_prompt
methods
Dependencies
mcp>=1.0.0
: Model Context Protocol SDKhttpx>=0.25.0
: HTTP client for API callspython-dotenv>=1.0.0
: Environment variable loading