ahmad7744/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 Model Context Protocol server that provides real-time weather information through a RESTful API, integrating with OpenWeatherMap API.
Weather MCP Server
A Model Context Protocol (MCP) server that provides weather information through a RESTful API. This server integrates with OpenWeatherMap API to fetch real-time weather data and can be used with AI assistants like Claude.
๐ Features
- MCP Protocol Support: Implements the Model Context Protocol for seamless AI integration
- Weather Data: Real-time weather information from OpenWeatherMap API
- RESTful API: HTTP endpoints for easy integration
- CORS Support: Cross-origin resource sharing enabled
- Error Handling: Robust error handling and validation
- TypeScript: Written in TypeScript for better type safety
๐ Quick Start
Prerequisites
- Node.js >= 18.0.0
- OpenWeatherMap API key
Installation
-
Clone the repository
git clone <repository-url> cd weather-mcp-server
-
Install dependencies
npm install
-
Set up environment variables
export OPENWEATHER_API_KEY="your-openweather-api-key"
-
Start the server
npm start
๐ Usage
Development Mode
Run the server in development mode with auto-restart:
npm run dev
Production Mode
Run the server in production:
npm start
๐ง API Endpoints
GET /api/weather/:city
Get weather information for a specific city.
Parameters:
city
(string): The city name to get weather for
Example Request:
curl http://localhost:3000/api/weather/London
Example Response:
{
"city": "London",
"temperature": 15.2,
"description": "scattered clouds",
"humidity": 72,
"windSpeed": 3.6
}
POST /api/mcp
MCP protocol endpoint for AI integration.
Example Request:
{
"method": "tools/call",
"params": {
"name": "get-weather",
"arguments": {
"city": "New York"
}
}
}
๐ ๏ธ Configuration
Environment Variables
Variable | Description | Required |
---|---|---|
OPENWEATHER_API_KEY | Your OpenWeatherMap API key | Yes |
PORT | Server port (default: 3000) | No |
Getting an OpenWeatherMap API Key
- Visit OpenWeatherMap
- Sign up for a free account
- Navigate to your API keys section
- Copy your API key and set it as an environment variable
๐ Project Structure
weather-mcp-server/
โโโ src/
โ โโโ index.js # Main server file
โโโ package.json # Dependencies and scripts
โโโ README.md # This file
โโโ .gitignore # Git ignore rules
๐ MCP Integration
This server implements the Model Context Protocol, making it compatible with AI assistants that support MCP. The server provides a get-weather
tool that can be called by AI assistants to retrieve weather information.
Available Tools
- get-weather: Retrieves current weather information for a specified city
๐งช Testing
Currently, no automated tests are configured. You can test the API manually using curl or any HTTP client.
Example test:
# Test weather endpoint
curl http://localhost:3000/api/weather/Tokyo
# Test MCP endpoint
curl -X POST http://localhost:3000/api/mcp \
-H "Content-Type: application/json" \
-d '{"method":"tools/call","params":{"name":"get-weather","arguments":{"city":"Paris"}}}'
๐ค Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
๐ License
This project is licensed under the MIT License - see the file for details.
๐ Acknowledgments
- Model Context Protocol - For the MCP specification
- OpenWeatherMap - For weather data API
- Express.js - For the web framework
๐ Support
If you encounter any issues or have questions, please:
- Check the Issues page
- Create a new issue with detailed information about your problem
- Include your Node.js version, operating system, and any error messages
Happy coding! ๐ค๏ธ