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:
pip install -r requirements.txtSet up environment variables:
cp env.example .envEdit
.env
and add your API keys:OPENAI_API_KEY=your_openai_api_key_here OPENWEATHER_API_KEY=your_openweather_api_key_here MCP_SERVER_HOST=localhost MCP_SERVER_PORT=8000
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
weather/get_forecast
Parameters:
city
(required),country_code
(optional),days
(optional, max 5)Returns: Weather forecast information
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 correctlyVerify your OpenAI API key is valid
"OPENWEATHER_API_KEY environment variable is required"
Ensure your OpenWeatherMap API key is in the
.env
fileCheck that the API key is active
"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
"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
- -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 -
- -securityFlicense-qualityA production-ready Model Context Protocol server that provides weather data from OpenWeatherMap API, allowing users to query current weather by city name or coordinates with support for different temperature units.
- 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 -1132MIT License
- AsecurityAlicenseAqualityA Model Context Protocol server that provides real-time weather data and forecasts for any city.Last updated -111ISC License