UNPKG

@bashcat/cwa-mcp-weather

Version:

MCP 伺服器整合中央氣象署 (CWA) 開放資料 API - 完整支援所有15個天氣工具

39 lines 1.46 kB
import { CWAAPIClient } from './cwa-client.js'; // 測試 CWA API 客戶端 async function testCWAClient() { // 檢查環境變數 const apiKey = process.env.CWA_API_KEY; if (!apiKey) { console.error('請設定環境變數 CWA_API_KEY'); process.exit(1); } const client = new CWAAPIClient(apiKey); try { console.log('🧪 測試 CWA API 連線...'); const isConnected = await client.testConnection(); console.log(isConnected ? '✅ 連線成功' : '❌ 連線失敗'); if (isConnected) { console.log('\n📍 測試查詢台北市天氣...'); const data = await client.getCountyWeather({ locationName: ['臺北市'], elementName: ['Wx', 'PoP', 'MinT', 'MaxT'] }); console.log('📊 查詢結果:'); console.log(client.formatWeatherData(data)); console.log('\n🏘️ 測試查詢桃園市鄉鎮天氣...'); const townshipData = await client.getTownshipWeather({ county: '桃園市', period: '3days', locationName: ['中壢區'] }); console.log('📊 鄉鎮查詢結果:'); console.log(client.formatWeatherData(townshipData)); } } catch (error) { console.error('❌ 測試失敗:', error); } } // 執行測試 testCWAClient(); //# sourceMappingURL=test.js.map