@pipeworx/mcp-openaq 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 +21 -0
- package/README.md +34 -0
- package/package.json +20 -0
- package/server.json +18 -0
- package/src/index.ts +230 -0
- package/tsconfig.json +14 -0
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,34 @@
|
|
|
1
|
+
# mcp-openaq
|
|
2
|
+
|
|
3
|
+
OpenAQ MCP — wraps OpenAQ v2 API (free, no auth required)
|
|
4
|
+
|
|
5
|
+
Part of the [Pipeworx](https://pipeworx.io) open MCP gateway.
|
|
6
|
+
|
|
7
|
+
## Tools
|
|
8
|
+
|
|
9
|
+
| Tool | Description |
|
|
10
|
+
|------|-------------|
|
|
11
|
+
|
|
12
|
+
## Quick Start
|
|
13
|
+
|
|
14
|
+
Add to your MCP client config:
|
|
15
|
+
|
|
16
|
+
```json
|
|
17
|
+
{
|
|
18
|
+
"mcpServers": {
|
|
19
|
+
"openaq": {
|
|
20
|
+
"url": "https://gateway.pipeworx.io/openaq/mcp"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or use the CLI:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npx pipeworx use openaq
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## License
|
|
33
|
+
|
|
34
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pipeworx/mcp-openaq",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "OpenAQ MCP — wraps OpenAQ v2 API (free, no auth required)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.ts",
|
|
7
|
+
"types": "src/index.ts",
|
|
8
|
+
"keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "openaq"],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/pipeworx-io/mcp-openaq"
|
|
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/openaq",
|
|
4
|
+
"title": "openaq",
|
|
5
|
+
"description": "OpenAQ MCP — wraps OpenAQ v2 API (free, no auth required)",
|
|
6
|
+
"version": "0.1.0",
|
|
7
|
+
"websiteUrl": "https://pipeworx.io/packs/openaq",
|
|
8
|
+
"repository": {
|
|
9
|
+
"url": "https://github.com/pipeworx-io/mcp-openaq",
|
|
10
|
+
"source": "github"
|
|
11
|
+
},
|
|
12
|
+
"remotes": [
|
|
13
|
+
{
|
|
14
|
+
"type": "streamable-http",
|
|
15
|
+
"url": "https://gateway.pipeworx.io/openaq/mcp"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
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
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* OpenAQ MCP — wraps OpenAQ v2 API (free, no auth required)
|
|
18
|
+
*
|
|
19
|
+
* Tools:
|
|
20
|
+
* - get_latest: Latest measurements from air quality sensor stations
|
|
21
|
+
* - get_locations: Sensor locations filtered by city and/or country
|
|
22
|
+
* - get_measurements: Historical measurements for a specific location
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
const BASE_URL = 'https://api.openaq.org/v2';
|
|
27
|
+
|
|
28
|
+
type RawLatestResult = {
|
|
29
|
+
location: string;
|
|
30
|
+
city: string;
|
|
31
|
+
country: string;
|
|
32
|
+
coordinates: { latitude: number; longitude: number };
|
|
33
|
+
measurements: Array<{ parameter: string; value: number; unit: string; lastUpdated: string }>;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
type RawLatestResponse = {
|
|
37
|
+
results: RawLatestResult[];
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
type RawLocation = {
|
|
41
|
+
id: number;
|
|
42
|
+
name: string;
|
|
43
|
+
city: string;
|
|
44
|
+
country: string;
|
|
45
|
+
coordinates: { latitude: number; longitude: number };
|
|
46
|
+
parameters: Array<{ parameter: string; unit: string; lastUpdated: string; count: number }>;
|
|
47
|
+
isMobile: boolean;
|
|
48
|
+
isAnalysis: boolean;
|
|
49
|
+
firstUpdated: string;
|
|
50
|
+
lastUpdated: string;
|
|
51
|
+
sources: Array<{ name: string; url: string; id: string }>;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
type RawLocationsResponse = {
|
|
55
|
+
results: RawLocation[];
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
type RawMeasurement = {
|
|
59
|
+
locationId: number;
|
|
60
|
+
location: string;
|
|
61
|
+
parameter: string;
|
|
62
|
+
value: number;
|
|
63
|
+
unit: string;
|
|
64
|
+
date: { utc: string; local: string };
|
|
65
|
+
coordinates: { latitude: number; longitude: number };
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
type RawMeasurementsResponse = {
|
|
69
|
+
results: RawMeasurement[];
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const tools: McpToolExport['tools'] = [
|
|
73
|
+
{
|
|
74
|
+
name: 'get_latest',
|
|
75
|
+
description:
|
|
76
|
+
'Get the latest air quality measurements from sensor stations. Optionally filter by country. Returns readings for pollutants like PM2.5, PM10, ozone, NO2, SO2, and CO.',
|
|
77
|
+
inputSchema: {
|
|
78
|
+
type: 'object',
|
|
79
|
+
properties: {
|
|
80
|
+
limit: {
|
|
81
|
+
type: 'number',
|
|
82
|
+
description: 'Maximum number of station results to return (default 10, max 100).',
|
|
83
|
+
},
|
|
84
|
+
country: {
|
|
85
|
+
type: 'string',
|
|
86
|
+
description: 'ISO 3166-1 alpha-2 country code to filter by (e.g. "US", "GB", "DE").',
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
required: [],
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: 'get_locations',
|
|
94
|
+
description:
|
|
95
|
+
'Search for air quality sensor locations. Filter by city and/or country to find monitoring stations near a place of interest.',
|
|
96
|
+
inputSchema: {
|
|
97
|
+
type: 'object',
|
|
98
|
+
properties: {
|
|
99
|
+
limit: {
|
|
100
|
+
type: 'number',
|
|
101
|
+
description: 'Maximum number of locations to return (default 10, max 100).',
|
|
102
|
+
},
|
|
103
|
+
city: {
|
|
104
|
+
type: 'string',
|
|
105
|
+
description: 'City name to filter locations by (e.g. "London", "Los Angeles").',
|
|
106
|
+
},
|
|
107
|
+
country: {
|
|
108
|
+
type: 'string',
|
|
109
|
+
description: 'ISO 3166-1 alpha-2 country code to filter by (e.g. "US", "GB").',
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
required: [],
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
name: 'get_measurements',
|
|
117
|
+
description:
|
|
118
|
+
'Get historical measurements for a specific sensor location. Optionally filter by parameter (pm25, pm10, o3, no2, so2, co).',
|
|
119
|
+
inputSchema: {
|
|
120
|
+
type: 'object',
|
|
121
|
+
properties: {
|
|
122
|
+
location_id: {
|
|
123
|
+
type: 'number',
|
|
124
|
+
description: 'Numeric location ID from get_locations (e.g. 2178).',
|
|
125
|
+
},
|
|
126
|
+
limit: {
|
|
127
|
+
type: 'number',
|
|
128
|
+
description: 'Maximum number of measurement records to return (default 20, max 100).',
|
|
129
|
+
},
|
|
130
|
+
parameter: {
|
|
131
|
+
type: 'string',
|
|
132
|
+
description:
|
|
133
|
+
'Pollutant parameter to filter by. One of: pm25, pm10, o3, no2, so2, co.',
|
|
134
|
+
enum: ['pm25', 'pm10', 'o3', 'no2', 'so2', 'co'],
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
required: ['location_id'],
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
];
|
|
141
|
+
|
|
142
|
+
async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
|
|
143
|
+
switch (name) {
|
|
144
|
+
case 'get_latest':
|
|
145
|
+
return getLatest(
|
|
146
|
+
(args.limit as number | undefined) ?? 10,
|
|
147
|
+
args.country as string | undefined,
|
|
148
|
+
);
|
|
149
|
+
case 'get_locations':
|
|
150
|
+
return getLocations(
|
|
151
|
+
(args.limit as number | undefined) ?? 10,
|
|
152
|
+
args.city as string | undefined,
|
|
153
|
+
args.country as string | undefined,
|
|
154
|
+
);
|
|
155
|
+
case 'get_measurements':
|
|
156
|
+
return getMeasurements(
|
|
157
|
+
args.location_id as number,
|
|
158
|
+
(args.limit as number | undefined) ?? 20,
|
|
159
|
+
args.parameter as string | undefined,
|
|
160
|
+
);
|
|
161
|
+
default:
|
|
162
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
async function getLatest(limit: number, country?: string) {
|
|
167
|
+
const params = new URLSearchParams({ limit: String(Math.min(limit, 100)) });
|
|
168
|
+
if (country) params.set('country_id', country);
|
|
169
|
+
const res = await fetch(`${BASE_URL}/latest?${params}`);
|
|
170
|
+
if (!res.ok) throw new Error(`OpenAQ API error: ${res.status}`);
|
|
171
|
+
const data = (await res.json()) as RawLatestResponse;
|
|
172
|
+
return {
|
|
173
|
+
count: data.results.length,
|
|
174
|
+
stations: data.results.map((r) => ({
|
|
175
|
+
location: r.location,
|
|
176
|
+
city: r.city,
|
|
177
|
+
country: r.country,
|
|
178
|
+
coordinates: r.coordinates,
|
|
179
|
+
measurements: r.measurements,
|
|
180
|
+
})),
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
async function getLocations(limit: number, city?: string, country?: string) {
|
|
185
|
+
const params = new URLSearchParams({ limit: String(Math.min(limit, 100)) });
|
|
186
|
+
if (city) params.set('city', city);
|
|
187
|
+
if (country) params.set('country_id', country);
|
|
188
|
+
const res = await fetch(`${BASE_URL}/locations?${params}`);
|
|
189
|
+
if (!res.ok) throw new Error(`OpenAQ API error: ${res.status}`);
|
|
190
|
+
const data = (await res.json()) as RawLocationsResponse;
|
|
191
|
+
return {
|
|
192
|
+
count: data.results.length,
|
|
193
|
+
locations: data.results.map((l) => ({
|
|
194
|
+
id: l.id,
|
|
195
|
+
name: l.name,
|
|
196
|
+
city: l.city,
|
|
197
|
+
country: l.country,
|
|
198
|
+
coordinates: l.coordinates,
|
|
199
|
+
parameters: l.parameters.map((p) => p.parameter),
|
|
200
|
+
last_updated: l.lastUpdated,
|
|
201
|
+
first_updated: l.firstUpdated,
|
|
202
|
+
is_mobile: l.isMobile,
|
|
203
|
+
})),
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
async function getMeasurements(locationId: number, limit: number, parameter?: string) {
|
|
208
|
+
const params = new URLSearchParams({
|
|
209
|
+
location_id: String(locationId),
|
|
210
|
+
limit: String(Math.min(limit, 100)),
|
|
211
|
+
});
|
|
212
|
+
if (parameter) params.set('parameter', parameter);
|
|
213
|
+
const res = await fetch(`${BASE_URL}/measurements?${params}`);
|
|
214
|
+
if (!res.ok) throw new Error(`OpenAQ API error: ${res.status}`);
|
|
215
|
+
const data = (await res.json()) as RawMeasurementsResponse;
|
|
216
|
+
return {
|
|
217
|
+
count: data.results.length,
|
|
218
|
+
measurements: data.results.map((m) => ({
|
|
219
|
+
parameter: m.parameter,
|
|
220
|
+
value: m.value,
|
|
221
|
+
unit: m.unit,
|
|
222
|
+
date_utc: m.date.utc,
|
|
223
|
+
date_local: m.date.local,
|
|
224
|
+
location: m.location,
|
|
225
|
+
coordinates: m.coordinates,
|
|
226
|
+
})),
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export default { tools, callTool, meter: { credits: 5 } } 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
|
+
}
|