@pipeworx/mcp-opensky 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,55 @@
1
+ # mcp-opensky
2
+
3
+ OpenSky MCP — OpenSky Network API (free, no auth for anonymous access)
4
+
5
+ Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 965+ live data sources.
6
+
7
+ ## Tools
8
+
9
+ | Tool | Description |
10
+ |------|-------------|
11
+
12
+ ## Quick Start
13
+
14
+ Add to your MCP client (Claude Desktop, Cursor, Windsurf, etc.):
15
+
16
+ ```json
17
+ {
18
+ "mcpServers": {
19
+ "opensky": {
20
+ "url": "https://gateway.pipeworx.io/opensky/mcp"
21
+ }
22
+ }
23
+ }
24
+ ```
25
+
26
+ Or connect to the full Pipeworx gateway for access to all 965+ data sources:
27
+
28
+ ```json
29
+ {
30
+ "mcpServers": {
31
+ "pipeworx": {
32
+ "url": "https://gateway.pipeworx.io/mcp"
33
+ }
34
+ }
35
+ }
36
+ ```
37
+
38
+ ## Using with ask_pipeworx
39
+
40
+ Instead of calling tools directly, you can ask questions in plain English:
41
+
42
+ ```
43
+ ask_pipeworx({ question: "your question about Opensky data" })
44
+ ```
45
+
46
+ The gateway picks the right tool and fills the arguments automatically.
47
+
48
+ ## More
49
+
50
+ - [All tools and guides](https://github.com/pipeworx-io/examples)
51
+ - [pipeworx.io](https://pipeworx.io)
52
+
53
+ ## License
54
+
55
+ MIT
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@pipeworx/mcp-opensky",
3
+ "version": "0.1.0",
4
+ "description": "OpenSky MCP — OpenSky Network API (free, no auth for anonymous access)",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "types": "src/index.ts",
8
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "opensky"],
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/pipeworx-io/mcp-opensky"
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/opensky",
4
+ "title": "Opensky",
5
+ "description": "OpenSky MCP — OpenSky Network API (free, no auth for anonymous access)",
6
+ "version": "0.1.0",
7
+ "websiteUrl": "https://pipeworx.io/packs/opensky",
8
+ "repository": {
9
+ "url": "https://github.com/pipeworx-io/mcp-opensky",
10
+ "source": "github"
11
+ },
12
+ "remotes": [
13
+ {
14
+ "type": "streamable-http",
15
+ "url": "https://gateway.pipeworx.io/opensky/mcp"
16
+ }
17
+ ]
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,307 @@
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
+ * OpenSky MCP — OpenSky Network API (free, no auth for anonymous access)
21
+ *
22
+ * Tools:
23
+ * - get_flights: get flights within a time interval (max 2 hours)
24
+ * - get_aircraft: get flights for a specific aircraft by ICAO24 address
25
+ * - get_states: get current state vectors of all aircraft (or filtered by ICAO24)
26
+ */
27
+
28
+
29
+ const BASE_URL = 'https://opensky-network.org/api';
30
+
31
+ // --- Raw API types ---
32
+
33
+ type RawFlight = {
34
+ icao24?: string | null;
35
+ firstSeen?: number | null;
36
+ estDepartureAirport?: string | null;
37
+ lastSeen?: number | null;
38
+ estArrivalAirport?: string | null;
39
+ callsign?: string | null;
40
+ estDepartureAirportHorizDistance?: number | null;
41
+ estDepartureAirportVertDistance?: number | null;
42
+ estArrivalAirportHorizDistance?: number | null;
43
+ estArrivalAirportVertDistance?: number | null;
44
+ departureAirportCandidatesCount?: number | null;
45
+ arrivalAirportCandidatesCount?: number | null;
46
+ };
47
+
48
+ // State vector is returned as an array
49
+ // [icao24, callsign, origin_country, time_position, last_contact,
50
+ // longitude, latitude, baro_altitude, on_ground, velocity,
51
+ // true_track, vertical_rate, sensors, geo_altitude, squawk,
52
+ // spi, position_source, category]
53
+ type StateVector = (string | number | boolean | number[] | null)[];
54
+
55
+ type StatesResponse = {
56
+ time?: number | null;
57
+ states?: StateVector[] | null;
58
+ };
59
+
60
+ // --- Formatters ---
61
+
62
+ function formatFlight(f: RawFlight) {
63
+ return {
64
+ icao24: f.icao24 ?? null,
65
+ callsign: f.callsign?.trim() ?? null,
66
+ departure_airport: f.estDepartureAirport ?? null,
67
+ arrival_airport: f.estArrivalAirport ?? null,
68
+ first_seen: f.firstSeen ? new Date(f.firstSeen * 1000).toISOString() : null,
69
+ last_seen: f.lastSeen ? new Date(f.lastSeen * 1000).toISOString() : null,
70
+ };
71
+ }
72
+
73
+ function formatState(s: StateVector) {
74
+ return {
75
+ icao24: (s[0] as string) ?? null,
76
+ callsign: ((s[1] as string) ?? '').trim() || null,
77
+ origin_country: (s[2] as string) ?? null,
78
+ longitude: (s[5] as number) ?? null,
79
+ latitude: (s[6] as number) ?? null,
80
+ baro_altitude_m: (s[7] as number) ?? null,
81
+ on_ground: (s[8] as boolean) ?? null,
82
+ velocity_ms: (s[9] as number) ?? null,
83
+ true_track_deg: (s[10] as number) ?? null,
84
+ vertical_rate_ms: (s[11] as number) ?? null,
85
+ geo_altitude_m: (s[13] as number) ?? null,
86
+ squawk: (s[14] as string) ?? null,
87
+ };
88
+ }
89
+
90
+ // --- Tool definitions ---
91
+
92
+ const tools: McpToolExport['tools'] = [
93
+ {
94
+ name: 'get_flights',
95
+ description:
96
+ 'Get all flights within a time interval (max 2 hours). Returns ICAO24 address, callsign, departure/arrival airports. Provide begin and end as Unix timestamps. Example: get_flights(1696118400, 1696125600).',
97
+ inputSchema: {
98
+ type: 'object',
99
+ properties: {
100
+ begin: { type: 'number', description: 'Start of time interval as Unix timestamp (seconds)' },
101
+ end: { type: 'number', description: 'End of time interval as Unix timestamp (seconds, max 2h after begin)' },
102
+ },
103
+ required: ['begin', 'end'],
104
+ },
105
+ },
106
+ {
107
+ name: 'get_aircraft',
108
+ description:
109
+ 'Get flights for a specific aircraft by its ICAO24 transponder address (hex string, e.g., "3c675a"). Returns departure/arrival airports and times. Optionally specify a time range.',
110
+ inputSchema: {
111
+ type: 'object',
112
+ properties: {
113
+ icao24: { type: 'string', description: 'ICAO24 transponder address in hex (e.g., "3c675a")' },
114
+ begin: { type: 'number', description: 'Start of time interval as Unix timestamp (optional, defaults to last 24h)' },
115
+ end: { type: 'number', description: 'End of time interval as Unix timestamp (optional, defaults to now)' },
116
+ },
117
+ required: ['icao24'],
118
+ },
119
+ },
120
+ {
121
+ name: 'get_states',
122
+ description:
123
+ 'Get live ADS-B state vectors for all currently tracked aircraft (up to 100 returned), or filter to specific aircraft by passing comma-separated ICAO24 hex addresses. Returns position (lat/lon), barometric and geometric altitude (metres), velocity (m/s), heading (degrees), vertical rate, and on-ground flag.',
124
+ inputSchema: {
125
+ type: 'object',
126
+ properties: {
127
+ icao24: {
128
+ type: 'string',
129
+ description: 'Filter by one or more ICAO24 addresses (comma-separated, e.g., "3c675a,3c675b")',
130
+ },
131
+ },
132
+ },
133
+ },
134
+ {
135
+ name: 'airspace_activity',
136
+ description:
137
+ 'Summary of live flight activity over a named region — total aircraft count, by-country breakdown of operators, average altitude, ground vs in-air split. Built for "is airspace open / closed" style geopolitical bets (Polymarket "Iran closes its airspace by X", "Strait of Hormuz traffic returns to normal", "Russia closes airspace"). Supported regions: Iran, Israel, Syria, Ukraine, Russia, Taiwan, North Korea, South China Sea, Yemen, Strait of Hormuz, Taiwan Strait, Red Sea, Saudi Arabia, Gulf of Aden, Lebanon.',
138
+ inputSchema: {
139
+ type: 'object',
140
+ properties: {
141
+ region: {
142
+ type: 'string',
143
+ description: 'Region name (case-insensitive). Use one of the named regions above, or use get_states with an icao24 filter for custom areas.',
144
+ },
145
+ },
146
+ required: ['region'],
147
+ },
148
+ },
149
+ ];
150
+
151
+ // Bounding boxes for common geopolitical-bet regions. Coords are
152
+ // [lat_min, lon_min, lat_max, lon_max]. Used by airspace_activity.
153
+ const REGION_BOXES: Record<string, [number, number, number, number]> = {
154
+ iran: [25.0, 44.0, 40.0, 64.0],
155
+ 'strait of hormuz': [24.5, 55.0, 27.5, 58.0],
156
+ israel: [29.0, 34.0, 34.0, 36.5],
157
+ syria: [32.0, 35.0, 37.5, 43.0],
158
+ lebanon: [33.0, 35.0, 35.0, 36.7],
159
+ ukraine: [44.0, 22.0, 53.0, 41.0],
160
+ russia: [41.0, 19.0, 82.0, 180.0],
161
+ taiwan: [21.5, 118.0, 26.5, 124.0],
162
+ 'taiwan strait': [22.0, 117.0, 27.0, 122.0],
163
+ 'north korea': [37.5, 124.0, 43.0, 131.0],
164
+ 'south china sea': [ 5.0, 105.0, 22.0, 122.0],
165
+ yemen: [12.0, 42.0, 19.0, 54.0],
166
+ 'red sea': [12.0, 32.0, 28.0, 43.5],
167
+ 'gulf of aden': [10.0, 43.0, 15.0, 52.0],
168
+ 'saudi arabia': [16.0, 34.0, 32.0, 56.0],
169
+ };
170
+
171
+ // --- callTool dispatcher ---
172
+
173
+ async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
174
+ switch (name) {
175
+ case 'get_flights':
176
+ return getFlights(args.begin as number, args.end as number);
177
+ case 'get_aircraft':
178
+ return getAircraft(
179
+ args.icao24 as string,
180
+ args.begin as number | undefined,
181
+ args.end as number | undefined,
182
+ );
183
+ case 'get_states':
184
+ return getStates(args.icao24 as string | undefined);
185
+ case 'airspace_activity':
186
+ return airspaceActivity(String(args.region ?? '').trim().toLowerCase());
187
+ default:
188
+ throw new Error(`Unknown tool: ${name}`);
189
+ }
190
+ }
191
+
192
+ async function airspaceActivity(region: string) {
193
+ const bbox = REGION_BOXES[region];
194
+ if (!bbox) {
195
+ throw new Error(
196
+ `Unknown region "${region}". Supported: ${Object.keys(REGION_BOXES).join(', ')}.`,
197
+ );
198
+ }
199
+ const [latMin, lonMin, latMax, lonMax] = bbox;
200
+ const url = `${BASE_URL}/states/all?lamin=${latMin}&lomin=${lonMin}&lamax=${latMax}&lomax=${lonMax}`;
201
+ const res = await fetch(url, { headers: { 'User-Agent': 'Pipeworx-OpenSky/1.0 (https://pipeworx.io)' } });
202
+ if (res.status === 429) {
203
+ throw new Error('OpenSky rate limit (10 anonymous calls/minute). Wait then retry, or sign up at opensky-network.org for higher limits.');
204
+ }
205
+ if (!res.ok) throw new Error(`OpenSky API error: ${res.status}`);
206
+ const data = (await res.json()) as StatesResponse;
207
+ const states = data.states ?? [];
208
+ const byCountry: Record<string, number> = {};
209
+ let altSum = 0; let altCount = 0;
210
+ let onGround = 0;
211
+ for (const s of states) {
212
+ const c = (s[2] as string) || 'unknown';
213
+ byCountry[c] = (byCountry[c] ?? 0) + 1;
214
+ const alt = s[7] as number | null;
215
+ if (alt != null) { altSum += alt; altCount++; }
216
+ if (s[8] as boolean) onGround++;
217
+ }
218
+ const topCountries = Object.entries(byCountry)
219
+ .sort((a, b) => b[1] - a[1])
220
+ .slice(0, 15)
221
+ .map(([country, count]) => ({ country, count }));
222
+ return {
223
+ region,
224
+ bbox: { lat_min: latMin, lon_min: lonMin, lat_max: latMax, lon_max: lonMax },
225
+ time: data.time ? new Date(data.time * 1000).toISOString() : null,
226
+ total_aircraft: states.length,
227
+ in_air: states.length - onGround,
228
+ on_ground: onGround,
229
+ avg_altitude_m: altCount > 0 ? Math.round(altSum / altCount) : null,
230
+ operators_by_country: topCountries,
231
+ note: 'OpenSky reflects live ADS-B transponder data. Military / state aircraft often disable transponders, so this undercounts non-civilian activity. Best used as a "civilian aviation normalcy" signal.',
232
+ };
233
+ }
234
+
235
+ // --- Tool implementations ---
236
+
237
+ async function getFlights(begin: number, end: number) {
238
+ const params = new URLSearchParams({
239
+ begin: String(begin),
240
+ end: String(end),
241
+ });
242
+
243
+ const res = await fetch(`${BASE_URL}/flights/all?${params}`);
244
+ if (!res.ok) throw new Error(`OpenSky API error: ${res.status}`);
245
+
246
+ const data = (await res.json()) as RawFlight[];
247
+
248
+ return {
249
+ begin: new Date(begin * 1000).toISOString(),
250
+ end: new Date(end * 1000).toISOString(),
251
+ count: data.length,
252
+ flights: data.slice(0, 100).map(formatFlight),
253
+ };
254
+ }
255
+
256
+ async function getAircraft(icao24: string, begin?: number, end?: number) {
257
+ const now = Math.floor(Date.now() / 1000);
258
+ const effectiveEnd = end ?? now;
259
+ const effectiveBegin = begin ?? effectiveEnd - 86400;
260
+
261
+ const params = new URLSearchParams({
262
+ icao24: icao24.toLowerCase(),
263
+ begin: String(effectiveBegin),
264
+ end: String(effectiveEnd),
265
+ });
266
+
267
+ const res = await fetch(`${BASE_URL}/flights/aircraft?${params}`);
268
+ if (!res.ok) throw new Error(`OpenSky API error: ${res.status}`);
269
+
270
+ const data = (await res.json()) as RawFlight[];
271
+
272
+ return {
273
+ icao24: icao24.toLowerCase(),
274
+ begin: new Date(effectiveBegin * 1000).toISOString(),
275
+ end: new Date(effectiveEnd * 1000).toISOString(),
276
+ count: data.length,
277
+ flights: data.map(formatFlight),
278
+ };
279
+ }
280
+
281
+ async function getStates(icao24Filter?: string) {
282
+ const params = new URLSearchParams();
283
+ if (icao24Filter) {
284
+ // API accepts multiple icao24 params
285
+ for (const addr of icao24Filter.split(',')) {
286
+ params.append('icao24', addr.trim().toLowerCase());
287
+ }
288
+ }
289
+
290
+ const url = params.toString()
291
+ ? `${BASE_URL}/states/all?${params}`
292
+ : `${BASE_URL}/states/all`;
293
+
294
+ const res = await fetch(url);
295
+ if (!res.ok) throw new Error(`OpenSky API error: ${res.status}`);
296
+
297
+ const data = (await res.json()) as StatesResponse;
298
+ const states = data.states ?? [];
299
+
300
+ return {
301
+ time: data.time ? new Date(data.time * 1000).toISOString() : null,
302
+ count: states.length,
303
+ states: states.slice(0, 100).map(formatState),
304
+ };
305
+ }
306
+
307
+ 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
+ }