Implements environment variable management for storing and accessing API keys and configuration settings like OpenAI and OpenWeatherMap credentials.
Uses OpenAI's GPT-3.5-turbo model to power the AI chatbot interface, enabling natural language processing and conversational interactions for weather queries.
Serves as the implementation language for the MCP server, providing the runtime environment for the weather information service.
Weather AI Chatbot with MCP Integration
A Python-based AI chatbot that uses OpenAI's GPT model and integrates with a Model Context Protocol (MCP) server to provide real-time weather information from OpenWeatherMap API.
Features
- 🤖 AI-Powered Chatbot: Uses OpenAI's GPT-3.5-turbo for natural language processing
- 🌤️ Real-time Weather Data: Access current weather and forecasts for any city worldwide
- 🔌 MCP Integration: Implements Model Context Protocol for modular service architecture
- 💬 Conversational Interface: Natural language interaction with weather queries
- 📊 Detailed Weather Information: Temperature, humidity, wind, pressure, and more
- 🗓️ Weather Forecasts: Multi-day weather predictions
- 🔄 Conversation Memory: Maintains context across conversation turns
Architecture
Prerequisites
- Python 3.8 or higher
- OpenAI API key
- OpenWeatherMap API key
Installation
- Clone or download the project files
- Install dependencies:
- Set up environment variables:Edit
.env
and add your API keys:
Getting API Keys
OpenAI API Key
- Go to OpenAI Platform
- Sign up or log in
- Navigate to API Keys section
- Create a new API key
- Copy the key to your
.env
file
OpenWeatherMap API Key
- Go to OpenWeatherMap
- Sign up for a free account
- Navigate to API Keys section
- Generate a new API key
- Copy the key to your
.env
file
Usage
Starting the MCP Weather Server
First, start the MCP server that provides weather data:
The server will start on http://localhost:8000
by default.
Running the Chatbot
In a new terminal, start the chatbot:
Example Conversations
Available Commands
quit
,exit
,bye
- End the conversationreset
- Clear conversation history
Weather Query Examples
The chatbot can understand various ways to ask about weather:
- "What's the weather in Paris?"
- "How's the weather in Tokyo?"
- "Weather forecast for London"
- "Temperature in New York"
- "What's the weather like in Sydney?"
- "Forecast for Berlin this week"
- "Weather in Toronto tomorrow"
MCP Server Endpoints
The MCP server provides the following endpoints:
POST /mcp
- Handle MCP requestsGET /capabilities
- Get server capabilities
Available Methods
- weather/get_current
- Parameters:
city
(required),country_code
(optional) - Returns: Current weather information
- Parameters:
- weather/get_forecast
- Parameters:
city
(required),country_code
(optional),days
(optional, max 5) - Returns: Weather forecast information
- Parameters:
Testing
You can test the MCP client independently:
This will test the weather service with sample requests.
Error Handling
The system includes comprehensive error handling for:
- API connection issues
- Invalid city names
- Missing API keys
- Network timeouts
- Malformed responses
Configuration
You can customize the following settings in your .env
file:
MCP_SERVER_HOST
- MCP server hostname (default: localhost)MCP_SERVER_PORT
- MCP server port (default: 8000)OPENAI_API_KEY
- Your OpenAI API keyOPENWEATHER_API_KEY
- Your OpenWeatherMap API key
Troubleshooting
Common Issues
- "OPENAI_API_KEY environment variable is required"
- Make sure you've set up your
.env
file correctly - Verify your OpenAI API key is valid
- Make sure you've set up your
- "OPENWEATHER_API_KEY environment variable is required"
- Ensure your OpenWeatherMap API key is in the
.env
file - Check that the API key is active
- Ensure your OpenWeatherMap API key is in the
- "Failed to connect to MCP server"
- Make sure the MCP server is running (
python weather_mcp_server.py
) - Check that the host and port settings are correct
- Make sure the MCP server is running (
- "City not found" errors
- Verify the city name spelling
- Try adding a country code (e.g., "London, GB")
Debug Mode
To enable debug logging, modify the logging level in the Python files:
Contributing
Feel free to contribute to this project by:
- Reporting bugs
- Suggesting new features
- Improving documentation
- Adding new weather data sources
License
This project is open source and available under the MIT License.
Acknowledgments
- OpenAI for providing the GPT API
- OpenWeatherMap for weather data
- The MCP community for the protocol specification
This server cannot be installed
A Model Context Protocol server that interfaces with OpenWeatherMap API to provide real-time weather information and forecasts for cities worldwide.
Related MCP Servers
- AsecurityAlicenseAqualityA Model Context Protocol server that retrieves current weather information for specified cities using the Open-Meteo API, requiring no API key.Last updated -312PythonApache 2.0
- -securityFlicense-qualityA Model Context Protocol server that provides current weather information and 3-day forecasts for specified cities using the Open-Meteo API.Last updated -Python
- AsecurityAlicenseAqualityA Model Context Protocol server that provides comprehensive weather data and forecasts through the OpenWeatherMap API, enabling AI assistants to access real-time weather information, forecasts, air quality data, and location services.Last updated -1120JavaScriptMIT License
- AsecurityAlicenseAqualityA Model Context Protocol server that provides real-time weather data and forecasts for any city.Last updated -18ISC License