@pipeworx/mcp-duffel 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-duffel
2
+
3
+ Duffel MCP — live flight search + pricing via the Duffel Flights API (duffel.com)
4
+
5
+ Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 1209+ 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
+ "duffel": {
20
+ "url": "https://gateway.pipeworx.io/duffel/mcp"
21
+ }
22
+ }
23
+ }
24
+ ```
25
+
26
+ Or connect to the full Pipeworx gateway for access to all 1209+ 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 Duffel 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-duffel",
3
+ "version": "0.1.0",
4
+ "description": "Duffel MCP — live flight search + pricing via the Duffel Flights API (duffel.com)",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "types": "src/index.ts",
8
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "duffel"],
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/pipeworx-io/mcp-duffel"
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/duffel",
4
+ "title": "Duffel",
5
+ "description": "Duffel MCP — live flight search + pricing via the Duffel Flights API (duffel.com)",
6
+ "version": "0.1.0",
7
+ "websiteUrl": "https://pipeworx.io/packs/duffel",
8
+ "repository": {
9
+ "url": "https://github.com/pipeworx-io/mcp-duffel",
10
+ "source": "github"
11
+ },
12
+ "remotes": [
13
+ {
14
+ "type": "streamable-http",
15
+ "url": "https://gateway.pipeworx.io/duffel/mcp"
16
+ }
17
+ ]
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,225 @@
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
+ * Duffel MCP — live flight search + pricing via the Duffel Flights API (duffel.com)
21
+ *
22
+ * Tools:
23
+ * - duffel_flight_search: search real bookable flight offers between two airports.
24
+ *
25
+ * Auth: Duffel access token. Pass _apiKey = your Duffel token.
26
+ * - Live tokens (`duffel_live_...`) hit real inventory.
27
+ * - Test tokens (`duffel_test_...`) return sandbox inventory — use one to try it out.
28
+ * BYO-key only; the user's own token bears any Duffel cost.
29
+ */
30
+
31
+
32
+ const BASE_URL = 'https://api.duffel.com';
33
+
34
+ const tools: McpToolExport['tools'] = [
35
+ {
36
+ name: 'duffel_flight_search',
37
+ description:
38
+ 'Search flights (with pricing) from <origin> to <destination> on <date> — returns the 5 cheapest real, bookable offers from the Duffel Flights API, each with total price, airline, and per-segment flight numbers/times. Pass `return_date` for a round trip. This is REAL flight inventory: use a Duffel test token (duffel_test_...) for sandbox results. Example: duffel_flight_search({ origin: "JFK", destination: "LHR", departure_date: "2026-08-15", passengers: 2, cabin_class: "economy", _apiKey: "duffel_test_..." })',
39
+ inputSchema: {
40
+ type: 'object' as const,
41
+ properties: {
42
+ origin: {
43
+ type: 'string',
44
+ description: 'Origin airport IATA code, e.g. "JFK"',
45
+ },
46
+ destination: {
47
+ type: 'string',
48
+ description: 'Destination airport IATA code, e.g. "LHR"',
49
+ },
50
+ departure_date: {
51
+ type: 'string',
52
+ description: 'Outbound date in YYYY-MM-DD format, e.g. "2026-08-15"',
53
+ },
54
+ return_date: {
55
+ type: 'string',
56
+ description: 'Optional return date (YYYY-MM-DD). If given, searches a round trip (destination back to origin on this date).',
57
+ },
58
+ passengers: {
59
+ type: 'integer',
60
+ description: 'Number of adult passengers (default 1, max 9)',
61
+ },
62
+ cabin_class: {
63
+ type: 'string',
64
+ description: 'Optional cabin: economy, premium_economy, business, or first',
65
+ enum: ['economy', 'premium_economy', 'business', 'first'],
66
+ },
67
+ _apiKey: {
68
+ type: 'string',
69
+ description: 'Your Duffel access token (from duffel.com). A test token "duffel_test_..." works against the sandbox.',
70
+ },
71
+ },
72
+ required: ['origin', 'destination', 'departure_date', '_apiKey'],
73
+ },
74
+ },
75
+ ];
76
+
77
+ interface DuffelError {
78
+ title?: string;
79
+ message?: string;
80
+ }
81
+
82
+ async function duffelPost(path: string, body: unknown, apiKey: string, tool: string): Promise<Record<string, unknown>> {
83
+ if (!apiKey) {
84
+ throw new Error(
85
+ `${tool} requires a Duffel access token. Pass your token as _apiKey (get one at duffel.com — a test token "duffel_test_..." works against the sandbox). This is a BYO-key flight data source; your own Duffel account bears the cost.`,
86
+ );
87
+ }
88
+ const res = await fetch(`${BASE_URL}${path}`, {
89
+ method: 'POST',
90
+ headers: {
91
+ Authorization: `Bearer ${apiKey}`,
92
+ 'Duffel-Version': 'v2',
93
+ Accept: 'application/json',
94
+ 'Content-Type': 'application/json',
95
+ },
96
+ body: JSON.stringify(body),
97
+ });
98
+
99
+ if (res.status === 401) {
100
+ throw new Error('Duffel auth failed (HTTP 401) — check your Duffel token (_apiKey).');
101
+ }
102
+
103
+ if (!res.ok) {
104
+ let errors: DuffelError[] | undefined;
105
+ try {
106
+ const parsed = (await res.json()) as { errors?: DuffelError[] };
107
+ errors = parsed.errors;
108
+ } catch {
109
+ /* body not JSON */
110
+ }
111
+ const first = errors?.[0];
112
+ if (first && (first.message || first.title)) {
113
+ throw new Error(`Duffel: ${first.message ?? first.title}`);
114
+ }
115
+ throw new Error(`Duffel error: HTTP ${res.status}`);
116
+ }
117
+
118
+ const data = (await res.json()) as { data?: Record<string, unknown> };
119
+ return data.data ?? {};
120
+ }
121
+
122
+ function str(v: unknown): string | null {
123
+ return typeof v === 'string' ? v : null;
124
+ }
125
+
126
+ async function flightSearch(args: Record<string, unknown>, apiKey: string) {
127
+ const origin = str(args.origin);
128
+ const destination = str(args.destination);
129
+ const departure_date = str(args.departure_date);
130
+
131
+ if (!origin) throw new Error('duffel_flight_search requires an `origin` airport IATA code, e.g. "JFK".');
132
+ if (!destination) throw new Error('duffel_flight_search requires a `destination` airport IATA code, e.g. "LHR".');
133
+ if (!departure_date) throw new Error('duffel_flight_search requires a `departure_date` in YYYY-MM-DD format.');
134
+
135
+ const return_date = str(args.return_date);
136
+ const paxCount = Math.min(Math.max(Math.floor(Number(args.passengers ?? 1)) || 1, 1), 9);
137
+ const cabin_class = str(args.cabin_class);
138
+
139
+ const slices: Array<Record<string, string>> = [
140
+ { origin, destination, departure_date },
141
+ ];
142
+ if (return_date) {
143
+ slices.push({ origin: destination, destination: origin, departure_date: return_date });
144
+ }
145
+
146
+ const passengers = Array.from({ length: paxCount }, () => ({ type: 'adult' }));
147
+
148
+ const requestData: Record<string, unknown> = { slices, passengers };
149
+ if (cabin_class) requestData.cabin_class = cabin_class;
150
+
151
+ const data = await duffelPost(
152
+ '/air/offer_requests?return_offers=true',
153
+ { data: requestData },
154
+ apiKey,
155
+ 'duffel_flight_search',
156
+ );
157
+
158
+ const offers = Array.isArray(data.offers) ? (data.offers as Array<Record<string, unknown>>) : [];
159
+
160
+ const sorted = offers
161
+ .slice()
162
+ .sort((a, b) => parseFloat(String(a.total_amount ?? 'Infinity')) - parseFloat(String(b.total_amount ?? 'Infinity')))
163
+ .slice(0, 5);
164
+
165
+ const results = sorted.map((offer) => {
166
+ const owner = (offer.owner ?? {}) as Record<string, unknown>;
167
+ const offerSlices = Array.isArray(offer.slices) ? (offer.slices as Array<Record<string, unknown>>) : [];
168
+
169
+ return {
170
+ total_amount: str(offer.total_amount),
171
+ currency: str(offer.total_currency),
172
+ airline: str(owner.name),
173
+ slices: offerSlices.map((slice) => {
174
+ const sOrigin = (slice.origin ?? {}) as Record<string, unknown>;
175
+ const sDest = (slice.destination ?? {}) as Record<string, unknown>;
176
+ const segments = Array.isArray(slice.segments) ? (slice.segments as Array<Record<string, unknown>>) : [];
177
+ return {
178
+ origin: str(sOrigin.iata_code),
179
+ destination: str(sDest.iata_code),
180
+ duration: str(slice.duration),
181
+ segments: segments.map((seg) => {
182
+ const segOrigin = (seg.origin ?? {}) as Record<string, unknown>;
183
+ const segDest = (seg.destination ?? {}) as Record<string, unknown>;
184
+ const carrier = (seg.marketing_carrier ?? {}) as Record<string, unknown>;
185
+ const aircraft = (seg.aircraft ?? null) as Record<string, unknown> | null;
186
+ return {
187
+ from: str(segOrigin.iata_code),
188
+ to: str(segDest.iata_code),
189
+ departing_at: str(seg.departing_at),
190
+ arriving_at: str(seg.arriving_at),
191
+ carrier: str(carrier.name),
192
+ flight_number: str(seg.marketing_carrier_flight_number),
193
+ aircraft: aircraft ? str(aircraft.name) : null,
194
+ };
195
+ }),
196
+ };
197
+ }),
198
+ };
199
+ });
200
+
201
+ return {
202
+ origin,
203
+ destination,
204
+ departure_date,
205
+ return_date: return_date ?? null,
206
+ passengers: paxCount,
207
+ cabin_class: cabin_class ?? null,
208
+ total_offers: offers.length,
209
+ offers: results,
210
+ };
211
+ }
212
+
213
+ async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
214
+ const apiKey = args._apiKey as string;
215
+ delete args._apiKey;
216
+
217
+ switch (name) {
218
+ case 'duffel_flight_search':
219
+ return flightSearch(args, apiKey);
220
+ default:
221
+ throw new Error(`Unknown tool: ${name}`);
222
+ }
223
+ }
224
+
225
+ 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
+ }