@driftwest/mcp-server 1.3.0 → 1.4.1

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.
package/index.js CHANGED
@@ -23,10 +23,43 @@
23
23
  const { McpServer } = require('@modelcontextprotocol/sdk/server/mcp.js');
24
24
  const { StdioServerTransport } = require('@modelcontextprotocol/sdk/server/stdio.js');
25
25
  const { z } = require('zod');
26
+ const fs = require('fs');
27
+ const path = require('path');
26
28
 
27
29
  const BASE_URL = process.env.DRIFTWEST_BASE_URL || 'https://driftwest.xyz';
28
30
  const API_KEY = process.env.DRIFTWEST_API_KEY || '';
29
31
 
32
+ // ── Tier Gating ──
33
+
34
+ const tierConfig = JSON.parse(fs.readFileSync(path.join(__dirname, 'tier-config.json'), 'utf8'));
35
+ let apiKeys = { keys: {} };
36
+ try { apiKeys = JSON.parse(fs.readFileSync(path.join(__dirname, 'api-keys.json'), 'utf8')); } catch { /* not shipped in npm package: everyone is free tier */ }
37
+ const FREE_TOOLS = new Set(tierConfig.tiers.free.tools);
38
+ const GATE_MESSAGE = tierConfig.gate_message;
39
+
40
+ function getUserTier() {
41
+ if (!API_KEY) return 'free';
42
+ const keyEntry = apiKeys.keys[API_KEY];
43
+ if (!keyEntry || !keyEntry.active) return 'free';
44
+ return keyEntry.tier || 'free';
45
+ }
46
+
47
+ function gateHandler(toolName, handler) {
48
+ if (FREE_TOOLS.has(toolName)) return handler; // free tools pass through
49
+ return async (...args) => {
50
+ const tier = getUserTier();
51
+ if (tier === 'pro') return handler(...args);
52
+ // Append upgrade hint to tool description context
53
+ const freeList = tierConfig.tiers.free.tools.join(', ');
54
+ return {
55
+ content: [{
56
+ type: 'text',
57
+ text: `🔒 Pro Tool: ${toolName}\n\n${GATE_MESSAGE}\n\nFree-tier tools available now: ${freeList}`
58
+ }]
59
+ };
60
+ };
61
+ }
62
+
30
63
  async function apiCall(path, options = {}) {
31
64
  const url = `${BASE_URL}${path}`;
32
65
  const headers = { 'Content-Type': 'application/json' };
@@ -46,6 +79,21 @@ const server = new McpServer({
46
79
  description: 'DriftWest Environmental Data — EMF sensors, space weather, coastal environment, wildfire monitoring, air quality, and seismic activity'
47
80
  });
48
81
 
82
+ // Wrap server.tool to auto-apply tier gating on all tool handlers
83
+ const _originalTool = server.tool.bind(server);
84
+ server.tool = function(name, ...rest) {
85
+ // Last arg is always the handler function
86
+ const handler = rest[rest.length - 1];
87
+ rest[rest.length - 1] = gateHandler(name, handler);
88
+
89
+ // Append tier badge to description (second arg is always description string)
90
+ if (!FREE_TOOLS.has(name) && typeof rest[0] === 'string') {
91
+ rest[0] = `[PRO] ${rest[0]}`;
92
+ }
93
+
94
+ return _originalTool(name, ...rest);
95
+ };
96
+
49
97
  // ── EMF Sensor Tools ──
50
98
 
51
99
  server.tool(
@@ -609,6 +657,54 @@ server.tool(
609
657
  }
610
658
  );
611
659
 
660
+ // ── Prairie Storm-Day Index (Alberta, GOES GLM 2018+) ──
661
+ // Gated server-side by its own key (sdi_*), so these pass the local tier gate.
662
+ const STORM_KEY = process.env.DRIFTWEST_STORM_KEY || '';
663
+ async function stormCall(endpoint, params) {
664
+ const qs = new URLSearchParams(Object.entries(params).filter(([, v]) => v !== undefined && v !== null).map(([k, v]) => [k, String(v)]));
665
+ const headers = STORM_KEY ? { 'X-API-Key': STORM_KEY } : {};
666
+ const res = await fetch(`${BASE_URL}/api/storm-days/${endpoint}?${qs}`, { headers });
667
+ const body = await res.text();
668
+ if (!res.ok) {
669
+ let msg = body; try { msg = JSON.parse(body).error; } catch {}
670
+ return { content: [{ type: 'text', text: `Storm-Day Index ${res.status}: ${msg}${res.status === 402 ? '\nSet DRIFTWEST_STORM_KEY to a Pro key: https://driftwest.xyz/storm-days.html' : ''}` }], isError: res.status >= 500 };
671
+ }
672
+ return { content: [{ type: 'text', text: body }] };
673
+ }
674
+
675
+ server.tool(
676
+ 'storm_days_point',
677
+ 'Prairie Storm-Day Index: thunderstorm (lightning) days per summer at any Alberta lat/lon, 2018–present, from GOES GLM satellite data. Returns storm days and strong-storm days per year, the multi-year normal, each year vs normal and its rank, and this season-to-date vs normal-to-date. Season = May 15–Sep 15. Use for convective/lightning exposure of a farm, site, line corridor or property. Measures lightning activity, NOT hail. Free without a key (20 lookups/day).',
678
+ {
679
+ lat: z.number().describe('Latitude, 48.9 to 56.6'),
680
+ lon: z.number().describe('Longitude, -120.1 to -109.9'),
681
+ radius_km: z.number().min(0).max(25).optional().describe('Count a storm day if lightning fell within this many km (0 = the ~5 km grid cell itself, default)')
682
+ },
683
+ async ({ lat, lon, radius_km }) => stormCall('point', { lat, lon, radius_km })
684
+ );
685
+
686
+ server.tool(
687
+ 'storm_days_season',
688
+ 'Prairie Storm-Day Index: list every storm (lightning) day for one Alberta lat/lon in a given summer, with flash counts and data coverage per day. Needs a Pro key (DRIFTWEST_STORM_KEY).',
689
+ {
690
+ lat: z.number().describe('Latitude'),
691
+ lon: z.number().describe('Longitude'),
692
+ year: z.number().int().min(2018).optional().describe('Summer year (default latest)'),
693
+ radius_km: z.number().min(0).max(25).optional().describe('Radius in km (default 0 = grid cell)')
694
+ },
695
+ async ({ lat, lon, year, radius_km }) => stormCall('season', { lat, lon, year, radius_km })
696
+ );
697
+
698
+ server.tool(
699
+ 'storm_days_grid',
700
+ 'Prairie Storm-Day Index: storm days for every 0.05° cell in a bounding box, for one year (with vs-normal) or the long-term normal. Good for mapping or ranking areas. Needs a Pro key (DRIFTWEST_STORM_KEY); Pro allows up to 2,500 cells per call.',
701
+ {
702
+ bbox: z.string().describe('lat0,lon0,lat1,lon1 e.g. "51,-114,52,-113"'),
703
+ year: z.union([z.number().int(), z.literal('normal')]).optional().describe('Year, or "normal" (default)')
704
+ },
705
+ async ({ bbox, year }) => stormCall('grid', { bbox, year })
706
+ );
707
+
612
708
  // ── Resources ──
613
709
 
614
710
  server.resource(
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@driftwest/mcp-server",
3
- "version": "1.3.0",
4
- "description": "MCP server for DriftWest environmental data — 40 tools including EMF MYSTERY GAME: a collaborative science game where AI agents investigate unexplained sensor anomalies, submit hypotheses, and compete on a leaderboard. Also: space weather, 355 beaches, wildfire, air quality, seismic. Free tier available.",
3
+ "version": "1.4.1",
4
+ "description": "MCP server for DriftWest environmental data \u2014 43 tools including EMF MYSTERY GAME: a collaborative science game where AI agents investigate unexplained sensor anomalies, submit hypotheses, and compete on a leaderboard. Also: Prairie Storm-Day Index (Alberta lightning days 2018+), space weather, 355 beaches, wildfire, air quality, seismic. Free tier available.",
5
5
  "main": "index.js",
6
6
  "bin": {
7
7
  "driftwest-mcp": "./index.js"
@@ -28,7 +28,12 @@
28
28
  "puzzle",
29
29
  "investigation",
30
30
  "citizen-science",
31
- "electromagnetic"
31
+ "electromagnetic",
32
+ "lightning",
33
+ "thunderstorm",
34
+ "alberta",
35
+ "climate-risk",
36
+ "insurance"
32
37
  ],
33
38
  "author": "DriftWest Labs <info@driftwest.xyz>",
34
39
  "license": "MIT",
package/server.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "$schema": "https://registry.modelcontextprotocol.io/schema/server.json",
3
3
  "name": "driftwest/mcp-server",
4
- "description": "Environmental data MCP server — 28 tools: EMF sensors, space weather, 355 beaches, wildfire monitoring, air quality, and seismic activity across Western Canada and Pacific Northwest.",
5
- "version": "1.1.1",
4
+ "description": "Environmental data MCP server \u2014 43 tools: EMF sensors, Alberta storm-day (lightning) index, space weather, 355 beaches, wildfire monitoring, air quality, seismic activity across Western Canada and Pacific Northwest, plus EMF Mystery Game for AI agents.",
5
+ "version": "1.4.1",
6
6
  "repository": {
7
7
  "url": "https://github.com/driftwest/mcp-server",
8
8
  "source": "https://github.com/driftwest/mcp-server"
@@ -11,7 +11,7 @@
11
11
  {
12
12
  "registryType": "npm",
13
13
  "name": "@driftwest/mcp-server",
14
- "version": "1.1.1",
14
+ "version": "1.4.1",
15
15
  "runtime": "node",
16
16
  "runtimeArgs": [],
17
17
  "environmentVariables": [
@@ -19,38 +19,187 @@
19
19
  "name": "DRIFTWEST_API_KEY",
20
20
  "description": "API key for DriftWest environmental data (register free at https://driftwest.xyz/api/account/register)",
21
21
  "required": false
22
+ },
23
+ {
24
+ "name": "DRIFTWEST_STORM_KEY",
25
+ "description": "Prairie Storm-Day Index Pro key (sdi_pro_...) for season/grid tools. Point lookups work without it.",
26
+ "required": false
22
27
  }
23
28
  ]
24
29
  }
25
30
  ],
26
31
  "tools": [
27
- { "name": "emf_latest", "description": "Latest EMF reading from any sensor node" },
28
- { "name": "emf_stats", "description": "24-hour statistics for all EMF sensor nodes" },
29
- { "name": "emf_history", "description": "Historical EMF time-series data" },
30
- { "name": "sensor_nodes", "description": "List all sensor nodes with online/offline status" },
31
- { "name": "space_weather", "description": "Current Kp/Dst index, solar wind speed, disturbance score" },
32
- { "name": "space_weather_alerts", "description": "Active NOAA space weather alerts" },
33
- { "name": "search_beaches", "description": "Geographic beach search across 355 beaches" },
34
- { "name": "beach_detail", "description": "Complete beach dossier with all environmental indices" },
35
- { "name": "water_quality_rankings", "description": "Beaches ranked by Water Quality Index" },
36
- { "name": "biodiversity_hotspots", "description": "Beaches ranked by biodiversity score" },
37
- { "name": "nearby_beaches", "description": "Find nearby beaches by location" },
38
- { "name": "shoreline_risk_alerts", "description": "Beaches by environmental risk level" },
39
- { "name": "compare_beaches", "description": "Side-by-side comparison of up to 10 beaches" },
40
- { "name": "water_quality_summary", "description": "Provincial water quality statistics" },
41
- { "name": "algae_risk", "description": "Algae bloom risk analysis" },
42
- { "name": "wildfire_current", "description": "Active fires, danger level, city proximity scores" },
43
- { "name": "wildfire_hotspots", "description": "Fire hotspot locations from NASA FIRMS satellite" },
44
- { "name": "wildfire_smoke_impact", "description": "Per-city smoke impact with AQI and PM2.5" },
45
- { "name": "air_quality_current", "description": "All 12 cities with AQI and health risk scores" },
46
- { "name": "air_quality_city", "description": "Detailed pollutant breakdown for one city" },
47
- { "name": "air_quality_rankings", "description": "Cities ranked by health risk score" },
48
- { "name": "air_quality_alerts", "description": "Cities exceeding AQI 100" },
49
- { "name": "seismic_recent", "description": "Recent global earthquakes (M2.5+) from USGS" },
50
- { "name": "seismic_canada", "description": "Canadian earthquakes only (M1.0+)" },
51
- { "name": "seismic_activity_score", "description": "Risk zone scores for 5 Canadian zones" },
52
- { "name": "seismic_nearby", "description": "Earthquakes near a geographic point" },
53
- { "name": "alberta_environment", "description": "Combined EMF + water quality + space weather dashboard" },
54
- { "name": "safety_check", "description": "Composite go/no-go verdict for air quality, wildfire, seismic" }
32
+ {
33
+ "name": "emf_latest",
34
+ "description": "Latest EMF reading from any sensor node"
35
+ },
36
+ {
37
+ "name": "emf_stats",
38
+ "description": "24-hour statistics for all EMF sensor nodes"
39
+ },
40
+ {
41
+ "name": "emf_history",
42
+ "description": "Historical EMF time-series data"
43
+ },
44
+ {
45
+ "name": "sensor_nodes",
46
+ "description": "List all sensor nodes with online/offline status"
47
+ },
48
+ {
49
+ "name": "space_weather",
50
+ "description": "Current Kp/Dst index, solar wind speed, disturbance score"
51
+ },
52
+ {
53
+ "name": "space_weather_alerts",
54
+ "description": "Active NOAA space weather alerts"
55
+ },
56
+ {
57
+ "name": "search_beaches",
58
+ "description": "Geographic beach search across 355 beaches"
59
+ },
60
+ {
61
+ "name": "beach_detail",
62
+ "description": "Complete beach dossier with all environmental indices"
63
+ },
64
+ {
65
+ "name": "water_quality_rankings",
66
+ "description": "Beaches ranked by Water Quality Index"
67
+ },
68
+ {
69
+ "name": "biodiversity_hotspots",
70
+ "description": "Beaches ranked by biodiversity score"
71
+ },
72
+ {
73
+ "name": "nearby_beaches",
74
+ "description": "Find nearby beaches by location"
75
+ },
76
+ {
77
+ "name": "shoreline_risk_alerts",
78
+ "description": "Beaches by environmental risk level"
79
+ },
80
+ {
81
+ "name": "compare_beaches",
82
+ "description": "Side-by-side comparison of up to 10 beaches"
83
+ },
84
+ {
85
+ "name": "water_quality_summary",
86
+ "description": "Provincial water quality statistics"
87
+ },
88
+ {
89
+ "name": "algae_risk",
90
+ "description": "Algae bloom risk analysis"
91
+ },
92
+ {
93
+ "name": "wildfire_current",
94
+ "description": "Active fires, danger level, city proximity scores"
95
+ },
96
+ {
97
+ "name": "wildfire_hotspots",
98
+ "description": "Fire hotspot locations from NASA FIRMS satellite"
99
+ },
100
+ {
101
+ "name": "wildfire_smoke_impact",
102
+ "description": "Per-city smoke impact with AQI and PM2.5"
103
+ },
104
+ {
105
+ "name": "air_quality_current",
106
+ "description": "All 12 cities with AQI and health risk scores"
107
+ },
108
+ {
109
+ "name": "air_quality_city",
110
+ "description": "Detailed pollutant breakdown for one city"
111
+ },
112
+ {
113
+ "name": "air_quality_rankings",
114
+ "description": "Cities ranked by health risk score"
115
+ },
116
+ {
117
+ "name": "air_quality_alerts",
118
+ "description": "Cities exceeding AQI 100"
119
+ },
120
+ {
121
+ "name": "seismic_recent",
122
+ "description": "Recent global earthquakes (M2.5+) from USGS"
123
+ },
124
+ {
125
+ "name": "seismic_canada",
126
+ "description": "Canadian earthquakes only (M1.0+)"
127
+ },
128
+ {
129
+ "name": "seismic_activity_score",
130
+ "description": "Risk zone scores for 5 Canadian zones"
131
+ },
132
+ {
133
+ "name": "seismic_nearby",
134
+ "description": "Earthquakes near a geographic point"
135
+ },
136
+ {
137
+ "name": "alberta_environment",
138
+ "description": "Combined EMF + water quality + space weather dashboard"
139
+ },
140
+ {
141
+ "name": "safety_check",
142
+ "description": "Composite go/no-go verdict for air quality, wildfire, seismic"
143
+ },
144
+ {
145
+ "name": "emf_mystery",
146
+ "description": "THE EMF MYSTERY \u2014 open challenge for AI agents to explain unexplained EMF fluctuations from plant/air sensors in Strathmore, Alberta"
147
+ },
148
+ {
149
+ "name": "emf_anomalies",
150
+ "description": "Z-score anomaly detection results across all EMF sensor nodes"
151
+ },
152
+ {
153
+ "name": "emf_correlations",
154
+ "description": "Correlation analysis: EMF vs weather, lunar phase, seismic, space weather"
155
+ },
156
+ {
157
+ "name": "emf_analysis_report",
158
+ "description": "Latest daily EMF analysis report with statistics, anomalies, and auto-generated hypotheses"
159
+ },
160
+ {
161
+ "name": "emf_events",
162
+ "description": "Logged events, annotations, and settings changes for ruling out human-caused anomalies"
163
+ },
164
+ {
165
+ "name": "mystery_game_status",
166
+ "description": "EMF Mystery Game status \u2014 active cases, leaderboard, and how to play"
167
+ },
168
+ {
169
+ "name": "mystery_cases",
170
+ "description": "List active mystery cases (real EMF anomalies needing explanation)"
171
+ },
172
+ {
173
+ "name": "mystery_case_detail",
174
+ "description": "Full details on a mystery case including submitted hypotheses"
175
+ },
176
+ {
177
+ "name": "mystery_register",
178
+ "description": "Register as an investigator in the EMF Mystery Game, get an investigator token"
179
+ },
180
+ {
181
+ "name": "mystery_investigate",
182
+ "description": "Log an investigation step for a mystery case, earn 2 points per action"
183
+ },
184
+ {
185
+ "name": "mystery_hypothesize",
186
+ "description": "Submit a hypothesis for a mystery case with confidence level (low=10pts, medium=30pts, high=50pts)"
187
+ },
188
+ {
189
+ "name": "mystery_leaderboard",
190
+ "description": "EMF Mystery Game leaderboard \u2014 top investigators ranked by score"
191
+ },
192
+ {
193
+ "name": "storm_days_point",
194
+ "description": "Alberta storm (lightning) days per summer at a lat/lon, 2018+, vs normal"
195
+ },
196
+ {
197
+ "name": "storm_days_season",
198
+ "description": "Every storm day at a lat/lon in one summer"
199
+ },
200
+ {
201
+ "name": "storm_days_grid",
202
+ "description": "Storm days per 0.05\u00b0 cell in a bounding box"
203
+ }
55
204
  ]
56
205
  }
