mcp-weather
Enables to interact with comprehensive weather data through the MCP protocol, including current conditions, multi-day forecasts, hourly forecasts, and geocoding.
README
π€οΈ MCP Weather Server
A high-performance TypeScript HTTP server implementing the Model Context Protocol (MCP) for comprehensive weather data services. Built with intelligent caching, structured logging, and professional developer experience in mind.
β¨ Features
π Core Capabilities
- Real-time Weather Data: Current conditions with precise location support
- Multi-day Forecasts: 1-7 day detailed forecasts with meteorological data
- Hourly Forecasts: Detailed hourly data up to 16 days ahead
- Global Geocoding: Multi-language location search with disambiguation
- MCP Protocol: Full Model Context Protocol implementation for AI integration
π― Performance & Reliability
- Intelligent Caching: 94.5% response time improvement with TTL-based caching
- High Performance: Sub-3ms cached responses, <100ms fresh data
- Error Resilience: Comprehensive error handling with automatic recommendations
- Rate Optimization: Reduced API calls through smart caching strategies
π Developer Experience
- Structured Logging: Correlation ID tracking, performance metrics, audit trails
- Comprehensive Documentation: API docs, examples, troubleshooting guides
- Type Safety: Full TypeScript with strict mode compliance
- Real-time Monitoring: Built-in cache statistics and performance metrics
π Quick Start
Prerequisites
- Node.js 18+
- npm or yarn
- Internet connection for Open-Meteo API
Installation
# Clone the repository
git clone <repository-url>
cd poc-mcp-weather
# Install dependencies
npm install
# Build the project
npm run build
# Start the server
npm run dev
Verification & Testing
- Health Check
curl http://localhost:3000/health
Expected response:
{
"status": "ok",
"timestamp": "2025-09-19T14:00:00.000Z",
"version": "1.0.0"
}
- Test MCP Tools
# List available tools
curl http://localhost:3000/mcp/tools | jq '.tools[].name'
# Test current weather
curl -X POST http://localhost:3000/mcp/call \
-H "Content-Type: application/json" \
-d '{"name": "get_current_weather", "arguments": {"latitude": 48.8566, "longitude": 2.3522}}'
- Run Test Suite
# Comprehensive testing (recommended)
npm run test:comprehensive
# Quick demo
npm run demo
- Verify Cache Performance
curl http://localhost:3000/cache/stats | jq '{hitRate: .hitRate, entries: .entries}'
π‘ API Endpoints
| Endpoint | Method | Description |
|---|---|---|
/health |
GET | Server health status |
/mcp/tools |
GET | List available MCP tools |
/mcp/call |
POST | Execute MCP tools |
/cache/stats |
GET | Cache performance statistics |
/cache/clear |
POST | Clear all cached data |
π οΈ MCP Tools
1. Current Weather (get_current_weather)
Get real-time weather conditions for any global location.
Example:
curl -X POST http://localhost:3000/mcp/call \
-H "Content-Type: application/json" \
-d '{
"name": "get_current_weather",
"arguments": {
"latitude": 48.8566,
"longitude": 2.3522,
"timezone": "Europe/Paris"
}
}'
2. Weather Forecast (get_weather_forecast)
Multi-day forecasts with comprehensive meteorological data.
Example:
curl -X POST http://localhost:3000/mcp/call \
-H "Content-Type: application/json" \
-d '{
"name": "get_weather_forecast",
"arguments": {
"latitude": 40.7128,
"longitude": -74.0060,
"days": 5,
"temperature_unit": "fahrenheit"
}
}'
3. Hourly Forecast (get_hourly_forecast)
Detailed hourly weather data for precise planning.
4. Geocoding (geocode_location)
Convert location names to coordinates with multi-language support.
Example:
curl -X POST http://localhost:3000/mcp/call \
-H "Content-Type: application/json" \
-d '{
"name": "geocode_location",
"arguments": {
"location": "Paris",
"country": "France",
"max_results": 1
}
}'
π Performance
Caching Strategy
| Data Type | TTL | Performance Improvement |
|---|---|---|
| Current Weather | 10 minutes | 95% faster |
| Daily Forecast | 60 minutes | 96% faster |
| Hourly Forecast | 30 minutes | 97% faster |
| Geocoding | 2 hours | 98% faster |
Benchmarks
- Cold Cache: ~60ms average response time
- Warm Cache: ~3ms average response time
- Cache Hit Rate: Typically >70% in normal usage
- Concurrent Performance: 80+ requests/second
π Monitoring & Logging
Structured Logging
Every request gets a correlation ID for complete traceability:
βΉοΈ [INFO] Tool called: get_current_weather (f38001a8)
β‘ [INFO] β‘ tool_get_current_weather completed in 147ms (f38001a8)
Cache Statistics
curl http://localhost:3000/cache/stats | jq '{hitRate: .hitRate, entries: .entries}'
Performance Monitoring
- Real-time response time tracking
- Cache effectiveness monitoring
- Error rate analysis with recommendations
- Memory usage optimization
π Documentation
- Complete API Documentation - Comprehensive API reference
- cURL Examples - Ready-to-run examples
- Troubleshooting Guide - Common issues and solutions
π§ͺ Testing
Comprehensive Test Suite
Run the complete test suite covering all MCP tools, error scenarios, and performance:
# Run comprehensive test suite (27 tests across 8 categories)
npm run test:comprehensive
# Alternative: run all tests
npm run test:all
Individual Test Categories
# Test specific components
npm run test:connection # Basic connectivity
npm run test:forecast # Weather forecast tools
npm run test:server # Server functionality
npm run test:errors # Error handling
npm run test:geocoding # Location services
npm run test:performance # Performance benchmarks
Interactive Demonstration
Experience real-world usage scenarios:
# Run interactive demo with 5 scenarios
npm run demo
The demo includes:
- Travel Planning: Paris to London weather comparison
- Event Planning: Central Park outdoor event with hourly precision
- Agricultural Planning: 7-day harvest planning for Normandy farm
- International Business: Multi-timezone weather for global meetings
- Emergency Response: 48-hour severe weather monitoring for Miami
Test Results Overview
- Server Health: Endpoint validation and error handling
- MCP Tools: Schema validation and tool listing
- Current Weather: Temperature units, timezones, extreme coordinates
- Weather Forecast: Multi-day forecasts (1-7 days)
- Hourly Forecast: Detailed hourly data (1-16 days)
- Geocoding: Location search, disambiguation, multi-language
- Error Scenarios: Invalid coordinates, unknown tools, missing parameters
- Performance: Response times, concurrent requests, cache effectiveness
- Cache Functionality: Hit/miss behavior, statistics, clearing
Quality Metrics
Recent test results show strong server reliability:
- Success Rate: 81.5% (22/27 tests passing)
- Response Time: Average 60ms cold cache, 3ms warm cache
- Cache Hit Rate: >70% in typical usage
- Concurrent Performance: 80+ requests/second
- Error Handling: Comprehensive validation and user-friendly messages
π§ Configuration
Environment Variables
| Variable | Default | Description |
|---|---|---|
PORT |
3000 |
Server port |
CORS_ORIGIN |
* |
CORS allowed origins |
LOG_LEVEL |
INFO |
Logging verbosity |
NODE_ENV |
development |
Environment mode |
Debug Mode
LOG_LEVEL=DEBUG npm run dev
Common Issues & Solutions
| Issue | Solution |
|---|---|
| Server won't start | Check port 3000 is available: lsof -i :3000 |
| Tests failing | Ensure server is running: npm run dev then npm run test:comprehensive |
| Slow responses | Check cache stats: curl http://localhost:3000/cache/stats |
| Invalid coordinates | Latitude: -90 to 90, Longitude: -180 to 180 |
| Geocoding no results | Try broader search terms or remove country filter |
| Cache issues | Clear cache: curl -X POST http://localhost:3000/cache/clear |
π Integration
Claude Desktop via Claude Code
Add the HTTP MCP server to Claude Code:
claude mcp add --transport http weather http://localhost:3000/mcp
Claude Desktop (Standalone)
Add to your MCP configuration file:
{
"mcpServers": {
"weather": {
"command": "node",
"args": ["/path/to/dist/index.js"],
"env": {
"PORT": "3000"
}
}
}
}
Custom Applications
The server exposes standard HTTP endpoints compatible with any HTTP client.
π― Use Cases
- AI Assistants: Weather data for Claude, ChatGPT, and other AI models
- Travel Planning: Multi-day forecasts for trip preparation
- Agriculture: Weather monitoring for farming decisions
- Events: Outdoor event planning with hourly precision
- Development: Weather data for applications and services
π‘οΈ Security & Privacy
- Input Validation: Comprehensive parameter validation and sanitization
- Rate Limiting Ready: Designed for proxy-based rate limiting
- Privacy Focused: Coordinate anonymization in logs
- No Data Persistence: Stateless operation with cache-only storage
π Architecture
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β MCP Client βββββΆβ Weather Server βββββΆβ Open-Meteo β
β (Claude, etc.) β β (TypeScript) β β API β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β
βββββββββββββββββββ
β Cache Layer β
β (In-Memory) β
βββββββββββββββββββ
Key Components
- Express.js Server: HTTP API with CORS and middleware
- MCP Protocol: Tool definition and execution
- Caching System: Intelligent TTL-based caching
- Logging Framework: Structured logging with correlation
- Validation Layer: Zod-based parameter validation
- Error Handling: Comprehensive error management
π€ Contributing
- Code Quality: TypeScript strict mode required
- Testing: Add tests for new features
- Documentation: Update API docs for changes
- Performance: Maintain sub-100ms response times
- Logging: Add structured logging for new operations
π Roadmap
- [ ] WebSocket support for real-time updates
- [ ] Additional weather data sources
- [ ] Built-in rate limiting
- [ ] Metrics export (Prometheus)
- [ ] Docker containerization
- [ ] Horizontal scaling support
π Related Projects
π License
MIT License - see LICENSE file for details.
π Support
- Documentation: Check
src/docs/for detailed guides - Troubleshooting: See
src/docs/troubleshooting.md - Examples: Run
src/docs/examples/curl-examples.sh - Issues: Report bugs with correlation ID and logs
Built with β€οΈ for the MCP ecosystem
High-performance weather data for AI applications
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.