#!/usr/bin/env node
/**
* Simple test runner for MCP Open Meteo Server
* Validates that all tools work correctly
*/
import { getCurrentWeather } from './tools/current-weather.js';
import { getWeatherForecast } from './tools/weather-forecast.js';
import { getHistoricalWeather } from './tools/historical-weather.js';
import { searchLocations } from './tools/geocoding.js';
import { getAirQuality } from './tools/air-quality.js';
import { getMarineWeather } from './tools/marine-weather.js';
import { getClimateData } from './tools/climate-data.js';
// Test data
const testLocation = {
latitude: 51.5074, // London
longitude: -0.1278,
name: 'London'
};
const tests = [
{
name: 'Search Locations',
tool: searchLocations,
args: { name: 'London', count: 3 }
},
{
name: 'Current Weather',
tool: getCurrentWeather,
args: { ...testLocation, units: 'celsius' }
},
{
name: 'Weather Forecast',
tool: getWeatherForecast,
args: { ...testLocation, days: 3, units: 'celsius' }
},
{
name: 'Historical Weather',
tool: getHistoricalWeather,
args: {
...testLocation,
start_date: '2023-12-01',
end_date: '2023-12-07',
units: 'celsius'
}
},
{
name: 'Air Quality',
tool: getAirQuality,
args: { ...testLocation, days: 2 }
},
{
name: 'Marine Weather',
tool: getMarineWeather,
args: { ...testLocation, days: 3 }
},
{
name: 'Climate Data',
tool: getClimateData,
args: {
...testLocation,
start_date: '2020-01-01',
end_date: '2020-01-31',
models: ['EC_Earth3P']
}
}
];
async function runTests() {
console.log('๐งช Running MCP Open Meteo Server Tests\n');
let passed = 0;
let failed = 0;
for (const test of tests) {
try {
console.log(`Testing: ${test.name}...`);
const result = await test.tool(test.args);
if (result && result.content && Array.isArray(result.content) && result.content.length > 0) {
console.log(`โ
${test.name} - PASSED`);
passed++;
} else {
console.log(`โ ${test.name} - FAILED (Invalid response format)`);
failed++;
}
} catch (error) {
console.log(`โ ${test.name} - FAILED (${error.message})`);
failed++;
}
}
console.log(`\n๐ Test Results:`);
console.log(`โ
Passed: ${passed}`);
console.log(`โ Failed: ${failed}`);
console.log(`๐ Success Rate: ${Math.round((passed / (passed + failed)) * 100)}%`);
if (failed === 0) {
console.log('\n๐ All tests passed! The MCP server is ready to use.');
} else {
console.log('\nโ ๏ธ Some tests failed. Check the error messages above.');
}
}
// Only run if this file is executed directly
if (import.meta.url === `file://${process.argv[1]}`) {
runTests().catch(console.error);
}