@dangahagan/weather-mcp 0.2.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/README.md +372 -53
  2. package/dist/config/cache.d.ts +2 -0
  3. package/dist/config/cache.d.ts.map +1 -1
  4. package/dist/config/cache.js +48 -2
  5. package/dist/config/cache.js.map +1 -1
  6. package/dist/config/displayThresholds.d.ts +83 -0
  7. package/dist/config/displayThresholds.d.ts.map +1 -0
  8. package/dist/config/displayThresholds.js +83 -0
  9. package/dist/config/displayThresholds.js.map +1 -0
  10. package/dist/errors/ApiError.d.ts +62 -0
  11. package/dist/errors/ApiError.d.ts.map +1 -0
  12. package/dist/errors/ApiError.js +147 -0
  13. package/dist/errors/ApiError.js.map +1 -0
  14. package/dist/handlers/airQualityHandler.d.ts +11 -0
  15. package/dist/handlers/airQualityHandler.d.ts.map +1 -0
  16. package/dist/handlers/airQualityHandler.js +154 -0
  17. package/dist/handlers/airQualityHandler.js.map +1 -0
  18. package/dist/handlers/alertsHandler.d.ts +11 -0
  19. package/dist/handlers/alertsHandler.d.ts.map +1 -0
  20. package/dist/handlers/alertsHandler.js +82 -0
  21. package/dist/handlers/alertsHandler.js.map +1 -0
  22. package/dist/handlers/currentConditionsHandler.d.ts +11 -0
  23. package/dist/handlers/currentConditionsHandler.d.ts.map +1 -0
  24. package/dist/handlers/currentConditionsHandler.js +231 -0
  25. package/dist/handlers/currentConditionsHandler.js.map +1 -0
  26. package/dist/handlers/forecastHandler.d.ts +13 -0
  27. package/dist/handlers/forecastHandler.d.ts.map +1 -0
  28. package/dist/handlers/forecastHandler.js +337 -0
  29. package/dist/handlers/forecastHandler.js.map +1 -0
  30. package/dist/handlers/historicalWeatherHandler.d.ts +12 -0
  31. package/dist/handlers/historicalWeatherHandler.d.ts.map +1 -0
  32. package/dist/handlers/historicalWeatherHandler.js +188 -0
  33. package/dist/handlers/historicalWeatherHandler.js.map +1 -0
  34. package/dist/handlers/locationHandler.d.ts +11 -0
  35. package/dist/handlers/locationHandler.d.ts.map +1 -0
  36. package/dist/handlers/locationHandler.js +113 -0
  37. package/dist/handlers/locationHandler.js.map +1 -0
  38. package/dist/handlers/marineConditionsHandler.d.ts +11 -0
  39. package/dist/handlers/marineConditionsHandler.d.ts.map +1 -0
  40. package/dist/handlers/marineConditionsHandler.js +154 -0
  41. package/dist/handlers/marineConditionsHandler.js.map +1 -0
  42. package/dist/handlers/statusHandler.d.ts +12 -0
  43. package/dist/handlers/statusHandler.d.ts.map +1 -0
  44. package/dist/handlers/statusHandler.js +106 -0
  45. package/dist/handlers/statusHandler.js.map +1 -0
  46. package/dist/index.js +219 -377
  47. package/dist/index.js.map +1 -1
  48. package/dist/services/noaa.d.ts +24 -1
  49. package/dist/services/noaa.d.ts.map +1 -1
  50. package/dist/services/noaa.js +116 -43
  51. package/dist/services/noaa.js.map +1 -1
  52. package/dist/services/openmeteo.d.ts +110 -3
  53. package/dist/services/openmeteo.d.ts.map +1 -1
  54. package/dist/services/openmeteo.js +568 -112
  55. package/dist/services/openmeteo.js.map +1 -1
  56. package/dist/types/noaa.d.ts +158 -12
  57. package/dist/types/noaa.d.ts.map +1 -1
  58. package/dist/types/openmeteo.d.ts +448 -0
  59. package/dist/types/openmeteo.d.ts.map +1 -1
  60. package/dist/utils/airQuality.d.ts +54 -0
  61. package/dist/utils/airQuality.d.ts.map +1 -0
  62. package/dist/utils/airQuality.js +251 -0
  63. package/dist/utils/airQuality.js.map +1 -0
  64. package/dist/utils/cache.d.ts +11 -4
  65. package/dist/utils/cache.d.ts.map +1 -1
  66. package/dist/utils/cache.js +33 -4
  67. package/dist/utils/cache.js.map +1 -1
  68. package/dist/utils/fireWeather.d.ts +62 -0
  69. package/dist/utils/fireWeather.d.ts.map +1 -0
  70. package/dist/utils/fireWeather.js +168 -0
  71. package/dist/utils/fireWeather.js.map +1 -0
  72. package/dist/utils/logger.d.ts +59 -0
  73. package/dist/utils/logger.d.ts.map +1 -0
  74. package/dist/utils/logger.js +128 -0
  75. package/dist/utils/logger.js.map +1 -0
  76. package/dist/utils/marine.d.ts +38 -0
  77. package/dist/utils/marine.d.ts.map +1 -0
  78. package/dist/utils/marine.js +162 -0
  79. package/dist/utils/marine.js.map +1 -0
  80. package/dist/utils/temperatureConversion.d.ts +12 -0
  81. package/dist/utils/temperatureConversion.d.ts.map +1 -0
  82. package/dist/utils/temperatureConversion.js +17 -0
  83. package/dist/utils/temperatureConversion.js.map +1 -0
  84. package/dist/utils/validation.d.ts +89 -0
  85. package/dist/utils/validation.d.ts.map +1 -0
  86. package/dist/utils/validation.js +177 -0
  87. package/dist/utils/validation.js.map +1 -0
  88. package/package.json +10 -3
