integrate-sdk 0.4.2 → 0.4.3
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/dist/index.js +205 -229
- package/dist/oauth.js +5 -18
- package/dist/server.js +209 -228
- package/dist/src/adapters/base-handler.d.ts.map +1 -1
- package/dist/src/server.d.ts +14 -2
- package/dist/src/server.d.ts.map +1 -1
- package/package.json +2 -3
package/dist/index.js
CHANGED
|
@@ -1,21 +1,4 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
6
|
-
var __toCommonJS = (from) => {
|
|
7
|
-
var entry = __moduleCache.get(from), desc;
|
|
8
|
-
if (entry)
|
|
9
|
-
return entry;
|
|
10
|
-
entry = __defProp({}, "__esModule", { value: true });
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
12
|
-
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
13
|
-
get: () => from[key],
|
|
14
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
-
}));
|
|
16
|
-
__moduleCache.set(from, entry);
|
|
17
|
-
return entry;
|
|
18
|
-
};
|
|
19
2
|
var __export = (target, all) => {
|
|
20
3
|
for (var name in all)
|
|
21
4
|
__defProp(target, name, {
|
|
@@ -165,215 +148,6 @@ var init_errors = __esm(() => {
|
|
|
165
148
|
};
|
|
166
149
|
});
|
|
167
150
|
|
|
168
|
-
// src/adapters/base-handler.ts
|
|
169
|
-
class OAuthHandler {
|
|
170
|
-
config;
|
|
171
|
-
serverUrl = MCP_SERVER_URL2;
|
|
172
|
-
constructor(config) {
|
|
173
|
-
this.config = config;
|
|
174
|
-
}
|
|
175
|
-
async handleAuthorize(request) {
|
|
176
|
-
const providerConfig = this.config.providers[request.provider];
|
|
177
|
-
if (!providerConfig) {
|
|
178
|
-
throw new Error(`Provider ${request.provider} not configured. Add OAuth credentials to your API route configuration.`);
|
|
179
|
-
}
|
|
180
|
-
if (!providerConfig.clientId || !providerConfig.clientSecret) {
|
|
181
|
-
throw new Error(`Missing OAuth credentials for ${request.provider}. Check your environment variables.`);
|
|
182
|
-
}
|
|
183
|
-
const url = new URL("/oauth/authorize", this.serverUrl);
|
|
184
|
-
url.searchParams.set("provider", request.provider);
|
|
185
|
-
url.searchParams.set("client_id", providerConfig.clientId);
|
|
186
|
-
url.searchParams.set("client_secret", providerConfig.clientSecret);
|
|
187
|
-
url.searchParams.set("scope", request.scopes.join(","));
|
|
188
|
-
url.searchParams.set("state", request.state);
|
|
189
|
-
url.searchParams.set("code_challenge", request.codeChallenge);
|
|
190
|
-
url.searchParams.set("code_challenge_method", request.codeChallengeMethod);
|
|
191
|
-
const redirectUri = request.redirectUri || providerConfig.redirectUri;
|
|
192
|
-
if (redirectUri) {
|
|
193
|
-
url.searchParams.set("redirect_uri", redirectUri);
|
|
194
|
-
}
|
|
195
|
-
const response = await fetch(url.toString(), {
|
|
196
|
-
method: "GET"
|
|
197
|
-
});
|
|
198
|
-
if (!response.ok) {
|
|
199
|
-
const error = await response.text();
|
|
200
|
-
throw new Error(`MCP server failed to generate authorization URL: ${error}`);
|
|
201
|
-
}
|
|
202
|
-
const data = await response.json();
|
|
203
|
-
return data;
|
|
204
|
-
}
|
|
205
|
-
async handleCallback(request) {
|
|
206
|
-
const providerConfig = this.config.providers[request.provider];
|
|
207
|
-
if (!providerConfig) {
|
|
208
|
-
throw new Error(`Provider ${request.provider} not configured. Add OAuth credentials to your API route configuration.`);
|
|
209
|
-
}
|
|
210
|
-
if (!providerConfig.clientId || !providerConfig.clientSecret) {
|
|
211
|
-
throw new Error(`Missing OAuth credentials for ${request.provider}. Check your environment variables.`);
|
|
212
|
-
}
|
|
213
|
-
const url = new URL("/oauth/callback", this.serverUrl);
|
|
214
|
-
const response = await fetch(url.toString(), {
|
|
215
|
-
method: "POST",
|
|
216
|
-
headers: {
|
|
217
|
-
"Content-Type": "application/json"
|
|
218
|
-
},
|
|
219
|
-
body: JSON.stringify({
|
|
220
|
-
provider: request.provider,
|
|
221
|
-
code: request.code,
|
|
222
|
-
code_verifier: request.codeVerifier,
|
|
223
|
-
state: request.state,
|
|
224
|
-
client_id: providerConfig.clientId,
|
|
225
|
-
client_secret: providerConfig.clientSecret
|
|
226
|
-
})
|
|
227
|
-
});
|
|
228
|
-
if (!response.ok) {
|
|
229
|
-
const error = await response.text();
|
|
230
|
-
throw new Error(`MCP server failed to exchange authorization code: ${error}`);
|
|
231
|
-
}
|
|
232
|
-
const data = await response.json();
|
|
233
|
-
return data;
|
|
234
|
-
}
|
|
235
|
-
async handleStatus(provider, accessToken) {
|
|
236
|
-
const url = new URL("/oauth/status", this.serverUrl);
|
|
237
|
-
url.searchParams.set("provider", provider);
|
|
238
|
-
const response = await fetch(url.toString(), {
|
|
239
|
-
method: "GET",
|
|
240
|
-
headers: {
|
|
241
|
-
Authorization: `Bearer ${accessToken}`
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
if (!response.ok) {
|
|
245
|
-
if (response.status === 401) {
|
|
246
|
-
return {
|
|
247
|
-
authorized: false
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
const error = await response.text();
|
|
251
|
-
throw new Error(`MCP server failed to check authorization status: ${error}`);
|
|
252
|
-
}
|
|
253
|
-
const data = await response.json();
|
|
254
|
-
return data;
|
|
255
|
-
}
|
|
256
|
-
async handleDisconnect(request, accessToken) {
|
|
257
|
-
if (!accessToken) {
|
|
258
|
-
throw new Error("No access token provided. Cannot disconnect provider.");
|
|
259
|
-
}
|
|
260
|
-
const url = new URL("/oauth/disconnect", this.serverUrl);
|
|
261
|
-
const response = await fetch(url.toString(), {
|
|
262
|
-
method: "POST",
|
|
263
|
-
headers: {
|
|
264
|
-
"Content-Type": "application/json",
|
|
265
|
-
Authorization: `Bearer ${accessToken}`
|
|
266
|
-
},
|
|
267
|
-
body: JSON.stringify({
|
|
268
|
-
provider: request.provider
|
|
269
|
-
})
|
|
270
|
-
});
|
|
271
|
-
if (!response.ok) {
|
|
272
|
-
const error = await response.text();
|
|
273
|
-
throw new Error(`MCP server failed to disconnect provider: ${error}`);
|
|
274
|
-
}
|
|
275
|
-
const data = await response.json();
|
|
276
|
-
return data;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
var MCP_SERVER_URL2 = "https://mcp.integrate.dev/api/v1/mcp";
|
|
280
|
-
|
|
281
|
-
// src/adapters/nextjs.ts
|
|
282
|
-
var exports_nextjs = {};
|
|
283
|
-
__export(exports_nextjs, {
|
|
284
|
-
createNextOAuthHandler: () => createNextOAuthHandler
|
|
285
|
-
});
|
|
286
|
-
function createNextOAuthHandler(config) {
|
|
287
|
-
const handler = new OAuthHandler(config);
|
|
288
|
-
const handlers = {
|
|
289
|
-
async authorize(req) {
|
|
290
|
-
try {
|
|
291
|
-
const body = await req.json();
|
|
292
|
-
const result = await handler.handleAuthorize(body);
|
|
293
|
-
return Response.json(result);
|
|
294
|
-
} catch (error) {
|
|
295
|
-
console.error("[OAuth Authorize] Error:", error);
|
|
296
|
-
return Response.json({ error: error.message || "Failed to get authorization URL" }, { status: 500 });
|
|
297
|
-
}
|
|
298
|
-
},
|
|
299
|
-
async callback(req) {
|
|
300
|
-
try {
|
|
301
|
-
const body = await req.json();
|
|
302
|
-
const result = await handler.handleCallback(body);
|
|
303
|
-
return Response.json(result);
|
|
304
|
-
} catch (error) {
|
|
305
|
-
console.error("[OAuth Callback] Error:", error);
|
|
306
|
-
return Response.json({ error: error.message || "Failed to exchange authorization code" }, { status: 500 });
|
|
307
|
-
}
|
|
308
|
-
},
|
|
309
|
-
async status(req) {
|
|
310
|
-
try {
|
|
311
|
-
const provider = req.nextUrl.searchParams.get("provider");
|
|
312
|
-
const authHeader = req.headers.get("authorization");
|
|
313
|
-
if (!provider) {
|
|
314
|
-
return Response.json({ error: "Missing provider query parameter" }, { status: 400 });
|
|
315
|
-
}
|
|
316
|
-
if (!authHeader || !authHeader.startsWith("Bearer ")) {
|
|
317
|
-
return Response.json({ error: "Missing or invalid Authorization header" }, { status: 400 });
|
|
318
|
-
}
|
|
319
|
-
const accessToken = authHeader.substring(7);
|
|
320
|
-
const result = await handler.handleStatus(provider, accessToken);
|
|
321
|
-
return Response.json(result);
|
|
322
|
-
} catch (error) {
|
|
323
|
-
console.error("[OAuth Status] Error:", error);
|
|
324
|
-
return Response.json({ error: error.message || "Failed to check authorization status" }, { status: 500 });
|
|
325
|
-
}
|
|
326
|
-
},
|
|
327
|
-
async disconnect(req) {
|
|
328
|
-
try {
|
|
329
|
-
const authHeader = req.headers.get("authorization");
|
|
330
|
-
if (!authHeader || !authHeader.startsWith("Bearer ")) {
|
|
331
|
-
return Response.json({ error: "Missing or invalid Authorization header" }, { status: 400 });
|
|
332
|
-
}
|
|
333
|
-
const accessToken = authHeader.substring(7);
|
|
334
|
-
const body = await req.json();
|
|
335
|
-
const { provider } = body;
|
|
336
|
-
if (!provider) {
|
|
337
|
-
return Response.json({ error: "Missing provider in request body" }, { status: 400 });
|
|
338
|
-
}
|
|
339
|
-
const result = await handler.handleDisconnect({ provider }, accessToken);
|
|
340
|
-
return Response.json(result);
|
|
341
|
-
} catch (error) {
|
|
342
|
-
console.error("[OAuth Disconnect] Error:", error);
|
|
343
|
-
return Response.json({ error: error.message || "Failed to disconnect provider" }, { status: 500 });
|
|
344
|
-
}
|
|
345
|
-
},
|
|
346
|
-
createRoutes() {
|
|
347
|
-
return {
|
|
348
|
-
async POST(req, context) {
|
|
349
|
-
const params = context.params instanceof Promise ? await context.params : context.params;
|
|
350
|
-
const action = params.action;
|
|
351
|
-
if (action === "authorize") {
|
|
352
|
-
return handlers.authorize(req);
|
|
353
|
-
}
|
|
354
|
-
if (action === "callback") {
|
|
355
|
-
return handlers.callback(req);
|
|
356
|
-
}
|
|
357
|
-
if (action === "disconnect") {
|
|
358
|
-
return handlers.disconnect(req);
|
|
359
|
-
}
|
|
360
|
-
return Response.json({ error: `Unknown action: ${action}` }, { status: 404 });
|
|
361
|
-
},
|
|
362
|
-
async GET(req, context) {
|
|
363
|
-
const params = context.params instanceof Promise ? await context.params : context.params;
|
|
364
|
-
const action = params.action;
|
|
365
|
-
if (action === "status") {
|
|
366
|
-
return handlers.status(req);
|
|
367
|
-
}
|
|
368
|
-
return Response.json({ error: `Unknown action: ${action}` }, { status: 404 });
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
};
|
|
373
|
-
return handlers;
|
|
374
|
-
}
|
|
375
|
-
var init_nextjs = () => {};
|
|
376
|
-
|
|
377
151
|
// src/protocol/jsonrpc.ts
|
|
378
152
|
function parseMessage(message) {
|
|
379
153
|
try {
|
|
@@ -1734,10 +1508,212 @@ async function clearClientCache() {
|
|
|
1734
1508
|
}
|
|
1735
1509
|
}));
|
|
1736
1510
|
}
|
|
1511
|
+
// src/adapters/base-handler.ts
|
|
1512
|
+
var MCP_SERVER_URL2 = "https://mcp.integrate.dev/api/v1/mcp";
|
|
1737
1513
|
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1514
|
+
class OAuthHandler {
|
|
1515
|
+
config;
|
|
1516
|
+
serverUrl = MCP_SERVER_URL2;
|
|
1517
|
+
constructor(config) {
|
|
1518
|
+
this.config = config;
|
|
1519
|
+
if (!config || !config.providers) {
|
|
1520
|
+
throw new Error("OAuthHandler requires a valid config with providers");
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
async handleAuthorize(request) {
|
|
1524
|
+
const providerConfig = this.config.providers[request.provider];
|
|
1525
|
+
if (!providerConfig) {
|
|
1526
|
+
throw new Error(`Provider ${request.provider} not configured. Add OAuth credentials to your API route configuration.`);
|
|
1527
|
+
}
|
|
1528
|
+
if (!providerConfig.clientId || !providerConfig.clientSecret) {
|
|
1529
|
+
throw new Error(`Missing OAuth credentials for ${request.provider}. Check your environment variables.`);
|
|
1530
|
+
}
|
|
1531
|
+
const url = new URL("/oauth/authorize", this.serverUrl);
|
|
1532
|
+
url.searchParams.set("provider", request.provider);
|
|
1533
|
+
url.searchParams.set("client_id", providerConfig.clientId);
|
|
1534
|
+
url.searchParams.set("client_secret", providerConfig.clientSecret);
|
|
1535
|
+
url.searchParams.set("scope", request.scopes.join(","));
|
|
1536
|
+
url.searchParams.set("state", request.state);
|
|
1537
|
+
url.searchParams.set("code_challenge", request.codeChallenge);
|
|
1538
|
+
url.searchParams.set("code_challenge_method", request.codeChallengeMethod);
|
|
1539
|
+
const redirectUri = request.redirectUri || providerConfig.redirectUri;
|
|
1540
|
+
if (redirectUri) {
|
|
1541
|
+
url.searchParams.set("redirect_uri", redirectUri);
|
|
1542
|
+
}
|
|
1543
|
+
const response = await fetch(url.toString(), {
|
|
1544
|
+
method: "GET"
|
|
1545
|
+
});
|
|
1546
|
+
if (!response.ok) {
|
|
1547
|
+
const error = await response.text();
|
|
1548
|
+
throw new Error(`MCP server failed to generate authorization URL: ${error}`);
|
|
1549
|
+
}
|
|
1550
|
+
const data = await response.json();
|
|
1551
|
+
return data;
|
|
1552
|
+
}
|
|
1553
|
+
async handleCallback(request) {
|
|
1554
|
+
const providerConfig = this.config.providers[request.provider];
|
|
1555
|
+
if (!providerConfig) {
|
|
1556
|
+
throw new Error(`Provider ${request.provider} not configured. Add OAuth credentials to your API route configuration.`);
|
|
1557
|
+
}
|
|
1558
|
+
if (!providerConfig.clientId || !providerConfig.clientSecret) {
|
|
1559
|
+
throw new Error(`Missing OAuth credentials for ${request.provider}. Check your environment variables.`);
|
|
1560
|
+
}
|
|
1561
|
+
const url = new URL("/oauth/callback", this.serverUrl);
|
|
1562
|
+
const response = await fetch(url.toString(), {
|
|
1563
|
+
method: "POST",
|
|
1564
|
+
headers: {
|
|
1565
|
+
"Content-Type": "application/json"
|
|
1566
|
+
},
|
|
1567
|
+
body: JSON.stringify({
|
|
1568
|
+
provider: request.provider,
|
|
1569
|
+
code: request.code,
|
|
1570
|
+
code_verifier: request.codeVerifier,
|
|
1571
|
+
state: request.state,
|
|
1572
|
+
client_id: providerConfig.clientId,
|
|
1573
|
+
client_secret: providerConfig.clientSecret
|
|
1574
|
+
})
|
|
1575
|
+
});
|
|
1576
|
+
if (!response.ok) {
|
|
1577
|
+
const error = await response.text();
|
|
1578
|
+
throw new Error(`MCP server failed to exchange authorization code: ${error}`);
|
|
1579
|
+
}
|
|
1580
|
+
const data = await response.json();
|
|
1581
|
+
return data;
|
|
1582
|
+
}
|
|
1583
|
+
async handleStatus(provider, accessToken) {
|
|
1584
|
+
const url = new URL("/oauth/status", this.serverUrl);
|
|
1585
|
+
url.searchParams.set("provider", provider);
|
|
1586
|
+
const response = await fetch(url.toString(), {
|
|
1587
|
+
method: "GET",
|
|
1588
|
+
headers: {
|
|
1589
|
+
Authorization: `Bearer ${accessToken}`
|
|
1590
|
+
}
|
|
1591
|
+
});
|
|
1592
|
+
if (!response.ok) {
|
|
1593
|
+
if (response.status === 401) {
|
|
1594
|
+
return {
|
|
1595
|
+
authorized: false
|
|
1596
|
+
};
|
|
1597
|
+
}
|
|
1598
|
+
const error = await response.text();
|
|
1599
|
+
throw new Error(`MCP server failed to check authorization status: ${error}`);
|
|
1600
|
+
}
|
|
1601
|
+
const data = await response.json();
|
|
1602
|
+
return data;
|
|
1603
|
+
}
|
|
1604
|
+
async handleDisconnect(request, accessToken) {
|
|
1605
|
+
if (!accessToken) {
|
|
1606
|
+
throw new Error("No access token provided. Cannot disconnect provider.");
|
|
1607
|
+
}
|
|
1608
|
+
const url = new URL("/oauth/disconnect", this.serverUrl);
|
|
1609
|
+
const response = await fetch(url.toString(), {
|
|
1610
|
+
method: "POST",
|
|
1611
|
+
headers: {
|
|
1612
|
+
"Content-Type": "application/json",
|
|
1613
|
+
Authorization: `Bearer ${accessToken}`
|
|
1614
|
+
},
|
|
1615
|
+
body: JSON.stringify({
|
|
1616
|
+
provider: request.provider
|
|
1617
|
+
})
|
|
1618
|
+
});
|
|
1619
|
+
if (!response.ok) {
|
|
1620
|
+
const error = await response.text();
|
|
1621
|
+
throw new Error(`MCP server failed to disconnect provider: ${error}`);
|
|
1622
|
+
}
|
|
1623
|
+
const data = await response.json();
|
|
1624
|
+
return data;
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
// src/adapters/nextjs.ts
|
|
1628
|
+
function createNextOAuthHandler(config) {
|
|
1629
|
+
const handler = new OAuthHandler(config);
|
|
1630
|
+
const handlers = {
|
|
1631
|
+
async authorize(req) {
|
|
1632
|
+
try {
|
|
1633
|
+
const body = await req.json();
|
|
1634
|
+
const result = await handler.handleAuthorize(body);
|
|
1635
|
+
return Response.json(result);
|
|
1636
|
+
} catch (error) {
|
|
1637
|
+
console.error("[OAuth Authorize] Error:", error);
|
|
1638
|
+
return Response.json({ error: error.message || "Failed to get authorization URL" }, { status: 500 });
|
|
1639
|
+
}
|
|
1640
|
+
},
|
|
1641
|
+
async callback(req) {
|
|
1642
|
+
try {
|
|
1643
|
+
const body = await req.json();
|
|
1644
|
+
const result = await handler.handleCallback(body);
|
|
1645
|
+
return Response.json(result);
|
|
1646
|
+
} catch (error) {
|
|
1647
|
+
console.error("[OAuth Callback] Error:", error);
|
|
1648
|
+
return Response.json({ error: error.message || "Failed to exchange authorization code" }, { status: 500 });
|
|
1649
|
+
}
|
|
1650
|
+
},
|
|
1651
|
+
async status(req) {
|
|
1652
|
+
try {
|
|
1653
|
+
const provider = req.nextUrl.searchParams.get("provider");
|
|
1654
|
+
const authHeader = req.headers.get("authorization");
|
|
1655
|
+
if (!provider) {
|
|
1656
|
+
return Response.json({ error: "Missing provider query parameter" }, { status: 400 });
|
|
1657
|
+
}
|
|
1658
|
+
if (!authHeader || !authHeader.startsWith("Bearer ")) {
|
|
1659
|
+
return Response.json({ error: "Missing or invalid Authorization header" }, { status: 400 });
|
|
1660
|
+
}
|
|
1661
|
+
const accessToken = authHeader.substring(7);
|
|
1662
|
+
const result = await handler.handleStatus(provider, accessToken);
|
|
1663
|
+
return Response.json(result);
|
|
1664
|
+
} catch (error) {
|
|
1665
|
+
console.error("[OAuth Status] Error:", error);
|
|
1666
|
+
return Response.json({ error: error.message || "Failed to check authorization status" }, { status: 500 });
|
|
1667
|
+
}
|
|
1668
|
+
},
|
|
1669
|
+
async disconnect(req) {
|
|
1670
|
+
try {
|
|
1671
|
+
const authHeader = req.headers.get("authorization");
|
|
1672
|
+
if (!authHeader || !authHeader.startsWith("Bearer ")) {
|
|
1673
|
+
return Response.json({ error: "Missing or invalid Authorization header" }, { status: 400 });
|
|
1674
|
+
}
|
|
1675
|
+
const accessToken = authHeader.substring(7);
|
|
1676
|
+
const body = await req.json();
|
|
1677
|
+
const { provider } = body;
|
|
1678
|
+
if (!provider) {
|
|
1679
|
+
return Response.json({ error: "Missing provider in request body" }, { status: 400 });
|
|
1680
|
+
}
|
|
1681
|
+
const result = await handler.handleDisconnect({ provider }, accessToken);
|
|
1682
|
+
return Response.json(result);
|
|
1683
|
+
} catch (error) {
|
|
1684
|
+
console.error("[OAuth Disconnect] Error:", error);
|
|
1685
|
+
return Response.json({ error: error.message || "Failed to disconnect provider" }, { status: 500 });
|
|
1686
|
+
}
|
|
1687
|
+
},
|
|
1688
|
+
createRoutes() {
|
|
1689
|
+
return {
|
|
1690
|
+
async POST(req, context) {
|
|
1691
|
+
const params = context.params instanceof Promise ? await context.params : context.params;
|
|
1692
|
+
const action = params.action;
|
|
1693
|
+
if (action === "authorize") {
|
|
1694
|
+
return handlers.authorize(req);
|
|
1695
|
+
}
|
|
1696
|
+
if (action === "callback") {
|
|
1697
|
+
return handlers.callback(req);
|
|
1698
|
+
}
|
|
1699
|
+
if (action === "disconnect") {
|
|
1700
|
+
return handlers.disconnect(req);
|
|
1701
|
+
}
|
|
1702
|
+
return Response.json({ error: `Unknown action: ${action}` }, { status: 404 });
|
|
1703
|
+
},
|
|
1704
|
+
async GET(req, context) {
|
|
1705
|
+
const params = context.params instanceof Promise ? await context.params : context.params;
|
|
1706
|
+
const action = params.action;
|
|
1707
|
+
if (action === "status") {
|
|
1708
|
+
return handlers.status(req);
|
|
1709
|
+
}
|
|
1710
|
+
return Response.json({ error: `Unknown action: ${action}` }, { status: 404 });
|
|
1711
|
+
}
|
|
1712
|
+
};
|
|
1713
|
+
}
|
|
1714
|
+
};
|
|
1715
|
+
return handlers;
|
|
1716
|
+
}
|
|
1741
1717
|
// src/adapters/nextjs-oauth-redirect.ts
|
|
1742
1718
|
function createOAuthRedirectHandler(config) {
|
|
1743
1719
|
const redirectUrl = config?.redirectUrl || "/";
|
package/dist/oauth.js
CHANGED
|
@@ -1,21 +1,4 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
6
|
-
var __toCommonJS = (from) => {
|
|
7
|
-
var entry = __moduleCache.get(from), desc;
|
|
8
|
-
if (entry)
|
|
9
|
-
return entry;
|
|
10
|
-
entry = __defProp({}, "__esModule", { value: true });
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
12
|
-
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
13
|
-
get: () => from[key],
|
|
14
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
-
}));
|
|
16
|
-
__moduleCache.set(from, entry);
|
|
17
|
-
return entry;
|
|
18
|
-
};
|
|
19
2
|
var __export = (target, all) => {
|
|
20
3
|
for (var name in all)
|
|
21
4
|
__defProp(target, name, {
|
|
@@ -28,11 +11,16 @@ var __export = (target, all) => {
|
|
|
28
11
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
29
12
|
|
|
30
13
|
// src/adapters/base-handler.ts
|
|
14
|
+
var MCP_SERVER_URL = "https://mcp.integrate.dev/api/v1/mcp";
|
|
15
|
+
|
|
31
16
|
class OAuthHandler {
|
|
32
17
|
config;
|
|
33
18
|
serverUrl = MCP_SERVER_URL;
|
|
34
19
|
constructor(config) {
|
|
35
20
|
this.config = config;
|
|
21
|
+
if (!config || !config.providers) {
|
|
22
|
+
throw new Error("OAuthHandler requires a valid config with providers");
|
|
23
|
+
}
|
|
36
24
|
}
|
|
37
25
|
async handleAuthorize(request) {
|
|
38
26
|
const providerConfig = this.config.providers[request.provider];
|
|
@@ -138,7 +126,6 @@ class OAuthHandler {
|
|
|
138
126
|
return data;
|
|
139
127
|
}
|
|
140
128
|
}
|
|
141
|
-
var MCP_SERVER_URL = "https://mcp.integrate.dev/api/v1/mcp";
|
|
142
129
|
|
|
143
130
|
// src/adapters/auto-routes.ts
|
|
144
131
|
var globalOAuthConfig = null;
|
package/dist/server.js
CHANGED
|
@@ -1,21 +1,4 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
6
|
-
var __toCommonJS = (from) => {
|
|
7
|
-
var entry = __moduleCache.get(from), desc;
|
|
8
|
-
if (entry)
|
|
9
|
-
return entry;
|
|
10
|
-
entry = __defProp({}, "__esModule", { value: true });
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
12
|
-
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
13
|
-
get: () => from[key],
|
|
14
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
-
}));
|
|
16
|
-
__moduleCache.set(from, entry);
|
|
17
|
-
return entry;
|
|
18
|
-
};
|
|
19
2
|
var __export = (target, all) => {
|
|
20
3
|
for (var name in all)
|
|
21
4
|
__defProp(target, name, {
|
|
@@ -165,215 +148,6 @@ var init_errors = __esm(() => {
|
|
|
165
148
|
};
|
|
166
149
|
});
|
|
167
150
|
|
|
168
|
-
// src/adapters/base-handler.ts
|
|
169
|
-
class OAuthHandler {
|
|
170
|
-
config;
|
|
171
|
-
serverUrl = MCP_SERVER_URL2;
|
|
172
|
-
constructor(config) {
|
|
173
|
-
this.config = config;
|
|
174
|
-
}
|
|
175
|
-
async handleAuthorize(request) {
|
|
176
|
-
const providerConfig = this.config.providers[request.provider];
|
|
177
|
-
if (!providerConfig) {
|
|
178
|
-
throw new Error(`Provider ${request.provider} not configured. Add OAuth credentials to your API route configuration.`);
|
|
179
|
-
}
|
|
180
|
-
if (!providerConfig.clientId || !providerConfig.clientSecret) {
|
|
181
|
-
throw new Error(`Missing OAuth credentials for ${request.provider}. Check your environment variables.`);
|
|
182
|
-
}
|
|
183
|
-
const url = new URL("/oauth/authorize", this.serverUrl);
|
|
184
|
-
url.searchParams.set("provider", request.provider);
|
|
185
|
-
url.searchParams.set("client_id", providerConfig.clientId);
|
|
186
|
-
url.searchParams.set("client_secret", providerConfig.clientSecret);
|
|
187
|
-
url.searchParams.set("scope", request.scopes.join(","));
|
|
188
|
-
url.searchParams.set("state", request.state);
|
|
189
|
-
url.searchParams.set("code_challenge", request.codeChallenge);
|
|
190
|
-
url.searchParams.set("code_challenge_method", request.codeChallengeMethod);
|
|
191
|
-
const redirectUri = request.redirectUri || providerConfig.redirectUri;
|
|
192
|
-
if (redirectUri) {
|
|
193
|
-
url.searchParams.set("redirect_uri", redirectUri);
|
|
194
|
-
}
|
|
195
|
-
const response = await fetch(url.toString(), {
|
|
196
|
-
method: "GET"
|
|
197
|
-
});
|
|
198
|
-
if (!response.ok) {
|
|
199
|
-
const error = await response.text();
|
|
200
|
-
throw new Error(`MCP server failed to generate authorization URL: ${error}`);
|
|
201
|
-
}
|
|
202
|
-
const data = await response.json();
|
|
203
|
-
return data;
|
|
204
|
-
}
|
|
205
|
-
async handleCallback(request) {
|
|
206
|
-
const providerConfig = this.config.providers[request.provider];
|
|
207
|
-
if (!providerConfig) {
|
|
208
|
-
throw new Error(`Provider ${request.provider} not configured. Add OAuth credentials to your API route configuration.`);
|
|
209
|
-
}
|
|
210
|
-
if (!providerConfig.clientId || !providerConfig.clientSecret) {
|
|
211
|
-
throw new Error(`Missing OAuth credentials for ${request.provider}. Check your environment variables.`);
|
|
212
|
-
}
|
|
213
|
-
const url = new URL("/oauth/callback", this.serverUrl);
|
|
214
|
-
const response = await fetch(url.toString(), {
|
|
215
|
-
method: "POST",
|
|
216
|
-
headers: {
|
|
217
|
-
"Content-Type": "application/json"
|
|
218
|
-
},
|
|
219
|
-
body: JSON.stringify({
|
|
220
|
-
provider: request.provider,
|
|
221
|
-
code: request.code,
|
|
222
|
-
code_verifier: request.codeVerifier,
|
|
223
|
-
state: request.state,
|
|
224
|
-
client_id: providerConfig.clientId,
|
|
225
|
-
client_secret: providerConfig.clientSecret
|
|
226
|
-
})
|
|
227
|
-
});
|
|
228
|
-
if (!response.ok) {
|
|
229
|
-
const error = await response.text();
|
|
230
|
-
throw new Error(`MCP server failed to exchange authorization code: ${error}`);
|
|
231
|
-
}
|
|
232
|
-
const data = await response.json();
|
|
233
|
-
return data;
|
|
234
|
-
}
|
|
235
|
-
async handleStatus(provider, accessToken) {
|
|
236
|
-
const url = new URL("/oauth/status", this.serverUrl);
|
|
237
|
-
url.searchParams.set("provider", provider);
|
|
238
|
-
const response = await fetch(url.toString(), {
|
|
239
|
-
method: "GET",
|
|
240
|
-
headers: {
|
|
241
|
-
Authorization: `Bearer ${accessToken}`
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
if (!response.ok) {
|
|
245
|
-
if (response.status === 401) {
|
|
246
|
-
return {
|
|
247
|
-
authorized: false
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
const error = await response.text();
|
|
251
|
-
throw new Error(`MCP server failed to check authorization status: ${error}`);
|
|
252
|
-
}
|
|
253
|
-
const data = await response.json();
|
|
254
|
-
return data;
|
|
255
|
-
}
|
|
256
|
-
async handleDisconnect(request, accessToken) {
|
|
257
|
-
if (!accessToken) {
|
|
258
|
-
throw new Error("No access token provided. Cannot disconnect provider.");
|
|
259
|
-
}
|
|
260
|
-
const url = new URL("/oauth/disconnect", this.serverUrl);
|
|
261
|
-
const response = await fetch(url.toString(), {
|
|
262
|
-
method: "POST",
|
|
263
|
-
headers: {
|
|
264
|
-
"Content-Type": "application/json",
|
|
265
|
-
Authorization: `Bearer ${accessToken}`
|
|
266
|
-
},
|
|
267
|
-
body: JSON.stringify({
|
|
268
|
-
provider: request.provider
|
|
269
|
-
})
|
|
270
|
-
});
|
|
271
|
-
if (!response.ok) {
|
|
272
|
-
const error = await response.text();
|
|
273
|
-
throw new Error(`MCP server failed to disconnect provider: ${error}`);
|
|
274
|
-
}
|
|
275
|
-
const data = await response.json();
|
|
276
|
-
return data;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
var MCP_SERVER_URL2 = "https://mcp.integrate.dev/api/v1/mcp";
|
|
280
|
-
|
|
281
|
-
// src/adapters/nextjs.ts
|
|
282
|
-
var exports_nextjs = {};
|
|
283
|
-
__export(exports_nextjs, {
|
|
284
|
-
createNextOAuthHandler: () => createNextOAuthHandler
|
|
285
|
-
});
|
|
286
|
-
function createNextOAuthHandler(config) {
|
|
287
|
-
const handler = new OAuthHandler(config);
|
|
288
|
-
const handlers = {
|
|
289
|
-
async authorize(req) {
|
|
290
|
-
try {
|
|
291
|
-
const body = await req.json();
|
|
292
|
-
const result = await handler.handleAuthorize(body);
|
|
293
|
-
return Response.json(result);
|
|
294
|
-
} catch (error) {
|
|
295
|
-
console.error("[OAuth Authorize] Error:", error);
|
|
296
|
-
return Response.json({ error: error.message || "Failed to get authorization URL" }, { status: 500 });
|
|
297
|
-
}
|
|
298
|
-
},
|
|
299
|
-
async callback(req) {
|
|
300
|
-
try {
|
|
301
|
-
const body = await req.json();
|
|
302
|
-
const result = await handler.handleCallback(body);
|
|
303
|
-
return Response.json(result);
|
|
304
|
-
} catch (error) {
|
|
305
|
-
console.error("[OAuth Callback] Error:", error);
|
|
306
|
-
return Response.json({ error: error.message || "Failed to exchange authorization code" }, { status: 500 });
|
|
307
|
-
}
|
|
308
|
-
},
|
|
309
|
-
async status(req) {
|
|
310
|
-
try {
|
|
311
|
-
const provider = req.nextUrl.searchParams.get("provider");
|
|
312
|
-
const authHeader = req.headers.get("authorization");
|
|
313
|
-
if (!provider) {
|
|
314
|
-
return Response.json({ error: "Missing provider query parameter" }, { status: 400 });
|
|
315
|
-
}
|
|
316
|
-
if (!authHeader || !authHeader.startsWith("Bearer ")) {
|
|
317
|
-
return Response.json({ error: "Missing or invalid Authorization header" }, { status: 400 });
|
|
318
|
-
}
|
|
319
|
-
const accessToken = authHeader.substring(7);
|
|
320
|
-
const result = await handler.handleStatus(provider, accessToken);
|
|
321
|
-
return Response.json(result);
|
|
322
|
-
} catch (error) {
|
|
323
|
-
console.error("[OAuth Status] Error:", error);
|
|
324
|
-
return Response.json({ error: error.message || "Failed to check authorization status" }, { status: 500 });
|
|
325
|
-
}
|
|
326
|
-
},
|
|
327
|
-
async disconnect(req) {
|
|
328
|
-
try {
|
|
329
|
-
const authHeader = req.headers.get("authorization");
|
|
330
|
-
if (!authHeader || !authHeader.startsWith("Bearer ")) {
|
|
331
|
-
return Response.json({ error: "Missing or invalid Authorization header" }, { status: 400 });
|
|
332
|
-
}
|
|
333
|
-
const accessToken = authHeader.substring(7);
|
|
334
|
-
const body = await req.json();
|
|
335
|
-
const { provider } = body;
|
|
336
|
-
if (!provider) {
|
|
337
|
-
return Response.json({ error: "Missing provider in request body" }, { status: 400 });
|
|
338
|
-
}
|
|
339
|
-
const result = await handler.handleDisconnect({ provider }, accessToken);
|
|
340
|
-
return Response.json(result);
|
|
341
|
-
} catch (error) {
|
|
342
|
-
console.error("[OAuth Disconnect] Error:", error);
|
|
343
|
-
return Response.json({ error: error.message || "Failed to disconnect provider" }, { status: 500 });
|
|
344
|
-
}
|
|
345
|
-
},
|
|
346
|
-
createRoutes() {
|
|
347
|
-
return {
|
|
348
|
-
async POST(req, context) {
|
|
349
|
-
const params = context.params instanceof Promise ? await context.params : context.params;
|
|
350
|
-
const action = params.action;
|
|
351
|
-
if (action === "authorize") {
|
|
352
|
-
return handlers.authorize(req);
|
|
353
|
-
}
|
|
354
|
-
if (action === "callback") {
|
|
355
|
-
return handlers.callback(req);
|
|
356
|
-
}
|
|
357
|
-
if (action === "disconnect") {
|
|
358
|
-
return handlers.disconnect(req);
|
|
359
|
-
}
|
|
360
|
-
return Response.json({ error: `Unknown action: ${action}` }, { status: 404 });
|
|
361
|
-
},
|
|
362
|
-
async GET(req, context) {
|
|
363
|
-
const params = context.params instanceof Promise ? await context.params : context.params;
|
|
364
|
-
const action = params.action;
|
|
365
|
-
if (action === "status") {
|
|
366
|
-
return handlers.status(req);
|
|
367
|
-
}
|
|
368
|
-
return Response.json({ error: `Unknown action: ${action}` }, { status: 404 });
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
};
|
|
373
|
-
return handlers;
|
|
374
|
-
}
|
|
375
|
-
var init_nextjs = () => {};
|
|
376
|
-
|
|
377
151
|
// src/protocol/jsonrpc.ts
|
|
378
152
|
function parseMessage(message) {
|
|
379
153
|
try {
|
|
@@ -1735,6 +1509,214 @@ async function clearClientCache() {
|
|
|
1735
1509
|
}));
|
|
1736
1510
|
}
|
|
1737
1511
|
|
|
1512
|
+
// src/adapters/base-handler.ts
|
|
1513
|
+
var MCP_SERVER_URL2 = "https://mcp.integrate.dev/api/v1/mcp";
|
|
1514
|
+
|
|
1515
|
+
class OAuthHandler {
|
|
1516
|
+
config;
|
|
1517
|
+
serverUrl = MCP_SERVER_URL2;
|
|
1518
|
+
constructor(config) {
|
|
1519
|
+
this.config = config;
|
|
1520
|
+
if (!config || !config.providers) {
|
|
1521
|
+
throw new Error("OAuthHandler requires a valid config with providers");
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
async handleAuthorize(request) {
|
|
1525
|
+
const providerConfig = this.config.providers[request.provider];
|
|
1526
|
+
if (!providerConfig) {
|
|
1527
|
+
throw new Error(`Provider ${request.provider} not configured. Add OAuth credentials to your API route configuration.`);
|
|
1528
|
+
}
|
|
1529
|
+
if (!providerConfig.clientId || !providerConfig.clientSecret) {
|
|
1530
|
+
throw new Error(`Missing OAuth credentials for ${request.provider}. Check your environment variables.`);
|
|
1531
|
+
}
|
|
1532
|
+
const url = new URL("/oauth/authorize", this.serverUrl);
|
|
1533
|
+
url.searchParams.set("provider", request.provider);
|
|
1534
|
+
url.searchParams.set("client_id", providerConfig.clientId);
|
|
1535
|
+
url.searchParams.set("client_secret", providerConfig.clientSecret);
|
|
1536
|
+
url.searchParams.set("scope", request.scopes.join(","));
|
|
1537
|
+
url.searchParams.set("state", request.state);
|
|
1538
|
+
url.searchParams.set("code_challenge", request.codeChallenge);
|
|
1539
|
+
url.searchParams.set("code_challenge_method", request.codeChallengeMethod);
|
|
1540
|
+
const redirectUri = request.redirectUri || providerConfig.redirectUri;
|
|
1541
|
+
if (redirectUri) {
|
|
1542
|
+
url.searchParams.set("redirect_uri", redirectUri);
|
|
1543
|
+
}
|
|
1544
|
+
const response = await fetch(url.toString(), {
|
|
1545
|
+
method: "GET"
|
|
1546
|
+
});
|
|
1547
|
+
if (!response.ok) {
|
|
1548
|
+
const error = await response.text();
|
|
1549
|
+
throw new Error(`MCP server failed to generate authorization URL: ${error}`);
|
|
1550
|
+
}
|
|
1551
|
+
const data = await response.json();
|
|
1552
|
+
return data;
|
|
1553
|
+
}
|
|
1554
|
+
async handleCallback(request) {
|
|
1555
|
+
const providerConfig = this.config.providers[request.provider];
|
|
1556
|
+
if (!providerConfig) {
|
|
1557
|
+
throw new Error(`Provider ${request.provider} not configured. Add OAuth credentials to your API route configuration.`);
|
|
1558
|
+
}
|
|
1559
|
+
if (!providerConfig.clientId || !providerConfig.clientSecret) {
|
|
1560
|
+
throw new Error(`Missing OAuth credentials for ${request.provider}. Check your environment variables.`);
|
|
1561
|
+
}
|
|
1562
|
+
const url = new URL("/oauth/callback", this.serverUrl);
|
|
1563
|
+
const response = await fetch(url.toString(), {
|
|
1564
|
+
method: "POST",
|
|
1565
|
+
headers: {
|
|
1566
|
+
"Content-Type": "application/json"
|
|
1567
|
+
},
|
|
1568
|
+
body: JSON.stringify({
|
|
1569
|
+
provider: request.provider,
|
|
1570
|
+
code: request.code,
|
|
1571
|
+
code_verifier: request.codeVerifier,
|
|
1572
|
+
state: request.state,
|
|
1573
|
+
client_id: providerConfig.clientId,
|
|
1574
|
+
client_secret: providerConfig.clientSecret
|
|
1575
|
+
})
|
|
1576
|
+
});
|
|
1577
|
+
if (!response.ok) {
|
|
1578
|
+
const error = await response.text();
|
|
1579
|
+
throw new Error(`MCP server failed to exchange authorization code: ${error}`);
|
|
1580
|
+
}
|
|
1581
|
+
const data = await response.json();
|
|
1582
|
+
return data;
|
|
1583
|
+
}
|
|
1584
|
+
async handleStatus(provider, accessToken) {
|
|
1585
|
+
const url = new URL("/oauth/status", this.serverUrl);
|
|
1586
|
+
url.searchParams.set("provider", provider);
|
|
1587
|
+
const response = await fetch(url.toString(), {
|
|
1588
|
+
method: "GET",
|
|
1589
|
+
headers: {
|
|
1590
|
+
Authorization: `Bearer ${accessToken}`
|
|
1591
|
+
}
|
|
1592
|
+
});
|
|
1593
|
+
if (!response.ok) {
|
|
1594
|
+
if (response.status === 401) {
|
|
1595
|
+
return {
|
|
1596
|
+
authorized: false
|
|
1597
|
+
};
|
|
1598
|
+
}
|
|
1599
|
+
const error = await response.text();
|
|
1600
|
+
throw new Error(`MCP server failed to check authorization status: ${error}`);
|
|
1601
|
+
}
|
|
1602
|
+
const data = await response.json();
|
|
1603
|
+
return data;
|
|
1604
|
+
}
|
|
1605
|
+
async handleDisconnect(request, accessToken) {
|
|
1606
|
+
if (!accessToken) {
|
|
1607
|
+
throw new Error("No access token provided. Cannot disconnect provider.");
|
|
1608
|
+
}
|
|
1609
|
+
const url = new URL("/oauth/disconnect", this.serverUrl);
|
|
1610
|
+
const response = await fetch(url.toString(), {
|
|
1611
|
+
method: "POST",
|
|
1612
|
+
headers: {
|
|
1613
|
+
"Content-Type": "application/json",
|
|
1614
|
+
Authorization: `Bearer ${accessToken}`
|
|
1615
|
+
},
|
|
1616
|
+
body: JSON.stringify({
|
|
1617
|
+
provider: request.provider
|
|
1618
|
+
})
|
|
1619
|
+
});
|
|
1620
|
+
if (!response.ok) {
|
|
1621
|
+
const error = await response.text();
|
|
1622
|
+
throw new Error(`MCP server failed to disconnect provider: ${error}`);
|
|
1623
|
+
}
|
|
1624
|
+
const data = await response.json();
|
|
1625
|
+
return data;
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
|
|
1629
|
+
// src/adapters/nextjs.ts
|
|
1630
|
+
function createNextOAuthHandler(config) {
|
|
1631
|
+
const handler = new OAuthHandler(config);
|
|
1632
|
+
const handlers = {
|
|
1633
|
+
async authorize(req) {
|
|
1634
|
+
try {
|
|
1635
|
+
const body = await req.json();
|
|
1636
|
+
const result = await handler.handleAuthorize(body);
|
|
1637
|
+
return Response.json(result);
|
|
1638
|
+
} catch (error) {
|
|
1639
|
+
console.error("[OAuth Authorize] Error:", error);
|
|
1640
|
+
return Response.json({ error: error.message || "Failed to get authorization URL" }, { status: 500 });
|
|
1641
|
+
}
|
|
1642
|
+
},
|
|
1643
|
+
async callback(req) {
|
|
1644
|
+
try {
|
|
1645
|
+
const body = await req.json();
|
|
1646
|
+
const result = await handler.handleCallback(body);
|
|
1647
|
+
return Response.json(result);
|
|
1648
|
+
} catch (error) {
|
|
1649
|
+
console.error("[OAuth Callback] Error:", error);
|
|
1650
|
+
return Response.json({ error: error.message || "Failed to exchange authorization code" }, { status: 500 });
|
|
1651
|
+
}
|
|
1652
|
+
},
|
|
1653
|
+
async status(req) {
|
|
1654
|
+
try {
|
|
1655
|
+
const provider = req.nextUrl.searchParams.get("provider");
|
|
1656
|
+
const authHeader = req.headers.get("authorization");
|
|
1657
|
+
if (!provider) {
|
|
1658
|
+
return Response.json({ error: "Missing provider query parameter" }, { status: 400 });
|
|
1659
|
+
}
|
|
1660
|
+
if (!authHeader || !authHeader.startsWith("Bearer ")) {
|
|
1661
|
+
return Response.json({ error: "Missing or invalid Authorization header" }, { status: 400 });
|
|
1662
|
+
}
|
|
1663
|
+
const accessToken = authHeader.substring(7);
|
|
1664
|
+
const result = await handler.handleStatus(provider, accessToken);
|
|
1665
|
+
return Response.json(result);
|
|
1666
|
+
} catch (error) {
|
|
1667
|
+
console.error("[OAuth Status] Error:", error);
|
|
1668
|
+
return Response.json({ error: error.message || "Failed to check authorization status" }, { status: 500 });
|
|
1669
|
+
}
|
|
1670
|
+
},
|
|
1671
|
+
async disconnect(req) {
|
|
1672
|
+
try {
|
|
1673
|
+
const authHeader = req.headers.get("authorization");
|
|
1674
|
+
if (!authHeader || !authHeader.startsWith("Bearer ")) {
|
|
1675
|
+
return Response.json({ error: "Missing or invalid Authorization header" }, { status: 400 });
|
|
1676
|
+
}
|
|
1677
|
+
const accessToken = authHeader.substring(7);
|
|
1678
|
+
const body = await req.json();
|
|
1679
|
+
const { provider } = body;
|
|
1680
|
+
if (!provider) {
|
|
1681
|
+
return Response.json({ error: "Missing provider in request body" }, { status: 400 });
|
|
1682
|
+
}
|
|
1683
|
+
const result = await handler.handleDisconnect({ provider }, accessToken);
|
|
1684
|
+
return Response.json(result);
|
|
1685
|
+
} catch (error) {
|
|
1686
|
+
console.error("[OAuth Disconnect] Error:", error);
|
|
1687
|
+
return Response.json({ error: error.message || "Failed to disconnect provider" }, { status: 500 });
|
|
1688
|
+
}
|
|
1689
|
+
},
|
|
1690
|
+
createRoutes() {
|
|
1691
|
+
return {
|
|
1692
|
+
async POST(req, context) {
|
|
1693
|
+
const params = context.params instanceof Promise ? await context.params : context.params;
|
|
1694
|
+
const action = params.action;
|
|
1695
|
+
if (action === "authorize") {
|
|
1696
|
+
return handlers.authorize(req);
|
|
1697
|
+
}
|
|
1698
|
+
if (action === "callback") {
|
|
1699
|
+
return handlers.callback(req);
|
|
1700
|
+
}
|
|
1701
|
+
if (action === "disconnect") {
|
|
1702
|
+
return handlers.disconnect(req);
|
|
1703
|
+
}
|
|
1704
|
+
return Response.json({ error: `Unknown action: ${action}` }, { status: 404 });
|
|
1705
|
+
},
|
|
1706
|
+
async GET(req, context) {
|
|
1707
|
+
const params = context.params instanceof Promise ? await context.params : context.params;
|
|
1708
|
+
const action = params.action;
|
|
1709
|
+
if (action === "status") {
|
|
1710
|
+
return handlers.status(req);
|
|
1711
|
+
}
|
|
1712
|
+
return Response.json({ error: `Unknown action: ${action}` }, { status: 404 });
|
|
1713
|
+
}
|
|
1714
|
+
};
|
|
1715
|
+
}
|
|
1716
|
+
};
|
|
1717
|
+
return handlers;
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1738
1720
|
// src/plugins/github.ts
|
|
1739
1721
|
var GITHUB_TOOLS = [
|
|
1740
1722
|
"github_create_issue",
|
|
@@ -1871,8 +1853,7 @@ function createMCPServer(config) {
|
|
|
1871
1853
|
};
|
|
1872
1854
|
}
|
|
1873
1855
|
function createOAuthRouteHandlers(config) {
|
|
1874
|
-
const
|
|
1875
|
-
const handler = createNextOAuthHandler2(config);
|
|
1856
|
+
const handler = createNextOAuthHandler(config);
|
|
1876
1857
|
return handler.createRoutes();
|
|
1877
1858
|
}
|
|
1878
1859
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-handler.d.ts","sourceRoot":"","sources":["../../../src/adapters/base-handler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,uCAAuC;IACvC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE;QACxB,iDAAiD;QACjD,QAAQ,EAAE,MAAM,CAAC;QACjB,qDAAqD;QACrD,YAAY,EAAE,MAAM,CAAC;QACrB,qCAAqC;QACrC,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,qBAAa,YAAY;IAGX,OAAO,CAAC,MAAM;IAF1B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAkB;gBAExB,MAAM,EAAE,kBAAkB;
|
|
1
|
+
{"version":3,"file":"base-handler.d.ts","sourceRoot":"","sources":["../../../src/adapters/base-handler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,uCAAuC;IACvC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE;QACxB,iDAAiD;QACjD,QAAQ,EAAE,MAAM,CAAC;QACjB,qDAAqD;QACrD,YAAY,EAAE,MAAM,CAAC;QACrB,qCAAqC;QACrC,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,qBAAa,YAAY;IAGX,OAAO,CAAC,MAAM;IAF1B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAkB;gBAExB,MAAM,EAAE,kBAAkB;IAO9C;;;;;;;;;OASG;IACG,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IA0C5E;;;;;;;;;OASG;IACG,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA0CzE;;;;;;;;;OASG;IACG,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IA4BlF;;;;;;;;;;OAUG;IACG,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;CA2BrG"}
|
package/dist/src/server.d.ts
CHANGED
|
@@ -42,9 +42,21 @@ export declare function createMCPServer<TPlugins extends readonly MCPPlugin[]>(c
|
|
|
42
42
|
/** Server-side MCP client instance */
|
|
43
43
|
client: MCPClient<TPlugins>;
|
|
44
44
|
/** OAuth POST handler - export this from your route file */
|
|
45
|
-
POST: any
|
|
45
|
+
POST: (req: any, context: {
|
|
46
|
+
params: {
|
|
47
|
+
action: string;
|
|
48
|
+
} | Promise<{
|
|
49
|
+
action: string;
|
|
50
|
+
}>;
|
|
51
|
+
}) => Promise<any>;
|
|
46
52
|
/** OAuth GET handler - export this from your route file */
|
|
47
|
-
GET: any
|
|
53
|
+
GET: (req: any, context: {
|
|
54
|
+
params: {
|
|
55
|
+
action: string;
|
|
56
|
+
} | Promise<{
|
|
57
|
+
action: string;
|
|
58
|
+
}>;
|
|
59
|
+
}) => Promise<any>;
|
|
48
60
|
};
|
|
49
61
|
export type { MCPPlugin } from './plugins/types.js';
|
|
50
62
|
export type { MCPClientConfig } from './config/types.js';
|
package/dist/src/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAGpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,eAAe,CAAC,QAAQ,SAAS,SAAS,SAAS,EAAE,EACnE,MAAM,EAAE,eAAe,CAAC,QAAQ,CAAC;IA4C/B,sCAAsC;;IAGtC,4DAA4D;;;;;;;;IAG5D,2DAA2D;;;;;;;;EAG9D;AAYD,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,YAAY,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGzD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "integrate-sdk",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "Type-safe TypeScript SDK for MCP Client with plugin-based OAuth provider configuration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -43,8 +43,7 @@
|
|
|
43
43
|
"test:watch": "bun test --watch tests/",
|
|
44
44
|
"test:unit": "bun test tests/protocol tests/plugins tests/client tests/integrations tests/oauth tests/transport tests/utils tests/errors",
|
|
45
45
|
"test:integration": "bun test tests/integration/simple-integration.test.ts",
|
|
46
|
-
"test:coverage": "bun test --coverage tests/"
|
|
47
|
-
"prepare": "simple-git-hooks"
|
|
46
|
+
"test:coverage": "bun test --coverage tests/"
|
|
48
47
|
},
|
|
49
48
|
"keywords": [
|
|
50
49
|
"mcp",
|