@pipeworx/mcp-airnow 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pipeworx
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # mcp-airnow
2
+
3
+ EPA AirNow MCP — official US real-time AQI + forecast (free key)
4
+
5
+ Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 250+ live data sources.
6
+
7
+ ## Tools
8
+
9
+ | Tool | Description |
10
+ |------|-------------|
11
+ | `current_by_location` | Latest observed AQI for the AirNow station nearest a lat/lon. |
12
+
13
+ ## Quick Start
14
+
15
+ Add to your MCP client (Claude Desktop, Cursor, Windsurf, etc.):
16
+
17
+ ```json
18
+ {
19
+ "mcpServers": {
20
+ "airnow": {
21
+ "url": "https://gateway.pipeworx.io/airnow/mcp"
22
+ }
23
+ }
24
+ }
25
+ ```
26
+
27
+ Or connect to the full Pipeworx gateway for access to all 250+ data sources:
28
+
29
+ ```json
30
+ {
31
+ "mcpServers": {
32
+ "pipeworx": {
33
+ "url": "https://gateway.pipeworx.io/mcp"
34
+ }
35
+ }
36
+ }
37
+ ```
38
+
39
+ ## Using with ask_pipeworx
40
+
41
+ Instead of calling tools directly, you can ask questions in plain English:
42
+
43
+ ```
44
+ ask_pipeworx({ question: "your question about Airnow data" })
45
+ ```
46
+
47
+ The gateway picks the right tool and fills the arguments automatically.
48
+
49
+ ## More
50
+
51
+ - [All tools and guides](https://github.com/pipeworx-io/examples)
52
+ - [pipeworx.io](https://pipeworx.io)
53
+
54
+ ## License
55
+
56
+ MIT
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@pipeworx/mcp-airnow",
3
+ "version": "0.1.0",
4
+ "description": "EPA AirNow MCP — official US real-time AQI + forecast (free key)",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "types": "src/index.ts",
8
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "airnow"],
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/pipeworx-io/mcp-airnow"
13
+ },
14
+ "scripts": {
15
+ "typecheck": "tsc --noEmit"
16
+ },
17
+ "devDependencies": {
18
+ "typescript": "^5.7.0"
19
+ }
20
+ }
package/server.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
3
+ "name": "io.github.pipeworx-io/airnow",
4
+ "title": "Airnow",
5
+ "description": "EPA AirNow MCP — official US real-time AQI + forecast (free key)",
6
+ "version": "0.1.0",
7
+ "websiteUrl": "https://pipeworx.io/packs/airnow",
8
+ "repository": {
9
+ "url": "https://github.com/pipeworx-io/mcp-airnow",
10
+ "source": "github"
11
+ },
12
+ "remotes": [
13
+ {
14
+ "type": "streamable-http",
15
+ "url": "https://gateway.pipeworx.io/airnow/mcp"
16
+ }
17
+ ]
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,286 @@
1
+ interface McpToolDefinition {
2
+ name: string;
3
+ description: string;
4
+ inputSchema: {
5
+ type: 'object';
6
+ properties: Record<string, unknown>;
7
+ required?: string[];
8
+ };
9
+ }
10
+
11
+ interface McpToolExport {
12
+ tools: McpToolDefinition[];
13
+ callTool: (name: string, args: Record<string, unknown>) => Promise<unknown>;
14
+ meter?: { credits: number };
15
+ cost?: Record<string, unknown>;
16
+ provider?: string;
17
+ }
18
+
19
+ /**
20
+ * EPA AirNow MCP — official US real-time AQI + forecast (free key)
21
+ *
22
+ * AirNow is the EPA's authoritative source for current and forecasted air
23
+ * quality at >2,000 US monitoring sites. Complements `airquality` (Open-Meteo
24
+ * gridded forecast), `openaq` (open dataset), and `waqi` (global private
25
+ * stations) with the EPA-official US layer.
26
+ *
27
+ * API: https://docs.airnowapi.org
28
+ * Auth: ?API_KEY= query param. Free tier 500 req/hour.
29
+ *
30
+ * Tools:
31
+ * - current_by_zip: latest AQI for a US ZIP code
32
+ * - current_by_location: latest AQI nearest a lat/lon
33
+ * - forecast_by_zip: AQI forecast for a US ZIP code on a given date
34
+ * - observations_in_bbox: historical observations inside a bounding box
35
+ */
36
+
37
+
38
+ const BASE_URL = 'https://www.airnowapi.org/aq';
39
+
40
+ const tools: McpToolExport['tools'] = [
41
+ {
42
+ name: 'current_by_zip',
43
+ description:
44
+ 'Latest observed AQI for a US ZIP code. Returns one record per pollutant reported at the nearest site (typically O3 + PM2.5). Includes AQI value, category (Good / Moderate / etc.), reporting area, and timestamp.',
45
+ inputSchema: {
46
+ type: 'object',
47
+ properties: {
48
+ zip_code: { type: 'string', description: 'US 5-digit ZIP code' },
49
+ distance_miles: { type: 'number', description: 'Search radius (default 25, max 250)' },
50
+ },
51
+ required: ['zip_code'],
52
+ },
53
+ },
54
+ {
55
+ name: 'current_by_location',
56
+ description: 'Latest observed AQI for the AirNow station nearest a lat/lon.',
57
+ inputSchema: {
58
+ type: 'object',
59
+ properties: {
60
+ latitude: { type: 'number', description: 'US latitude' },
61
+ longitude: { type: 'number', description: 'US longitude' },
62
+ distance_miles: { type: 'number', description: 'Search radius (default 25, max 250)' },
63
+ },
64
+ required: ['latitude', 'longitude'],
65
+ },
66
+ },
67
+ {
68
+ name: 'forecast_by_zip',
69
+ description:
70
+ 'AQI forecast for a US ZIP code on a given date (defaults to today). Useful for "is tomorrow ok for outdoor activity" decisions.',
71
+ inputSchema: {
72
+ type: 'object',
73
+ properties: {
74
+ zip_code: { type: 'string', description: 'US 5-digit ZIP code' },
75
+ date: { type: 'string', description: 'YYYY-MM-DD (default today)' },
76
+ distance_miles: { type: 'number', description: 'Search radius (default 25)' },
77
+ },
78
+ required: ['zip_code'],
79
+ },
80
+ },
81
+ {
82
+ name: 'observations_in_bbox',
83
+ description:
84
+ 'Historical AQI observations inside a bounding box for a date range. Specify pollutants as comma-separated parameter codes (e.g., "OZONE,PM25,PM10,CO,NO2,SO2"). bbox format: "minLon,minLat,maxLon,maxLat".',
85
+ inputSchema: {
86
+ type: 'object',
87
+ properties: {
88
+ bbox: { type: 'string', description: 'minLon,minLat,maxLon,maxLat' },
89
+ start_date: { type: 'string', description: 'YYYY-MM-DDT00 (hour-granular ISO truncated)' },
90
+ end_date: { type: 'string', description: 'YYYY-MM-DDT23' },
91
+ parameters: { type: 'string', description: 'Comma-separated pollutants (default: OZONE,PM25,PM10)' },
92
+ data_type: { type: 'string', description: 'A (AQI) | C (concentration) | B (both, default)' },
93
+ verbose: { type: 'boolean', description: 'Include site / county / agency / full-AQS-code fields' },
94
+ },
95
+ required: ['bbox', 'start_date', 'end_date'],
96
+ },
97
+ },
98
+ ];
99
+
100
+ async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
101
+ const apiKey = (args._apiKey as string | undefined)?.trim();
102
+ if (!apiKey) {
103
+ throw new Error(
104
+ 'EPA AirNow requires an API key (free 500 req/hour). Contact the operator about platform credentials, or BYO via ?_apiKey=<key> after registering at https://docs.airnowapi.org/account/request/.',
105
+ );
106
+ }
107
+ switch (name) {
108
+ case 'current_by_zip':
109
+ return currentByZip(apiKey, args);
110
+ case 'current_by_location':
111
+ return currentByLocation(apiKey, args);
112
+ case 'forecast_by_zip':
113
+ return forecastByZip(apiKey, args);
114
+ case 'observations_in_bbox':
115
+ return observationsInBbox(apiKey, args);
116
+ default:
117
+ throw new Error(`Unknown tool: ${name}`);
118
+ }
119
+ }
120
+
121
+ function reqStr(args: Record<string, unknown>, key: string, example: string): string {
122
+ const v = args[key];
123
+ if (typeof v !== 'string' || !v.trim()) {
124
+ throw new Error(`Required argument "${key}" is missing or empty. Pass a string like ${example}.`);
125
+ }
126
+ return v;
127
+ }
128
+
129
+ async function airnowFetch<T>(path: string, params: URLSearchParams): Promise<T> {
130
+ const url = `${BASE_URL}${path}?${params}`;
131
+ const res = await fetch(url, { headers: { Accept: 'application/json' } });
132
+ if (res.status === 401 || res.status === 403) throw new Error('AirNow: unauthorized — check the API key');
133
+ if (res.status === 429) throw new Error('AirNow: rate-limit (HTTP 429) — free tier is 500/hour');
134
+ if (!res.ok) {
135
+ const body = await res.text();
136
+ throw new Error(`AirNow error: ${res.status} ${body.slice(0, 200)}`);
137
+ }
138
+ return res.json() as Promise<T>;
139
+ }
140
+
141
+ interface ObservationRow {
142
+ DateObserved?: string;
143
+ HourObserved?: number;
144
+ LocalTimeZone?: string;
145
+ ReportingArea?: string;
146
+ StateCode?: string;
147
+ Latitude?: number;
148
+ Longitude?: number;
149
+ ParameterName?: string;
150
+ AQI?: number;
151
+ Category?: { Number?: number; Name?: string };
152
+ }
153
+
154
+ interface ForecastRow extends ObservationRow {
155
+ DateForecast?: string;
156
+ ActionDay?: boolean;
157
+ Discussion?: string;
158
+ }
159
+
160
+ function normalizeObservation(o: ObservationRow) {
161
+ return {
162
+ date: o.DateObserved?.trim() ?? null,
163
+ hour: o.HourObserved ?? null,
164
+ timezone: o.LocalTimeZone ?? null,
165
+ reporting_area: o.ReportingArea ?? null,
166
+ state: o.StateCode ?? null,
167
+ latitude: o.Latitude ?? null,
168
+ longitude: o.Longitude ?? null,
169
+ pollutant: o.ParameterName ?? null,
170
+ aqi: o.AQI ?? null,
171
+ category: o.Category?.Name ?? null,
172
+ category_number: o.Category?.Number ?? null,
173
+ };
174
+ }
175
+
176
+ async function currentByZip(apiKey: string, args: Record<string, unknown>) {
177
+ const zip = reqStr(args, 'zip_code', '"94103"');
178
+ const params = new URLSearchParams({
179
+ format: 'application/json',
180
+ zipCode: zip,
181
+ distance: String(Math.min(250, Math.max(0, (args.distance_miles as number) ?? 25))),
182
+ API_KEY: apiKey,
183
+ });
184
+ const data = await airnowFetch<ObservationRow[]>('/observation/zipCode/current/', params);
185
+ return { zip_code: zip, count: data.length, observations: data.map(normalizeObservation) };
186
+ }
187
+
188
+ async function currentByLocation(apiKey: string, args: Record<string, unknown>) {
189
+ const params = new URLSearchParams({
190
+ format: 'application/json',
191
+ latitude: String(args.latitude),
192
+ longitude: String(args.longitude),
193
+ distance: String(Math.min(250, Math.max(0, (args.distance_miles as number) ?? 25))),
194
+ API_KEY: apiKey,
195
+ });
196
+ const data = await airnowFetch<ObservationRow[]>('/observation/latLong/current/', params);
197
+ return {
198
+ latitude: args.latitude,
199
+ longitude: args.longitude,
200
+ count: data.length,
201
+ observations: data.map(normalizeObservation),
202
+ };
203
+ }
204
+
205
+ async function forecastByZip(apiKey: string, args: Record<string, unknown>) {
206
+ const zip = reqStr(args, 'zip_code', '"94103"');
207
+ const params = new URLSearchParams({
208
+ format: 'application/json',
209
+ zipCode: zip,
210
+ distance: String(Math.min(250, Math.max(0, (args.distance_miles as number) ?? 25))),
211
+ API_KEY: apiKey,
212
+ });
213
+ if (args.date) params.set('date', String(args.date));
214
+
215
+ const data = await airnowFetch<ForecastRow[]>('/forecast/zipCode/', params);
216
+ return {
217
+ zip_code: zip,
218
+ requested_date: args.date ?? 'today',
219
+ count: data.length,
220
+ forecast: data.map((f) => ({
221
+ forecast_date: f.DateForecast?.trim() ?? null,
222
+ reporting_area: f.ReportingArea ?? null,
223
+ state: f.StateCode ?? null,
224
+ latitude: f.Latitude ?? null,
225
+ longitude: f.Longitude ?? null,
226
+ pollutant: f.ParameterName ?? null,
227
+ aqi: f.AQI ?? null,
228
+ category: f.Category?.Name ?? null,
229
+ action_day: f.ActionDay ?? false,
230
+ discussion: f.Discussion ?? null,
231
+ })),
232
+ };
233
+ }
234
+
235
+ interface BboxObservation {
236
+ DateObserved?: string;
237
+ HourObserved?: number;
238
+ UTC?: string;
239
+ Parameter?: string;
240
+ AQI?: number;
241
+ Category?: number;
242
+ SiteName?: string;
243
+ AgencyName?: string;
244
+ FullAQSCode?: string;
245
+ IntlAQSCode?: string;
246
+ Latitude?: number;
247
+ Longitude?: number;
248
+ Value?: number;
249
+ Unit?: string;
250
+ }
251
+
252
+ async function observationsInBbox(apiKey: string, args: Record<string, unknown>) {
253
+ const params = new URLSearchParams({
254
+ BBOX: reqStr(args, 'bbox', '"-123.0,37.0,-121.0,38.5"'),
255
+ startDate: reqStr(args, 'start_date', '"2026-05-01T00"'),
256
+ endDate: reqStr(args, 'end_date', '"2026-05-01T23"'),
257
+ parameters: (args.parameters as string) ?? 'OZONE,PM25,PM10',
258
+ dataType: (args.data_type as string) ?? 'B',
259
+ format: 'application/json',
260
+ verbose: args.verbose ? '1' : '0',
261
+ API_KEY: apiKey,
262
+ });
263
+
264
+ const data = await airnowFetch<BboxObservation[]>('/data/', params);
265
+ return {
266
+ bbox: args.bbox,
267
+ count: data.length,
268
+ observations: data.map((o) => ({
269
+ observed_date: o.DateObserved?.trim() ?? null,
270
+ hour: o.HourObserved ?? null,
271
+ utc: o.UTC ?? null,
272
+ site: o.SiteName ?? null,
273
+ agency: o.AgencyName ?? null,
274
+ aqs_code: o.FullAQSCode ?? null,
275
+ latitude: o.Latitude ?? null,
276
+ longitude: o.Longitude ?? null,
277
+ pollutant: o.Parameter ?? null,
278
+ aqi: o.AQI ?? null,
279
+ category: o.Category ?? null,
280
+ value: o.Value ?? null,
281
+ unit: o.Unit ?? null,
282
+ })),
283
+ };
284
+ }
285
+
286
+ export default { tools, callTool, meter: { credits: 1 } } satisfies McpToolExport;
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "strict": true,
7
+ "esModuleInterop": true,
8
+ "skipLibCheck": true,
9
+ "outDir": "dist",
10
+ "rootDir": "src",
11
+ "declaration": true
12
+ },
13
+ "include": ["src"]
14
+ }