bhaveshxop/Build-your-first-MCP-Server
If you are the rightful owner of Build-your-first-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 beginner-friendly Model Context Protocol (MCP) server providing real-time weather data to Claude Desktop.
get_alerts
Get active weather alerts for a US state.
get_forecast
Get detailed weather forecast for specific coordinates.
Weather MCP Server ๐ค๏ธ
A beginner-friendly Model Context Protocol (MCP) server that provides real-time weather data to Claude Desktop. This project serves as a perfect starting point for anyone learning to build MCP servers.
๐ What is MCP?
The Model Context Protocol (MCP) allows AI assistants like Claude to securely connect to external data sources and tools. This weather server demonstrates how to:
- Create a basic MCP server using Python
- Integrate with Claude Desktop
- Fetch real-time data from external APIs
- Handle errors gracefully
โจ Features
- ๐ช๏ธ Weather Alerts: Get active weather alerts for any US state
- ๐ Weather Forecasts: Get detailed 5-day forecasts for any location
- ๐ง No External Dependencies: Uses only Python standard library (urllib)
- ๐ Comprehensive Logging: Built-in error handling and debugging
- ๐ Easy Setup: Works out of the box with minimal configuration
๐ฆ Installation
Prerequisites
- Python 3.8+ installed on your system
- Claude Desktop application
- Internet connection for weather data
Step 1: Clone the Repository
git clone https://github.com/your-username/weather-mcp-server.git
cd weather-mcp-server
Step 2: Install MCP Dependencies
pip install mcp
Note: This is the only dependency required! The weather server uses Python's built-in
urllib
library for HTTP requests to keep things simple.
Step 3: Test the Server
python weather.py
You should see: Starting Simple Weather MCP Server...
The server will run and wait for connections (this is normal behavior).
๐ง Claude Desktop Integration
Step 1: Find Your Claude Desktop Config
The configuration file is located at:
- Windows:
%APPDATA%\Claude\claude_desktop_config.json
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
- Linux:
~/.config/Claude/claude_desktop_config.json
Step 2: Update Configuration
Add this to your claude_desktop_config.json
:
{
"mcpServers": {
"weather": {
"command": "python",
"args": ["/path/to/your/weather-mcp-server/weather.py"]
}
}
}
Windows Example:
{
"mcpServers": {
"weather": {
"command": "C:\\Python312\\python.exe",
"args": ["C:\\Users\\YourName\\weather-mcp-server\\weather.py"]
}
}
}
macOS/Linux Example:
{
"mcpServers": {
"weather": {
"command": "/usr/bin/python3",
"args": ["/Users/YourName/weather-mcp-server/weather.py"]
}
}
}
Step 3: Restart Claude Desktop
- Completely close Claude Desktop
- Reopen Claude Desktop
- Look for the weather server connection status
๐งช Testing the Integration
Once connected, try these prompts in Claude Desktop:
What are the current weather alerts for California?
What's the weather forecast for New York City coordinates 40.7128, -74.0060?
Are there any active weather alerts for Texas?
๐ ๏ธ Available Tools
get_alerts(state: str)
Get active weather alerts for a US state.
Parameters:
state
: Two-letter US state code (e.g., "CA", "NY", "TX")
Example:
Get weather alerts for Florida
get_forecast(latitude: float, longitude: float)
Get detailed weather forecast for specific coordinates.
Parameters:
latitude
: Latitude coordinatelongitude
: Longitude coordinate
Example:
What's the weather forecast for coordinates 34.0522, -118.2437?
๐ Troubleshooting
Server Not Connecting
- Check Python Path: Ensure the Python path in your config is correct
- Verify File Path: Make sure the path to
weather.py
is absolute and correct - Restart Claude: Always restart Claude Desktop after config changes
- Check Logs: Look at the log file for error messages
Common Issues
Issue: "Server disconnected"
- Solution: Check that all dependencies are installed in the correct Python environment
Issue: "No module named 'mcp'"
- Solution: Install MCP:
pip install mcp
Issue: "File not found"
- Solution: Use absolute paths in your configuration
Viewing Logs
Check the log file created in your project directory:
- File:
weather.log
- Contains detailed error messages and request information
๐ Project Structure
weather-mcp-server/
โโโ weather.py # Main MCP server
โโโ weather.log # Log file (auto-generated)
โโโ README.md # This file
โโโ LICENSE # MIT License
โโโ .gitignore # Git ignore patterns
๐ง How It Works
- MCP Server:
weather.py
creates an MCP server using FastMCP - API Integration: Uses the National Weather Service API (no API key required)
- Tools Registration: Exposes
get_alerts
andget_forecast
as tools - Claude Integration: Claude Desktop connects via stdio transport
๐ Extending This Project
This basic weather server can be extended with:
- More Weather Data: Add hourly forecasts, radar data, etc.
- Additional APIs: Integrate other weather services
- Caching: Add response caching for better performance
- Error Handling: Enhanced error recovery and retries
- Configuration: Add config files for customization
๐ Learning Resources
๐ License
This project is licensed under the MIT License - see the file for details.
๐ก Acknowledgments
- Built with MCP (Model Context Protocol)
- Weather data from National Weather Service API
- Inspired by the need for accessible MCP learning resources
Happy coding! ๐ If this project helped you learn MCP, please give it a star โญ