package/README.md CHANGED
@@ -4,16 +4,71 @@
4
4
  [![MCP Registry](https://img.shields.io/badge/MCP-Registry-blue)](https://registry.modelcontextprotocol.io/v0/servers?search=io.github.dgahagan/weather-mcp)
5
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
6
 
7
- An MCP (Model Context Protocol) server that provides weather data to AI systems like Claude Code. Uses NOAA's API for US weather forecasts and current conditions, plus Open-Meteo for global historical weather data.
7
+ An MCP (Model Context Protocol) server that provides **global weather data** to AI systems like Claude Code. Uses NOAA's API for detailed US weather, plus Open-Meteo for international forecasts and historical weather data worldwide.
8
8
 
9
9
  **📦 Available in the [Official MCP Registry](https://registry.modelcontextprotocol.io/v0/servers?search=io.github.dgahagan/weather-mcp)** as `io.github.dgahagan/weather-mcp`
10
10
 
11
- **No API keys required!** Both NOAA and Open-Meteo APIs are free to use with no authentication needed.
11
+ **No API keys required!** All APIs (NOAA, Open-Meteo) are free to use with no authentication needed.
12
12
 
13
13
  ## Features
14
14
 
15
- - **Get Forecast**: Retrieve weather forecasts for any US location (7-day forecast)
16
- - **Current Conditions**: Get real-time weather observations for US locations
15
+ - **Marine Conditions**: Comprehensive marine weather for coastal and ocean areas (NEW in v0.6.0)
16
+ - Global coverage for waves, swell, and ocean currents
17
+ - Significant wave height with safety categorization (Calm to Extreme)
18
+ - Wind waves (locally generated) and swell (distant systems) separation
19
+ - Wave period and direction for planning
20
+ - Ocean current velocity and direction
21
+ - Optional 5-day marine forecast with daily summaries
22
+ - Safety assessment for maritime activities (sailing, boating, surfing)
23
+ - Wave interpretation guide based on Douglas Sea Scale
24
+ - Important: Data has limited coastal accuracy - NOT for navigation
25
+ - **Severe Weather Probabilities**: Probabilistic severe weather forecasting (NEW in v0.6.0)
26
+ - US locations only (NOAA gridpoint data)
27
+ - Optional enhancement to forecasts (`include_severe_weather` parameter)
28
+ - Thunderstorm probability for next 48 hours
29
+ - Wind gust probabilities (20-60+ mph categories)
30
+ - Tropical storm and hurricane wind probabilities
31
+ - Lightning activity levels
32
+ - Smart display showing only significant threats
33
+ - Works with both daily and hourly forecasts
34
+ - **Air Quality Monitoring**: Comprehensive air quality data for any location worldwide (v0.5.0)
35
+ - Air Quality Index (AQI) with automatic region detection (US AQI or European EAQI)
36
+ - Health recommendations based on AQI levels
37
+ - Pollutant concentrations (PM2.5, PM10, O₃, NO₂, SO₂, CO, NH₃)
38
+ - UV Index with sun protection recommendations
39
+ - Optional hourly air quality forecasts (5-day outlook)
40
+ - Categorized health risk levels (Good, Moderate, Unhealthy, etc.)
41
+ - Activity recommendations for sensitive populations
42
+ - **Fire Weather Data**: Fire danger indices for US locations (v0.5.0)
43
+ - Haines Index (atmospheric fire growth potential)
44
+ - Grassland Fire Danger Index
45
+ - Red Flag Threat Index
46
+ - Mixing Height (smoke dispersion indicator)
47
+ - Transport Wind Speed (smoke transport)
48
+ - Optional enhancement to current conditions
49
+ - **Location Search**: Find coordinates for any location worldwide (v0.4.0)
50
+ - Convert location names to coordinates ("Paris" → 48.8534°, 2.3488°)
51
+ - Support for cities, airports, landmarks, and regions globally
52
+ - Detailed metadata: timezone, elevation, population, country
53
+ - Enables natural language queries: "What's the weather in Tokyo?"
54
+ - **Global Weather Forecasts**: Get forecasts for any location worldwide (ENHANCED in v0.4.0)
55
+ - Automatic source selection: NOAA (US, more detailed) or Open-Meteo (international)
56
+ - Extended forecasts up to 16 days (was 7)
57
+ - Sunrise/sunset times with daylight duration
58
+ - Daily or hourly granularity
59
+ - Precipitation probability display
60
+ - Temperature trends, humidity, wind, and UV index
61
+ - **Weather Alerts**: Get active weather watches, warnings, and advisories for US locations
62
+ - Severity levels (Extreme, Severe, Moderate, Minor)
63
+ - Urgency and certainty indicators
64
+ - Effective and expiration times
65
+ - Instructions and recommended responses
66
+ - **Current Conditions**: Get enhanced real-time weather observations for US locations
67
+ - Heat index and wind chill when relevant
68
+ - 24-hour temperature range
69
+ - Wind gusts and detailed cloud cover
70
+ - Recent precipitation history
71
+ - Optional fire weather indices (see above)
17
72
  - **Historical Data**: Access historical weather observations for any location worldwide
18
73
  - Recent data (last 7 days): Detailed hourly observations from NOAA real-time API (US only)
19
74
  - Archival data (>7 days old): Hourly/daily weather data from 1940-present via Open-Meteo (global coverage)
@@ -36,6 +91,11 @@ The Weather MCP server includes an intelligent in-memory caching system that sig
36
91
 
37
92
  The cache automatically stores and retrieves weather data with intelligent expiration:
38
93
 
94
+ - **Location Searches**: Cached for 30 days (locations don't move)
95
+ - **Marine Conditions**: Cached for 1 hour (marine data updates hourly) - NEW in v0.6.0
96
+ - **Air Quality Data**: Cached for 1 hour (air quality updates hourly) - v0.5.0
97
+ - **Fire Weather Data**: Cached for 2 hours (gridpoint data updates ~hourly) - v0.5.0
98
+ - **Weather Alerts**: Cached for 5 minutes (alerts can change rapidly)
39
99
  - **Forecasts**: Cached for 2 hours (updated approximately hourly)
40
100
  - **Current Conditions**: Cached for 15 minutes (observations update every 20-60 minutes)
41
101
  - **Historical Data (>1 day old)**: Cached indefinitely (finalized data never changes)
@@ -150,60 +210,109 @@ Restart Claude Code and the weather tools will be available.
150
210
 
151
211
  ## Finding Coordinates
152
212
 
153
- All tools require latitude and longitude coordinates. You can find coordinates for any location by:
154
- - Asking Claude Code: "What are the coordinates for [city name]?"
213
+ **NEW in v0.4.0**: Use the built-in `search_location` tool to find coordinates automatically!
214
+
215
+ ```
216
+ "What's the weather in Paris?"
217
+ → Uses search_location to find Paris coordinates (48.8534°, 2.3488°)
218
+ → Then gets the forecast for those coordinates
219
+ ```
220
+
221
+ You can also find coordinates manually:
155
222
  - Using Google Maps: Right-click a location and select the coordinates
156
223
  - Using a geocoding service like geocode.maps.co or nominatim.org
157
224
 
158
- ### Common US City Coordinates
225
+ ### Common City Coordinates (For Reference)
159
226
 
160
227
  | City | Latitude | Longitude |
161
228
  |------|----------|-----------|
162
- | San Francisco, CA | 37.7749 | -122.4194 |
229
+ | Paris, France | 48.8534 | 2.3488 |
230
+ | Tokyo, Japan | 35.6895 | 139.6917 |
231
+ | London, UK | 51.5085 | -0.1257 |
163
232
  | New York, NY | 40.7128 | -74.0060 |
164
- | Chicago, IL | 41.8781 | -87.6298 |
165
- | Los Angeles, CA | 34.0522 | -118.2437 |
166
- | Denver, CO | 39.7392 | -104.9903 |
167
- | Miami, FL | 25.7617 | -80.1918 |
168
- | Seattle, WA | 47.6062 | -122.3321 |
169
- | Austin, TX | 30.2672 | -97.7431 |
233
+ | San Francisco, CA | 37.7749 | -122.4194 |
234
+ | Sydney, Australia | -33.8688 | 151.2093 |
235
+ | Berlin, Germany | 52.5200 | 13.4050 |
236
+ | Dubai, UAE | 25.2048 | 55.2708 |
170
237
 
171
238
  ## Available Tools
172
239
 
173
- ### 1. check_service_status
174
- Check the operational status of weather APIs and cache performance.
240
+ ### 1. search_location (NEW in v0.4.0)
241
+ Find coordinates for any location worldwide by name.
175
242
 
176
- **Parameters:** None
243
+ **Parameters:**
244
+ - `query` (required): Location name to search for (e.g., "Paris", "New York, NY", "Tokyo")
245
+ - `limit` (optional): Maximum number of results to return (1-100, default: 5)
177
246
 
178
247
  **Description:**
179
- Performs health checks on both NOAA and Open-Meteo APIs to verify they are operational. Use this tool when experiencing errors or to proactively verify service availability before making weather data requests. Returns current status, helpful messages, links to official status pages, and cache statistics.
248
+ Converts location names to coordinates using the Open-Meteo Geocoding API. Returns multiple matches with detailed metadata including coordinates, timezone, elevation, population, and administrative regions. Enables natural language weather queries by finding coordinates automatically.
180
249
 
181
- **Example:**
250
+ **Examples:**
182
251
  ```
183
- Check if the weather services are operational
252
+ "Find coordinates for Paris"
253
+ "Search for Tokyo, Japan"
254
+ "Where is San Francisco, CA?"
184
255
  ```
185
256
 
186
257
  **Returns:**
187
- - Operational status for NOAA API (forecasts & current conditions)
188
- - Operational status for Open-Meteo API (historical data)
189
- - Cache statistics (hit rate, size, API call reduction)
190
- - Status page links and recommended actions if issues are detected
191
- - Overall service availability summary
258
+ - Location name and full administrative hierarchy
259
+ - Latitude and longitude coordinates
260
+ - Timezone and elevation
261
+ - Population (when available)
262
+ - Country and region information
263
+ - Feature type (capital, city, airport, etc.)
192
264
 
193
- ### 2. get_forecast
194
- Get weather forecast for a location.
265
+ ### 2. get_forecast (ENHANCED in v0.4.0)
266
+ Get weather forecast for any location worldwide.
195
267
 
196
268
  **Parameters:**
197
269
  - `latitude` (required): Latitude coordinate (-90 to 90)
198
270
  - `longitude` (required): Longitude coordinate (-180 to 180)
199
- - `days` (optional): Number of days in forecast (1-7, default: 7)
271
+ - `days` (optional): Number of days in forecast (1-16, default: 7)
272
+ - `granularity` (optional): "daily" or "hourly" (default: "daily")
273
+ - `include_precipitation_probability` (optional): Include rain chances (default: true)
274
+ - `source` (optional): "auto" (default), "noaa" (US only), or "openmeteo" (global)
275
+
276
+ **Description:**
277
+ Automatically selects the best data source: NOAA for US locations (more detailed) or Open-Meteo for international locations. Supports extended forecasts up to 16 days. Includes sunrise/sunset times, daylight duration, temperature, precipitation, wind, and UV index.
278
+
279
+ **Examples:**
280
+ ```
281
+ "Get a 7-day forecast for Paris (48.8534, 2.3488)"
282
+ "Hourly forecast for Tokyo for the next 3 days"
283
+ "16-day extended forecast for Sydney, Australia"
284
+ ```
285
+
286
+ **Returns:**
287
+ - Temperature (high/low, feels like)
288
+ - Sunrise and sunset times with daylight duration (NEW in v0.4.0)
289
+ - Precipitation chances and amounts
290
+ - Wind speed, direction, and gusts
291
+ - Weather conditions and descriptions
292
+ - UV index (for international locations)
293
+ - Humidity and atmospheric conditions
294
+
295
+ ### 3. check_service_status
296
+ Check the operational status of weather APIs and cache performance.
297
+
298
+ **Parameters:** None
299
+
300
+ **Description:**
301
+ Performs health checks on both NOAA and Open-Meteo APIs to verify they are operational. Use this tool when experiencing errors or to proactively verify service availability before making weather data requests. Returns current status, helpful messages, links to official status pages, and cache statistics.
200
302
 
201
303
  **Example:**
202
304
  ```
203
- Get the weather forecast for San Francisco (latitude: 37.7749, longitude: -122.4194)
305
+ Check if the weather services are operational
204
306
  ```
205
307
 
206
- ### 3. get_current_conditions
308
+ **Returns:**
309
+ - Operational status for NOAA API (forecasts & current conditions)
310
+ - Operational status for Open-Meteo API (historical data & forecasts)
311
+ - Cache statistics (hit rate, size, API call reduction)
312
+ - Status page links and recommended actions if issues are detected
313
+ - Overall service availability summary
314
+
315
+ ### 4. get_current_conditions
207
316
  Get current weather conditions for a location.
208
317
 
209
318
  **Parameters:**
@@ -215,7 +324,7 @@ Get current weather conditions for a location.
215
324
  What are the current weather conditions in New York? (latitude: 40.7128, longitude: -74.0060)
216
325
  ```
217
326
 
218
- ### 4. get_historical_weather
327
+ ### 5. get_historical_weather
219
328
  Get historical weather observations for a location.
220
329
 
221
330
  **Parameters:**
@@ -274,6 +383,88 @@ If you get "No historical data available":
274
383
  - Note: Most recent data has a 5-day delay
275
384
  - Very recent dates (last 5 days) may not be available in archival data yet
276
385
 
386
+ ### 6. get_alerts
387
+ Get active weather alerts, watches, warnings, and advisories for US locations.
388
+
389
+ **Parameters:**
390
+ - `latitude` (required): Latitude coordinate (-90 to 90)
391
+ - `longitude` (required): Longitude coordinate (-180 to 180)
392
+ - `active_only` (optional): Show only active alerts (default: true)
393
+
394
+ **Description:**
395
+ Retrieves current weather alerts from the NOAA API for safety-critical weather information. Returns severity levels (Extreme, Severe, Moderate, Minor), urgency indicators, effective/expiration times, and affected areas. Alerts are automatically sorted by severity with the most critical first.
396
+
397
+ **Examples:**
398
+ ```
399
+ "Are there any weather alerts for Miami, Florida?"
400
+ "Check for severe weather warnings in Oklahoma City"
401
+ "What weather watches are active in my area?" (latitude: 40.7128, longitude: -74.0060)
402
+ ```
403
+
404
+ **Returns:**
405
+ - Alert type and severity (Extreme → Severe → Moderate → Minor)
406
+ - Urgency, certainty, and response type
407
+ - Event description and instructions
408
+ - Effective and expiration times
409
+ - Affected geographic areas
410
+ - Recommended actions and safety information
411
+
412
+ ### 7. get_air_quality (NEW in v0.5.0)
413
+ Get comprehensive air quality data for any location worldwide.
414
+
415
+ **Parameters:**
416
+ - `latitude` (required): Latitude coordinate (-90 to 90)
417
+ - `longitude` (required): Longitude coordinate (-180 to 180)
418
+ - `forecast` (optional): Include hourly forecast for next 5 days (default: false)
419
+
420
+ **Description:**
421
+ Provides current air quality conditions using the Open-Meteo Air Quality API with automatic AQI scale selection (US AQI for US locations, European EAQI elsewhere). Includes health recommendations, pollutant concentrations, and UV index.
422
+
423
+ **Examples:**
424
+ ```
425
+ "What's the air quality in Los Angeles?"
426
+ "Check pollution levels in Beijing"
427
+ "Get air quality forecast for Paris for the next 5 days"
428
+ ```
429
+
430
+ **Returns:**
431
+ - Air Quality Index (AQI) with appropriate scale (US or European)
432
+ - Health risk category and recommendations
433
+ - Pollutant concentrations (PM2.5, PM10, O₃, NO₂, SO₂, CO, NH₃)
434
+ - UV Index with sun protection guidance
435
+ - Activity recommendations for sensitive groups
436
+ - Optional 5-day hourly forecast
437
+
438
+ ### 8. get_marine_conditions (NEW in v0.6.0)
439
+ Get marine weather conditions including wave height, swell, ocean currents, and sea state.
440
+
441
+ **Parameters:**
442
+ - `latitude` (required): Latitude coordinate (-90 to 90)
443
+ - `longitude` (required): Longitude coordinate (-180 to 180)
444
+ - `forecast` (optional): Include 5-day marine forecast (default: false)
445
+
446
+ **Description:**
447
+ Provides comprehensive marine weather data using the Open-Meteo Marine API with global ocean coverage. Includes significant wave height with Douglas Sea Scale categorization, wind waves vs swell separation, wave period/direction, ocean currents, and safety assessment for maritime activities.
448
+
449
+ **Important:** Data has limited accuracy in coastal areas and is NOT suitable for coastal navigation - always consult official marine forecasts.
450
+
451
+ **Examples:**
452
+ ```
453
+ "What are the ocean conditions off the coast of California?"
454
+ "Get wave height and swell for surfing in Hawaii"
455
+ "Check marine conditions in the Atlantic Ocean" (latitude: 30.0, longitude: -60.0)
456
+ ```
457
+
458
+ **Returns:**
459
+ - Significant wave height (meters/feet) with safety category
460
+ - Wind waves (locally generated) height and direction
461
+ - Swell height, period, and direction (from distant systems)
462
+ - Ocean current velocity and direction
463
+ - Sea state interpretation (Calm → Phenomenal based on Douglas Sea Scale)
464
+ - Safety assessment for maritime activities
465
+ - Wave period for planning and safety
466
+ - Optional 5-day forecast with daily summaries
467
+
277
468
  ## Error Handling & Service Status
278
469
 
279
470
  ### Enhanced Error Messages
@@ -346,19 +537,45 @@ Use the `check_service_status` tool to proactively verify API availability:
346
537
 
347
538
  ## Testing
348
539
 
349
- ### Quick Test
540
+ ### Automated Test Suite
541
+
542
+ This project includes a comprehensive test suite with 247 automated tests:
350
543
 
351
- Verify NOAA API connectivity:
352
544
  ```bash
353
- npx tsx tests/test_noaa_api.ts
545
+ # Run all tests
546
+ npm test
547
+
548
+ # Run tests with coverage report
549
+ npm run test:coverage
550
+
551
+ # Run tests in watch mode (during development)
552
+ npm run test:watch
553
+
554
+ # Run tests with interactive UI
555
+ npm run test:ui
354
556
  ```
355
557
 
356
- This runs 5 tests covering all major functionality with real NOAA API calls.
558
+ **Test Coverage:**
559
+ - **247 tests** across unit and integration test suites
560
+ - **100% coverage** on critical utilities (cache, validation, units, errors)
561
+ - **54% overall coverage** with focus on reliability and security
562
+ - All tests execute in ~1 second
563
+
564
+ **Test Categories:**
565
+ - **Unit Tests** (228 tests) - Cache, validation, units, errors, config, retry logic
566
+ - **Integration Tests** (19 tests) - Error recovery scenarios, service status checks
567
+
568
+ ### Quick API Connectivity Test
569
+
570
+ Verify NOAA API connectivity with a quick integration test:
571
+ ```bash
572
+ npx tsx tests/test_noaa_api.ts
573
+ ```
357
574
 
358
575
  ### Manual Testing with Claude Code
359
576
 
360
- See [TESTING_GUIDE.md](./docs/TESTING_GUIDE.md) for comprehensive testing instructions including:
361
- - Setup steps
577
+ See [TESTING_GUIDE.md](./docs/TESTING_GUIDE.md) for comprehensive manual testing instructions including:
578
+ - Setup steps for MCP clients
362
579
  - Test cases for all tools
363
580
  - Error handling verification
364
581
  - Performance testing
@@ -368,43 +585,89 @@ See [TESTING_GUIDE.md](./docs/TESTING_GUIDE.md) for comprehensive testing instru
368
585
 
369
586
  ### Available Scripts
370
587
 
588
+ **Build & Run:**
371
589
  - `npm run build` - Compile TypeScript to JavaScript
372
590
  - `npm run dev` - Run the server in development mode with tsx
373
591
  - `npm start` - Run the compiled server
374
- - `npx tsx tests/test_noaa_api.ts` - Run API connectivity tests
592
+
593
+ **Testing:**
594
+ - `npm test` - Run all automated tests
595
+ - `npm run test:coverage` - Run tests with coverage report
596
+ - `npm run test:watch` - Run tests in watch mode
597
+ - `npm run test:ui` - Run tests with interactive UI
598
+ - `npx tsx tests/test_noaa_api.ts` - Quick API connectivity test
599
+
600
+ **Security & Maintenance:**
601
+ - `npm run audit` - Check for dependency vulnerabilities
602
+ - `npm run audit:fix` - Automatically fix dependency vulnerabilities
375
603
 
376
604
  ### Project Structure
377
605
 
378
606
  ```
379
607
  weather-mcp/
380
608
  ├── src/
381
- │ ├── index.ts # Main MCP server
609
+ │ ├── index.ts # Main MCP server
610
+ │ ├── config/
611
+ │ │ ├── cache.ts # Cache configuration and TTL strategies
612
+ │ │ └── displayThresholds.ts # Display thresholds for weather conditions
613
+ │ ├── errors/
614
+ │ │ └── ApiError.ts # Custom error class hierarchy
615
+ │ ├── handlers/
616
+ │ │ ├── alertsHandler.ts # Weather alerts tool handler
617
+ │ │ ├── currentConditionsHandler.ts # Current conditions handler
618
+ │ │ ├── forecastHandler.ts # Forecast tool handler
619
+ │ │ ├── historicalWeatherHandler.ts # Historical weather handler
620
+ │ │ └── statusHandler.ts # Service status handler
382
621
  │ ├── services/
383
- │ │ ├── noaa.ts # NOAA real-time API service
384
- │ │ └── openmeteo.ts # Open-Meteo historical weather API service
622
+ │ │ ├── noaa.ts # NOAA API service
623
+ │ │ └── openmeteo.ts # Open-Meteo API service
385
624
  │ ├── types/
386
- │ │ ├── noaa.ts # NOAA TypeScript type definitions
387
- │ │ └── openmeteo.ts # Open-Meteo TypeScript type definitions
625
+ │ │ ├── noaa.ts # NOAA TypeScript type definitions
626
+ │ │ └── openmeteo.ts # Open-Meteo TypeScript type definitions
388
627
  │ └── utils/
389
- └── units.ts # Unit conversion utilities
390
- ├── dist/ # Compiled JavaScript (generated)
391
- ├── tests/ # Test files
628
+ ├── cache.ts # LRU cache implementation
629
+ ├── logger.ts # Structured logging utilities
630
+ ├── temperatureConversion.ts # Temperature conversion helpers
631
+ │ ├── units.ts # Unit conversion utilities
632
+ │ └── validation.ts # Input validation functions
633
+ ├── tests/
634
+ │ ├── unit/ # Unit tests (228 tests)
635
+ │ └── integration/ # Integration tests (19 tests)
636
+ ├── dist/ # Compiled JavaScript (generated)
637
+ ├── docs/ # Documentation
392
638
  └── package.json
393
639
  ```
394
640
 
395
641
  ## API Information
396
642
 
397
- This server uses two weather APIs:
643
+ This server uses three weather APIs:
398
644
 
399
- ### NOAA Weather API (Real-time)
645
+ ### NOAA Weather API (Real-time, US)
400
646
  - **Base URL**: https://api.weather.gov
401
647
  - **Authentication**: None required (User-Agent header only)
402
648
  - **Rate Limits**: Enforced with 5-second retry window
403
649
  - **Coverage**: United States locations only
404
- - **Use cases**: Forecasts, current conditions, recent observations (last 7 days)
650
+ - **Use cases**: US forecasts (detailed), current conditions, recent observations (last 7 days)
405
651
  - **Data**: Detailed hourly observations from weather stations
406
652
 
407
- ### Open-Meteo Historical Weather API (Archival)
653
+ ### Open-Meteo Forecast API (Global) - NEW in v0.4.0
654
+ - **Base URL**: https://api.open-meteo.com/v1
655
+ - **Authentication**: None required (no API token needed)
656
+ - **Rate Limits**: 10,000 requests/day for non-commercial use
657
+ - **Coverage**: Global (worldwide locations)
658
+ - **Use cases**: International forecasts, extended forecasts (up to 16 days)
659
+ - **Data**: Temperature, precipitation, wind, humidity, UV index, sunrise/sunset
660
+ - **Resolution**: 11km global grid resolution
661
+
662
+ ### Open-Meteo Geocoding API (Global) - NEW in v0.4.0
663
+ - **Base URL**: https://geocoding-api.open-meteo.com/v1
664
+ - **Authentication**: None required (no API token needed)
665
+ - **Coverage**: Global (worldwide locations)
666
+ - **Use cases**: Location name to coordinates conversion
667
+ - **Data**: Coordinates, timezone, elevation, population, administrative regions
668
+ - **Cache**: 30-day TTL (locations don't move)
669
+
670
+ ### Open-Meteo Historical Weather API (Global, Archival)
408
671
  - **Base URL**: https://archive-api.open-meteo.com/v1
409
672
  - **Authentication**: None required (no API token needed)
410
673
  - **Rate Limits**: 10,000 requests/day for non-commercial use
@@ -420,9 +683,15 @@ For more details on NOAA APIs, see [NOAA_API_RESEARCH.md](./docs/NOAA_API_RESEAR
420
683
 
421
684
  ### Geographic Coverage
422
685
 
423
- **Forecasts and Current Conditions:**
424
- - NOAA APIs only cover **United States locations**
425
- - International locations are not supported for forecasts and current conditions
686
+ **Forecasts:** (UPDATED in v0.4.0)
687
+ - **Global coverage** via automatic source selection
688
+ - US locations: Uses NOAA API (more detailed, includes narratives)
689
+ - International locations: Uses Open-Meteo API (reliable global forecasts)
690
+ - Extended forecasts (>7 days, up to 16 days): Open-Meteo only
691
+
692
+ **Current Conditions:**
693
+ - **US locations only** (NOAA API)
694
+ - International real-time conditions not yet supported
426
695
 
427
696
  **Historical Data:**
428
697
  - Recent data (last 7 days): **US locations only** (NOAA API)
@@ -455,6 +724,51 @@ For more details on NOAA APIs, see [NOAA_API_RESEARCH.md](./docs/NOAA_API_RESEAR
455
724
  - **For historical analysis**: Open-Meteo provides reliable global coverage back to 1940
456
725
  - **For international locations**: Only historical data (>7 days old) is supported
457
726
 
727
+ ## Security
728
+
729
+ This project takes security seriously and implements multiple layers of protection:
730
+
731
+ ### Security Features
732
+
733
+ **Input Validation:**
734
+ - Comprehensive runtime validation for all user inputs
735
+ - NaN and Infinity checks for numeric coordinates
736
+ - Range validation for latitude (-90 to 90) and longitude (-180 to 180)
737
+ - Type checking with TypeScript strict mode
738
+
739
+ **Error Handling:**
740
+ - Custom error class hierarchy with typed errors
741
+ - Error message sanitization to prevent information leakage
742
+ - Retryable errors clearly identified for graceful recovery
743
+ - Network errors sanitized before display
744
+
745
+ **Dependency Security:**
746
+ - Automated dependency scanning via `npm audit`
747
+ - GitHub Dependabot configured for weekly security updates
748
+ - Minimal dependency footprint (3 runtime dependencies)
749
+ - Zero known vulnerabilities in current dependencies
750
+
751
+ **Reliability:**
752
+ - Exponential backoff with jitter prevents thundering herd problems
753
+ - Comprehensive test suite (247 tests) with 100% coverage on critical utilities
754
+ - Memory-safe cache with automatic cleanup
755
+ - Graceful shutdown handling
756
+
757
+ ### Security Audit
758
+
759
+ The project has undergone a comprehensive security audit:
760
+ - **Overall Security Posture:** B+ (Good)
761
+ - **Risk Level:** LOW
762
+ - **Vulnerabilities:** Zero critical or high-severity issues
763
+ - See [SECURITY_AUDIT.md](./docs/development/SECURITY_AUDIT.md) for full audit report
764
+
765
+ ### Reporting Security Issues
766
+
767
+ To report a security vulnerability, please see our [Security Policy](./SECURITY.md) which includes:
768
+ - Vulnerability reporting procedures
769
+ - Response timeline commitments (48hr acknowledgment, 7-day assessment)
770
+ - Security best practices for users and developers
771
+
458
772
  ## License
459
773
 
460
774
  MIT
@@ -462,3 +776,8 @@ MIT
462
776
  ## Contributing
463
777
 
464
778
  Contributions are welcome! Please feel free to submit a Pull Request.
779
+
780
+ For information about code quality, security considerations, and development best practices, see:
781
+ - [CODE_REVIEW.md](./docs/development/CODE_REVIEW.md) - Comprehensive code quality analysis
782
+ - [CONTRIBUTING.md](./CONTRIBUTING.md) - Contribution guidelines
783
+ - [SECURITY.md](./SECURITY.md) - Security policy and vulnerability reporting
@@ -10,11 +10,13 @@
10
10
  export declare const CacheConfig: {
11
11
  readonly enabled: boolean;
12
12
  readonly maxSize: number;
13
+ readonly apiTimeoutMs: number;
13
14
  readonly ttl: {
14
15
  readonly gridCoordinates: number;
15
16
  readonly stations: number;
16
17
  readonly forecast: number;
17
18
  readonly currentConditions: number;
19
+ readonly alerts: number;
18
20
  readonly recentHistorical: number;
19
21
  readonly historicalData: number;
20
22
  readonly serviceStatus: number;
@@ -1 +1 @@
1
- {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/config/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAOH,eAAO,MAAM,WAAW;;;;;;;;;;;;CAqCd,CAAC;AAEX;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAYrE"}
1
+ {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/config/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAkDH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;CA8Cd,CAAC;AAEX;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAYrE"}
@@ -11,11 +11,54 @@
11
11
  const MINUTE = 60 * 1000;
12
12
  const HOUR = 60 * MINUTE;
13
13
  const DAY = 24 * HOUR;
14
+ /**
15
+ * Parse a boolean environment variable
16
+ * @param key Environment variable key
17
+ * @param defaultValue Default value if not set
18
+ * @returns Boolean value
19
+ */
20
+ function getEnvBoolean(key, defaultValue) {
21
+ const value = process.env[key];
22
+ if (value === undefined)
23
+ return defaultValue;
24
+ return value !== 'false' && value !== '0';
25
+ }
26
+ /**
27
+ * Parse a number environment variable with validation
28
+ * @param key Environment variable key
29
+ * @param defaultValue Default value if not set or invalid
30
+ * @param min Minimum allowed value (optional)
31
+ * @param max Maximum allowed value (optional)
32
+ * @returns Validated number value
33
+ */
34
+ function getEnvNumber(key, defaultValue, min, max) {
35
+ const value = process.env[key];
36
+ if (value === undefined)
37
+ return defaultValue;
38
+ const parsed = parseInt(value, 10);
39
+ if (isNaN(parsed)) {
40
+ console.warn(`Invalid ${key}: "${value}". Using default: ${defaultValue}`);
41
+ return defaultValue;
42
+ }
43
+ if (min !== undefined && parsed < min) {
44
+ console.warn(`${key} too low: ${parsed}. Using minimum: ${min}`);
45
+ return min;
46
+ }
47
+ if (max !== undefined && parsed > max) {
48
+ console.warn(`${key} too high: ${parsed}. Using maximum: ${max}`);
49
+ return max;
50
+ }
51
+ return parsed;
52
+ }
14
53
  export const CacheConfig = {
15
54
  // Enable/disable caching globally
16
- enabled: process.env.CACHE_ENABLED !== 'false', // Default: enabled
55
+ enabled: getEnvBoolean('CACHE_ENABLED', true),
17
56
  // Maximum number of entries in cache before LRU eviction
18
- maxSize: parseInt(process.env.CACHE_MAX_SIZE || '1000', 10),
57
+ // Min: 100, Max: 10000, Default: 1000
58
+ maxSize: getEnvNumber('CACHE_MAX_SIZE', 1000, 100, 10000),
59
+ // API timeout configuration
60
+ // Min: 5000ms (5 seconds), Max: 120000ms (2 minutes), Default: 30000ms (30 seconds)
61
+ apiTimeoutMs: getEnvNumber('API_TIMEOUT_MS', 30000, 5000, 120000),
19
62
  // TTL values for different data types
20
63
  ttl: {
21
64
  // Grid coordinate lookups (lat/lon -> grid mapping)
@@ -30,6 +73,9 @@ export const CacheConfig = {
30
73
  // Current weather conditions
31
74
  // Observations typically update every 20-60 minutes
32
75
  currentConditions: 15 * MINUTE,
76
+ // Weather alerts
77
+ // Alerts can change rapidly, cache for shorter period
78
+ alerts: 5 * MINUTE,
33
79
  // Recent historical data (< 7 days old)
34
80
  // Recent data may still be updated/corrected
35
81
  recentHistorical: 1 * HOUR,
@@ -1 +1 @@
1
- {"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/config/cache.ts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