@@ -0,0 +1,29 @@
1
+ {
2
+ "tiers": {
3
+ "free": {
4
+ "description": "Free tier \u2014 11 core tools for environmental monitoring and EMF mystery",
5
+ "tools": [
6
+ "emf_latest",
7
+ "emf_stats",
8
+ "sensor_nodes",
9
+ "space_weather",
10
+ "search_beaches",
11
+ "air_quality_current",
12
+ "wildfire_current",
13
+ "seismic_recent",
14
+ "safety_check",
15
+ "emf_mystery",
16
+ "mystery_game_status",
17
+ "storm_days_point",
18
+ "storm_days_season",
19
+ "storm_days_grid"
20
+ ]
21
+ },
22
+ "pro": {
23
+ "description": "DriftWest Pro ($19/mo) \u2014 All 40 tools including deep analysis, comparisons, and full mystery game",
24
+ "price": "$19/month",
25
+ "upgrade_url": "https://driftwest.xyz/mcp-pro.html"
26
+ }
27
+ },
28
+ "gate_message": "This tool requires DriftWest Pro ($19/mo). You're on the free tier which includes 11 core tools. Upgrade at https://driftwest.xyz/mcp-pro.html to unlock all 40 tools including deep analysis, beach comparisons, biodiversity data, and the full EMF Mystery Game."
29
+ }