Package Exports
- @thiagosqr/weathernow-mcp
- @thiagosqr/weathernow-mcp/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@thiagosqr/weathernow-mcp) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
WeatherNow MCP Tool
A Model Context Protocol (MCP) tool for accessing real-time weather information using the Weatherstack API. This tool can be installed as an npm package and integrated into MCP-compatible applications.
Features
- 🌤️ Get current weather information for any location worldwide
- 🌍 Support for cities, countries, and coordinates
- 📊 Detailed weather data including temperature, humidity, wind, and more
- 🎨 Formatted output with emojis for better readability
- ⚡ Fast and reliable API responses
- 🔒 Secure API key management with environment variables
- 📦 Easy installation as an npm package
Installation
Prerequisites
- Node.js 18.0.0 or higher
- A Weatherstack API key (free at weatherstack.com)
Install the Package
npm install weathernow-mcpGet Your API Key
- Visit Weatherstack
- Sign up for a free account
- Get your API key from the dashboard
- Set it as an environment variable:
export WEATHERSTACK_API_KEY="your_api_key_here"Usage
As an MCP Server
The package can be used as an MCP server that provides weather information to MCP clients.
# Start the MCP server
npx weathernow-mcpProgrammatic Usage
import { WeatherService } from 'weathernow-mcp';
const weatherService = new WeatherService(process.env.WEATHERSTACK_API_KEY!);
// Get weather for a location
const weather = await weatherService.getCurrentWeather('New York');
if ('error' in weather) {
console.error('Error:', weather.error.info);
} else {
console.log(weatherService.formatWeatherData(weather));
}MCP Tool Integration
The tool provides a weathernow tool with the following parameters:
location(required): The location to get weather for (e.g., "New York", "London", "Tokyo")format(optional): Output format - "detailed" (default) or "simple"
Example MCP tool call:
{
"name": "weathernow",
"arguments": {
"location": "Paris, France",
"format": "detailed"
}
}API Reference
WeatherService
Constructor
new WeatherService(apiKey: string)Methods
getCurrentWeather(location: string): Promise<WeatherData | WeatherError>
Fetches current weather data for the specified location.
Parameters:
location: The location to get weather for (city name, country, coordinates, etc.)
Returns:
WeatherData: Weather information objectWeatherError: Error object if the request fails
formatWeatherData(data: WeatherData): string
Formats weather data into a human-readable string with emojis.
Parameters:
data: WeatherData object to format
Returns:
string: Formatted weather information
WeatherData Interface
interface WeatherData {
location: {
name: string;
country: string;
region: string;
lat: string;
lon: string;
timezone_id: string;
localtime: string;
localtime_epoch: number;
utc_offset: string;
};
current: {
observation_time: string;
temperature: number;
weather_code: number;
weather_icons: string[];
weather_descriptions: string[];
wind_speed: number;
wind_degree: number;
wind_dir: string;
pressure: number;
precip: number;
humidity: number;
cloudcover: number;
feelslike: number;
uv_index: number;
visibility: number;
is_day: string;
};
}Development
Setup
Clone the repository
Install dependencies:
npm install
Set up environment variables:
cp .env.example .env # Edit .env and add your API key
Build the project:
npm run build
Testing
Run the test suite:
npm testBuilding
Build the TypeScript source:
npm run buildConfiguration
Environment Variables
WEATHERSTACK_API_KEY: Your Weatherstack API key (required)
MCP Server Configuration
The MCP server can be configured by setting environment variables:
export WEATHERSTACK_API_KEY="your_api_key_here"Error Handling
The tool provides comprehensive error handling for:
- Invalid API keys
- Network connectivity issues
- Invalid location names
- API rate limiting
- Service unavailability
All errors are returned in a consistent format with error codes and descriptive messages.
License
MIT License - see LICENSE file for details.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
Support
For issues and questions:
- Check the GitHub Issues
- Create a new issue with detailed information
- Include your Node.js version and error messages
Changelog
1.0.0
- Initial release
- Weatherstack API integration
- MCP server implementation
- TypeScript support
- Comprehensive error handling