integrate-sdk 0.7.28 → 0.7.29
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/adapters/index.js +13 -5
- package/dist/adapters/solid-start.js +13 -5
- package/dist/adapters/svelte-kit.js +13 -5
- package/dist/index.d.ts +42 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -5
- package/dist/server.js +13 -5
- package/dist/src/client.d.ts +2 -0
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/config/types.d.ts +38 -3
- package/dist/src/config/types.d.ts.map +1 -1
- package/dist/src/oauth/manager.d.ts +2 -1
- package/dist/src/oauth/manager.d.ts.map +1 -1
- package/index.ts +53 -6
- package/package.json +1 -1
package/dist/adapters/index.js
CHANGED
|
@@ -1113,8 +1113,10 @@ class OAuthManager {
|
|
|
1113
1113
|
windowManager;
|
|
1114
1114
|
flowConfig;
|
|
1115
1115
|
oauthApiBase;
|
|
1116
|
-
|
|
1116
|
+
apiBaseUrl;
|
|
1117
|
+
constructor(oauthApiBase, flowConfig, apiBaseUrl) {
|
|
1117
1118
|
this.oauthApiBase = oauthApiBase;
|
|
1119
|
+
this.apiBaseUrl = apiBaseUrl;
|
|
1118
1120
|
this.windowManager = new OAuthWindowManager;
|
|
1119
1121
|
this.flowConfig = {
|
|
1120
1122
|
mode: flowConfig?.mode || "redirect",
|
|
@@ -1365,7 +1367,7 @@ class OAuthManager {
|
|
|
1365
1367
|
}
|
|
1366
1368
|
}
|
|
1367
1369
|
async getAuthorizationUrl(provider, scopes, state, codeChallenge, redirectUri) {
|
|
1368
|
-
const url = `${this.oauthApiBase}/authorize`;
|
|
1370
|
+
const url = this.apiBaseUrl ? `${this.apiBaseUrl}${this.oauthApiBase}/authorize` : `${this.oauthApiBase}/authorize`;
|
|
1369
1371
|
const response = await fetch(url, {
|
|
1370
1372
|
method: "POST",
|
|
1371
1373
|
headers: {
|
|
@@ -1388,7 +1390,7 @@ class OAuthManager {
|
|
|
1388
1390
|
return data.authorizationUrl;
|
|
1389
1391
|
}
|
|
1390
1392
|
async exchangeCodeForToken(provider, code, codeVerifier, state) {
|
|
1391
|
-
const url = `${this.oauthApiBase}/callback`;
|
|
1393
|
+
const url = this.apiBaseUrl ? `${this.apiBaseUrl}${this.oauthApiBase}/callback` : `${this.oauthApiBase}/callback`;
|
|
1392
1394
|
const response = await fetch(url, {
|
|
1393
1395
|
method: "POST",
|
|
1394
1396
|
headers: {
|
|
@@ -1464,6 +1466,7 @@ class MCPClient {
|
|
|
1464
1466
|
oauthManager;
|
|
1465
1467
|
eventEmitter = new SimpleEventEmitter;
|
|
1466
1468
|
apiRouteBase;
|
|
1469
|
+
apiBaseUrl;
|
|
1467
1470
|
github;
|
|
1468
1471
|
gmail;
|
|
1469
1472
|
server;
|
|
@@ -1476,6 +1479,7 @@ class MCPClient {
|
|
|
1476
1479
|
const oauthApiBase = config.oauthApiBase || "/api/integrate/oauth";
|
|
1477
1480
|
const defaultRedirectUri = this.getDefaultRedirectUri(oauthApiBase);
|
|
1478
1481
|
this.apiRouteBase = config.apiRouteBase || "/api/integrate";
|
|
1482
|
+
this.apiBaseUrl = config.apiBaseUrl;
|
|
1479
1483
|
this.integrations = config.integrations.map((integration) => {
|
|
1480
1484
|
if (integration.oauth && !integration.oauth.redirectUri) {
|
|
1481
1485
|
return {
|
|
@@ -1494,7 +1498,7 @@ class MCPClient {
|
|
|
1494
1498
|
};
|
|
1495
1499
|
this.onReauthRequired = config.onReauthRequired;
|
|
1496
1500
|
this.maxReauthRetries = config.maxReauthRetries ?? 1;
|
|
1497
|
-
this.oauthManager = new OAuthManager(oauthApiBase, config.oauthFlow);
|
|
1501
|
+
this.oauthManager = new OAuthManager(oauthApiBase, config.oauthFlow, this.apiBaseUrl);
|
|
1498
1502
|
const providers = this.integrations.filter((p) => p.oauth).map((p) => p.oauth.provider);
|
|
1499
1503
|
this.oauthManager.loadAllProviderTokens(providers);
|
|
1500
1504
|
for (const integration of this.integrations) {
|
|
@@ -1520,6 +1524,10 @@ class MCPClient {
|
|
|
1520
1524
|
return `${origin}${normalizedPath}/callback`;
|
|
1521
1525
|
}
|
|
1522
1526
|
createIntegrationProxy(integrationId) {
|
|
1527
|
+
const hasIntegration = this.integrations.some((integration) => integration.id === integrationId);
|
|
1528
|
+
if (!hasIntegration) {
|
|
1529
|
+
return;
|
|
1530
|
+
}
|
|
1523
1531
|
return new Proxy({}, {
|
|
1524
1532
|
get: (_target, methodName) => {
|
|
1525
1533
|
return async (args) => {
|
|
@@ -1633,7 +1641,7 @@ class MCPClient {
|
|
|
1633
1641
|
});
|
|
1634
1642
|
return result2;
|
|
1635
1643
|
}
|
|
1636
|
-
const url = `${this.apiRouteBase}/mcp`;
|
|
1644
|
+
const url = this.apiBaseUrl ? `${this.apiBaseUrl}${this.apiRouteBase}/mcp` : `${this.apiRouteBase}/mcp`;
|
|
1637
1645
|
const headers = {
|
|
1638
1646
|
"Content-Type": "application/json"
|
|
1639
1647
|
};
|
|
@@ -978,8 +978,10 @@ class OAuthManager {
|
|
|
978
978
|
windowManager;
|
|
979
979
|
flowConfig;
|
|
980
980
|
oauthApiBase;
|
|
981
|
-
|
|
981
|
+
apiBaseUrl;
|
|
982
|
+
constructor(oauthApiBase, flowConfig, apiBaseUrl) {
|
|
982
983
|
this.oauthApiBase = oauthApiBase;
|
|
984
|
+
this.apiBaseUrl = apiBaseUrl;
|
|
983
985
|
this.windowManager = new OAuthWindowManager;
|
|
984
986
|
this.flowConfig = {
|
|
985
987
|
mode: flowConfig?.mode || "redirect",
|
|
@@ -1230,7 +1232,7 @@ class OAuthManager {
|
|
|
1230
1232
|
}
|
|
1231
1233
|
}
|
|
1232
1234
|
async getAuthorizationUrl(provider, scopes, state, codeChallenge, redirectUri) {
|
|
1233
|
-
const url = `${this.oauthApiBase}/authorize`;
|
|
1235
|
+
const url = this.apiBaseUrl ? `${this.apiBaseUrl}${this.oauthApiBase}/authorize` : `${this.oauthApiBase}/authorize`;
|
|
1234
1236
|
const response = await fetch(url, {
|
|
1235
1237
|
method: "POST",
|
|
1236
1238
|
headers: {
|
|
@@ -1253,7 +1255,7 @@ class OAuthManager {
|
|
|
1253
1255
|
return data.authorizationUrl;
|
|
1254
1256
|
}
|
|
1255
1257
|
async exchangeCodeForToken(provider, code, codeVerifier, state) {
|
|
1256
|
-
const url = `${this.oauthApiBase}/callback`;
|
|
1258
|
+
const url = this.apiBaseUrl ? `${this.apiBaseUrl}${this.oauthApiBase}/callback` : `${this.oauthApiBase}/callback`;
|
|
1257
1259
|
const response = await fetch(url, {
|
|
1258
1260
|
method: "POST",
|
|
1259
1261
|
headers: {
|
|
@@ -1329,6 +1331,7 @@ class MCPClient {
|
|
|
1329
1331
|
oauthManager;
|
|
1330
1332
|
eventEmitter = new SimpleEventEmitter;
|
|
1331
1333
|
apiRouteBase;
|
|
1334
|
+
apiBaseUrl;
|
|
1332
1335
|
github;
|
|
1333
1336
|
gmail;
|
|
1334
1337
|
server;
|
|
@@ -1341,6 +1344,7 @@ class MCPClient {
|
|
|
1341
1344
|
const oauthApiBase = config.oauthApiBase || "/api/integrate/oauth";
|
|
1342
1345
|
const defaultRedirectUri = this.getDefaultRedirectUri(oauthApiBase);
|
|
1343
1346
|
this.apiRouteBase = config.apiRouteBase || "/api/integrate";
|
|
1347
|
+
this.apiBaseUrl = config.apiBaseUrl;
|
|
1344
1348
|
this.integrations = config.integrations.map((integration) => {
|
|
1345
1349
|
if (integration.oauth && !integration.oauth.redirectUri) {
|
|
1346
1350
|
return {
|
|
@@ -1359,7 +1363,7 @@ class MCPClient {
|
|
|
1359
1363
|
};
|
|
1360
1364
|
this.onReauthRequired = config.onReauthRequired;
|
|
1361
1365
|
this.maxReauthRetries = config.maxReauthRetries ?? 1;
|
|
1362
|
-
this.oauthManager = new OAuthManager(oauthApiBase, config.oauthFlow);
|
|
1366
|
+
this.oauthManager = new OAuthManager(oauthApiBase, config.oauthFlow, this.apiBaseUrl);
|
|
1363
1367
|
const providers = this.integrations.filter((p) => p.oauth).map((p) => p.oauth.provider);
|
|
1364
1368
|
this.oauthManager.loadAllProviderTokens(providers);
|
|
1365
1369
|
for (const integration of this.integrations) {
|
|
@@ -1385,6 +1389,10 @@ class MCPClient {
|
|
|
1385
1389
|
return `${origin}${normalizedPath}/callback`;
|
|
1386
1390
|
}
|
|
1387
1391
|
createIntegrationProxy(integrationId) {
|
|
1392
|
+
const hasIntegration = this.integrations.some((integration) => integration.id === integrationId);
|
|
1393
|
+
if (!hasIntegration) {
|
|
1394
|
+
return;
|
|
1395
|
+
}
|
|
1388
1396
|
return new Proxy({}, {
|
|
1389
1397
|
get: (_target, methodName) => {
|
|
1390
1398
|
return async (args) => {
|
|
@@ -1498,7 +1506,7 @@ class MCPClient {
|
|
|
1498
1506
|
});
|
|
1499
1507
|
return result2;
|
|
1500
1508
|
}
|
|
1501
|
-
const url = `${this.apiRouteBase}/mcp`;
|
|
1509
|
+
const url = this.apiBaseUrl ? `${this.apiBaseUrl}${this.apiRouteBase}/mcp` : `${this.apiRouteBase}/mcp`;
|
|
1502
1510
|
const headers = {
|
|
1503
1511
|
"Content-Type": "application/json"
|
|
1504
1512
|
};
|
|
@@ -978,8 +978,10 @@ class OAuthManager {
|
|
|
978
978
|
windowManager;
|
|
979
979
|
flowConfig;
|
|
980
980
|
oauthApiBase;
|
|
981
|
-
|
|
981
|
+
apiBaseUrl;
|
|
982
|
+
constructor(oauthApiBase, flowConfig, apiBaseUrl) {
|
|
982
983
|
this.oauthApiBase = oauthApiBase;
|
|
984
|
+
this.apiBaseUrl = apiBaseUrl;
|
|
983
985
|
this.windowManager = new OAuthWindowManager;
|
|
984
986
|
this.flowConfig = {
|
|
985
987
|
mode: flowConfig?.mode || "redirect",
|
|
@@ -1230,7 +1232,7 @@ class OAuthManager {
|
|
|
1230
1232
|
}
|
|
1231
1233
|
}
|
|
1232
1234
|
async getAuthorizationUrl(provider, scopes, state, codeChallenge, redirectUri) {
|
|
1233
|
-
const url = `${this.oauthApiBase}/authorize`;
|
|
1235
|
+
const url = this.apiBaseUrl ? `${this.apiBaseUrl}${this.oauthApiBase}/authorize` : `${this.oauthApiBase}/authorize`;
|
|
1234
1236
|
const response = await fetch(url, {
|
|
1235
1237
|
method: "POST",
|
|
1236
1238
|
headers: {
|
|
@@ -1253,7 +1255,7 @@ class OAuthManager {
|
|
|
1253
1255
|
return data.authorizationUrl;
|
|
1254
1256
|
}
|
|
1255
1257
|
async exchangeCodeForToken(provider, code, codeVerifier, state) {
|
|
1256
|
-
const url = `${this.oauthApiBase}/callback`;
|
|
1258
|
+
const url = this.apiBaseUrl ? `${this.apiBaseUrl}${this.oauthApiBase}/callback` : `${this.oauthApiBase}/callback`;
|
|
1257
1259
|
const response = await fetch(url, {
|
|
1258
1260
|
method: "POST",
|
|
1259
1261
|
headers: {
|
|
@@ -1329,6 +1331,7 @@ class MCPClient {
|
|
|
1329
1331
|
oauthManager;
|
|
1330
1332
|
eventEmitter = new SimpleEventEmitter;
|
|
1331
1333
|
apiRouteBase;
|
|
1334
|
+
apiBaseUrl;
|
|
1332
1335
|
github;
|
|
1333
1336
|
gmail;
|
|
1334
1337
|
server;
|
|
@@ -1341,6 +1344,7 @@ class MCPClient {
|
|
|
1341
1344
|
const oauthApiBase = config.oauthApiBase || "/api/integrate/oauth";
|
|
1342
1345
|
const defaultRedirectUri = this.getDefaultRedirectUri(oauthApiBase);
|
|
1343
1346
|
this.apiRouteBase = config.apiRouteBase || "/api/integrate";
|
|
1347
|
+
this.apiBaseUrl = config.apiBaseUrl;
|
|
1344
1348
|
this.integrations = config.integrations.map((integration) => {
|
|
1345
1349
|
if (integration.oauth && !integration.oauth.redirectUri) {
|
|
1346
1350
|
return {
|
|
@@ -1359,7 +1363,7 @@ class MCPClient {
|
|
|
1359
1363
|
};
|
|
1360
1364
|
this.onReauthRequired = config.onReauthRequired;
|
|
1361
1365
|
this.maxReauthRetries = config.maxReauthRetries ?? 1;
|
|
1362
|
-
this.oauthManager = new OAuthManager(oauthApiBase, config.oauthFlow);
|
|
1366
|
+
this.oauthManager = new OAuthManager(oauthApiBase, config.oauthFlow, this.apiBaseUrl);
|
|
1363
1367
|
const providers = this.integrations.filter((p) => p.oauth).map((p) => p.oauth.provider);
|
|
1364
1368
|
this.oauthManager.loadAllProviderTokens(providers);
|
|
1365
1369
|
for (const integration of this.integrations) {
|
|
@@ -1385,6 +1389,10 @@ class MCPClient {
|
|
|
1385
1389
|
return `${origin}${normalizedPath}/callback`;
|
|
1386
1390
|
}
|
|
1387
1391
|
createIntegrationProxy(integrationId) {
|
|
1392
|
+
const hasIntegration = this.integrations.some((integration) => integration.id === integrationId);
|
|
1393
|
+
if (!hasIntegration) {
|
|
1394
|
+
return;
|
|
1395
|
+
}
|
|
1388
1396
|
return new Proxy({}, {
|
|
1389
1397
|
get: (_target, methodName) => {
|
|
1390
1398
|
return async (args) => {
|
|
@@ -1498,7 +1506,7 @@ class MCPClient {
|
|
|
1498
1506
|
});
|
|
1499
1507
|
return result2;
|
|
1500
1508
|
}
|
|
1501
|
-
const url = `${this.apiRouteBase}/mcp`;
|
|
1509
|
+
const url = this.apiBaseUrl ? `${this.apiBaseUrl}${this.apiRouteBase}/mcp` : `${this.apiRouteBase}/mcp`;
|
|
1502
1510
|
const headers = {
|
|
1503
1511
|
"Content-Type": "application/json"
|
|
1504
1512
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -5,16 +5,52 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
7
|
* ```typescript
|
|
8
|
+
* // Use the default client with all integrations
|
|
9
|
+
* import { client } from 'integrate-sdk';
|
|
10
|
+
*
|
|
11
|
+
* await client.github.listOwnRepos({});
|
|
12
|
+
*
|
|
13
|
+
* // Or create a custom client with different API configuration
|
|
8
14
|
* import { createMCPClient, githubIntegration } from 'integrate-sdk';
|
|
9
15
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
+
* // Example 1: Different API path (same origin)
|
|
17
|
+
* const customClient = createMCPClient({
|
|
18
|
+
* apiRouteBase: '/custom/api/path', // Calls /custom/api/path/mcp
|
|
19
|
+
* integrations: [githubIntegration()],
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // Example 2: Different API domain (cross-origin)
|
|
23
|
+
* const crossOriginClient = createMCPClient({
|
|
24
|
+
* apiBaseUrl: 'https://api.example.com', // API on different domain
|
|
25
|
+
* apiRouteBase: '/api/integrate', // Calls https://api.example.com/api/integrate/mcp
|
|
26
|
+
* integrations: [githubIntegration()],
|
|
16
27
|
* });
|
|
17
28
|
* ```
|
|
18
29
|
*/
|
|
19
30
|
export * from './src/index.js';
|
|
31
|
+
/**
|
|
32
|
+
* Default MCP Client with all integrations pre-configured
|
|
33
|
+
*
|
|
34
|
+
* This is a singleton client instance that includes GitHub and Gmail integrations.
|
|
35
|
+
* You can use it directly without having to configure integrations.
|
|
36
|
+
*
|
|
37
|
+
* Default configuration:
|
|
38
|
+
* - Calls API routes at: {window.location.origin}/api/integrate/mcp
|
|
39
|
+
* - OAuth routes at: {window.location.origin}/api/integrate/oauth/*
|
|
40
|
+
*
|
|
41
|
+
* For custom configuration (different apiBaseUrl, apiRouteBase, etc.),
|
|
42
|
+
* use `createMCPClient()` instead.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* import { client } from 'integrate-sdk';
|
|
47
|
+
*
|
|
48
|
+
* // Use GitHub integration
|
|
49
|
+
* const repos = await client.github.listOwnRepos({});
|
|
50
|
+
*
|
|
51
|
+
* // Use Gmail integration
|
|
52
|
+
* const messages = await client.gmail.listMessages({});
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare const client: import("./index.js").MCPClient<import("./index.js").MCPIntegration[]>;
|
|
20
56
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,cAAc,gBAAgB,CAAC;AAO/B;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,MAAM,uEAKjB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -825,8 +825,10 @@ class OAuthManager {
|
|
|
825
825
|
windowManager;
|
|
826
826
|
flowConfig;
|
|
827
827
|
oauthApiBase;
|
|
828
|
-
|
|
828
|
+
apiBaseUrl;
|
|
829
|
+
constructor(oauthApiBase, flowConfig, apiBaseUrl) {
|
|
829
830
|
this.oauthApiBase = oauthApiBase;
|
|
831
|
+
this.apiBaseUrl = apiBaseUrl;
|
|
830
832
|
this.windowManager = new OAuthWindowManager;
|
|
831
833
|
this.flowConfig = {
|
|
832
834
|
mode: flowConfig?.mode || "redirect",
|
|
@@ -1077,7 +1079,7 @@ class OAuthManager {
|
|
|
1077
1079
|
}
|
|
1078
1080
|
}
|
|
1079
1081
|
async getAuthorizationUrl(provider, scopes, state, codeChallenge, redirectUri) {
|
|
1080
|
-
const url = `${this.oauthApiBase}/authorize`;
|
|
1082
|
+
const url = this.apiBaseUrl ? `${this.apiBaseUrl}${this.oauthApiBase}/authorize` : `${this.oauthApiBase}/authorize`;
|
|
1081
1083
|
const response = await fetch(url, {
|
|
1082
1084
|
method: "POST",
|
|
1083
1085
|
headers: {
|
|
@@ -1100,7 +1102,7 @@ class OAuthManager {
|
|
|
1100
1102
|
return data.authorizationUrl;
|
|
1101
1103
|
}
|
|
1102
1104
|
async exchangeCodeForToken(provider, code, codeVerifier, state) {
|
|
1103
|
-
const url = `${this.oauthApiBase}/callback`;
|
|
1105
|
+
const url = this.apiBaseUrl ? `${this.apiBaseUrl}${this.oauthApiBase}/callback` : `${this.oauthApiBase}/callback`;
|
|
1104
1106
|
const response = await fetch(url, {
|
|
1105
1107
|
method: "POST",
|
|
1106
1108
|
headers: {
|
|
@@ -1178,6 +1180,7 @@ class MCPClient {
|
|
|
1178
1180
|
oauthManager;
|
|
1179
1181
|
eventEmitter = new SimpleEventEmitter;
|
|
1180
1182
|
apiRouteBase;
|
|
1183
|
+
apiBaseUrl;
|
|
1181
1184
|
github;
|
|
1182
1185
|
gmail;
|
|
1183
1186
|
server;
|
|
@@ -1190,6 +1193,7 @@ class MCPClient {
|
|
|
1190
1193
|
const oauthApiBase = config.oauthApiBase || "/api/integrate/oauth";
|
|
1191
1194
|
const defaultRedirectUri = this.getDefaultRedirectUri(oauthApiBase);
|
|
1192
1195
|
this.apiRouteBase = config.apiRouteBase || "/api/integrate";
|
|
1196
|
+
this.apiBaseUrl = config.apiBaseUrl;
|
|
1193
1197
|
this.integrations = config.integrations.map((integration) => {
|
|
1194
1198
|
if (integration.oauth && !integration.oauth.redirectUri) {
|
|
1195
1199
|
return {
|
|
@@ -1208,7 +1212,7 @@ class MCPClient {
|
|
|
1208
1212
|
};
|
|
1209
1213
|
this.onReauthRequired = config.onReauthRequired;
|
|
1210
1214
|
this.maxReauthRetries = config.maxReauthRetries ?? 1;
|
|
1211
|
-
this.oauthManager = new OAuthManager(oauthApiBase, config.oauthFlow);
|
|
1215
|
+
this.oauthManager = new OAuthManager(oauthApiBase, config.oauthFlow, this.apiBaseUrl);
|
|
1212
1216
|
const providers = this.integrations.filter((p) => p.oauth).map((p) => p.oauth.provider);
|
|
1213
1217
|
this.oauthManager.loadAllProviderTokens(providers);
|
|
1214
1218
|
for (const integration of this.integrations) {
|
|
@@ -1234,6 +1238,10 @@ class MCPClient {
|
|
|
1234
1238
|
return `${origin}${normalizedPath}/callback`;
|
|
1235
1239
|
}
|
|
1236
1240
|
createIntegrationProxy(integrationId) {
|
|
1241
|
+
const hasIntegration = this.integrations.some((integration) => integration.id === integrationId);
|
|
1242
|
+
if (!hasIntegration) {
|
|
1243
|
+
return;
|
|
1244
|
+
}
|
|
1237
1245
|
return new Proxy({}, {
|
|
1238
1246
|
get: (_target, methodName) => {
|
|
1239
1247
|
return async (args) => {
|
|
@@ -1347,7 +1355,7 @@ class MCPClient {
|
|
|
1347
1355
|
});
|
|
1348
1356
|
return result2;
|
|
1349
1357
|
}
|
|
1350
|
-
const url = `${this.apiRouteBase}/mcp`;
|
|
1358
|
+
const url = this.apiBaseUrl ? `${this.apiBaseUrl}${this.apiRouteBase}/mcp` : `${this.apiRouteBase}/mcp`;
|
|
1351
1359
|
const headers = {
|
|
1352
1360
|
"Content-Type": "application/json"
|
|
1353
1361
|
};
|
|
@@ -2362,6 +2370,13 @@ var createTanStackOAuthHandler = toTanStackStartHandler;
|
|
|
2362
2370
|
|
|
2363
2371
|
// src/index.ts
|
|
2364
2372
|
init_errors();
|
|
2373
|
+
// index.ts
|
|
2374
|
+
var client = createMCPClient({
|
|
2375
|
+
integrations: [
|
|
2376
|
+
githubIntegration(),
|
|
2377
|
+
gmailIntegration()
|
|
2378
|
+
]
|
|
2379
|
+
});
|
|
2365
2380
|
export {
|
|
2366
2381
|
toTanStackStartHandler,
|
|
2367
2382
|
toSvelteKitHandler,
|
|
@@ -2387,6 +2402,7 @@ export {
|
|
|
2387
2402
|
createOAuthRedirectHandler,
|
|
2388
2403
|
createNextOAuthHandler,
|
|
2389
2404
|
createMCPClient,
|
|
2405
|
+
client,
|
|
2390
2406
|
clearClientCache,
|
|
2391
2407
|
ToolCallError,
|
|
2392
2408
|
TokenExpiredError,
|
package/dist/server.js
CHANGED
|
@@ -818,8 +818,10 @@ class OAuthManager {
|
|
|
818
818
|
windowManager;
|
|
819
819
|
flowConfig;
|
|
820
820
|
oauthApiBase;
|
|
821
|
-
|
|
821
|
+
apiBaseUrl;
|
|
822
|
+
constructor(oauthApiBase, flowConfig, apiBaseUrl) {
|
|
822
823
|
this.oauthApiBase = oauthApiBase;
|
|
824
|
+
this.apiBaseUrl = apiBaseUrl;
|
|
823
825
|
this.windowManager = new OAuthWindowManager;
|
|
824
826
|
this.flowConfig = {
|
|
825
827
|
mode: flowConfig?.mode || "redirect",
|
|
@@ -1070,7 +1072,7 @@ class OAuthManager {
|
|
|
1070
1072
|
}
|
|
1071
1073
|
}
|
|
1072
1074
|
async getAuthorizationUrl(provider, scopes, state, codeChallenge, redirectUri) {
|
|
1073
|
-
const url = `${this.oauthApiBase}/authorize`;
|
|
1075
|
+
const url = this.apiBaseUrl ? `${this.apiBaseUrl}${this.oauthApiBase}/authorize` : `${this.oauthApiBase}/authorize`;
|
|
1074
1076
|
const response = await fetch(url, {
|
|
1075
1077
|
method: "POST",
|
|
1076
1078
|
headers: {
|
|
@@ -1093,7 +1095,7 @@ class OAuthManager {
|
|
|
1093
1095
|
return data.authorizationUrl;
|
|
1094
1096
|
}
|
|
1095
1097
|
async exchangeCodeForToken(provider, code, codeVerifier, state) {
|
|
1096
|
-
const url = `${this.oauthApiBase}/callback`;
|
|
1098
|
+
const url = this.apiBaseUrl ? `${this.apiBaseUrl}${this.oauthApiBase}/callback` : `${this.oauthApiBase}/callback`;
|
|
1097
1099
|
const response = await fetch(url, {
|
|
1098
1100
|
method: "POST",
|
|
1099
1101
|
headers: {
|
|
@@ -1169,6 +1171,7 @@ class MCPClient {
|
|
|
1169
1171
|
oauthManager;
|
|
1170
1172
|
eventEmitter = new SimpleEventEmitter;
|
|
1171
1173
|
apiRouteBase;
|
|
1174
|
+
apiBaseUrl;
|
|
1172
1175
|
github;
|
|
1173
1176
|
gmail;
|
|
1174
1177
|
server;
|
|
@@ -1181,6 +1184,7 @@ class MCPClient {
|
|
|
1181
1184
|
const oauthApiBase = config.oauthApiBase || "/api/integrate/oauth";
|
|
1182
1185
|
const defaultRedirectUri = this.getDefaultRedirectUri(oauthApiBase);
|
|
1183
1186
|
this.apiRouteBase = config.apiRouteBase || "/api/integrate";
|
|
1187
|
+
this.apiBaseUrl = config.apiBaseUrl;
|
|
1184
1188
|
this.integrations = config.integrations.map((integration) => {
|
|
1185
1189
|
if (integration.oauth && !integration.oauth.redirectUri) {
|
|
1186
1190
|
return {
|
|
@@ -1199,7 +1203,7 @@ class MCPClient {
|
|
|
1199
1203
|
};
|
|
1200
1204
|
this.onReauthRequired = config.onReauthRequired;
|
|
1201
1205
|
this.maxReauthRetries = config.maxReauthRetries ?? 1;
|
|
1202
|
-
this.oauthManager = new OAuthManager(oauthApiBase, config.oauthFlow);
|
|
1206
|
+
this.oauthManager = new OAuthManager(oauthApiBase, config.oauthFlow, this.apiBaseUrl);
|
|
1203
1207
|
const providers = this.integrations.filter((p) => p.oauth).map((p) => p.oauth.provider);
|
|
1204
1208
|
this.oauthManager.loadAllProviderTokens(providers);
|
|
1205
1209
|
for (const integration of this.integrations) {
|
|
@@ -1225,6 +1229,10 @@ class MCPClient {
|
|
|
1225
1229
|
return `${origin}${normalizedPath}/callback`;
|
|
1226
1230
|
}
|
|
1227
1231
|
createIntegrationProxy(integrationId) {
|
|
1232
|
+
const hasIntegration = this.integrations.some((integration) => integration.id === integrationId);
|
|
1233
|
+
if (!hasIntegration) {
|
|
1234
|
+
return;
|
|
1235
|
+
}
|
|
1228
1236
|
return new Proxy({}, {
|
|
1229
1237
|
get: (_target, methodName) => {
|
|
1230
1238
|
return async (args) => {
|
|
@@ -1338,7 +1346,7 @@ class MCPClient {
|
|
|
1338
1346
|
});
|
|
1339
1347
|
return result2;
|
|
1340
1348
|
}
|
|
1341
|
-
const url = `${this.apiRouteBase}/mcp`;
|
|
1349
|
+
const url = this.apiBaseUrl ? `${this.apiBaseUrl}${this.apiRouteBase}/mcp` : `${this.apiRouteBase}/mcp`;
|
|
1342
1350
|
const headers = {
|
|
1343
1351
|
"Content-Type": "application/json"
|
|
1344
1352
|
};
|
package/dist/src/client.d.ts
CHANGED
|
@@ -56,6 +56,7 @@ export declare class MCPClient<TIntegrations extends readonly MCPIntegration[] =
|
|
|
56
56
|
private oauthManager;
|
|
57
57
|
private eventEmitter;
|
|
58
58
|
private apiRouteBase;
|
|
59
|
+
private apiBaseUrl?;
|
|
59
60
|
readonly github: IntegrationNamespaces<TIntegrations> extends {
|
|
60
61
|
github: GitHubIntegrationClient;
|
|
61
62
|
} ? GitHubIntegrationClient : never;
|
|
@@ -75,6 +76,7 @@ export declare class MCPClient<TIntegrations extends readonly MCPIntegration[] =
|
|
|
75
76
|
/**
|
|
76
77
|
* Create a proxy for a integration namespace that intercepts method calls
|
|
77
78
|
* and routes them to the appropriate tool
|
|
79
|
+
* Returns undefined if the integration is not configured
|
|
78
80
|
*/
|
|
79
81
|
private createIntegrationProxy;
|
|
80
82
|
/**
|
package/dist/src/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EACV,OAAO,EAEP,mBAAmB,EAGpB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,KAAK,EAAE,eAAe,EAAiB,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAGL,KAAK,mBAAmB,EACzB,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAC7E,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAE/E,OAAO,KAAK,EACV,UAAU,EACV,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,mBAAmB,EACpB,MAAM,kBAAkB,CAAC;AAgE1B;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,gBAAgB;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,qBAAqB;IACrB,SAAS,CAAC,EAAE,MAAM,C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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,eAAe,CAAC,aAAa,SAAS,SAAS,cAAc,EAAE,EAC7E,MAAM,EAAE,eAAe,CAAC,aAAa,CAAC,GACrC,SAAS,CAAC,aAAa,CAAC,CAkE1B;AA0CD;;;;;;;;;;;GAWG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAetD"}
|
|
@@ -59,20 +59,55 @@ export interface MCPClientConfig<TIntegrations extends readonly MCPIntegration[]
|
|
|
59
59
|
/** Array of integrations to enable */
|
|
60
60
|
integrations: TIntegrations;
|
|
61
61
|
/**
|
|
62
|
-
* MCP Server URL
|
|
62
|
+
* MCP Server URL (SERVER-SIDE ONLY - for createMCPServer)
|
|
63
|
+
*
|
|
64
|
+
* ⚠️ DO NOT configure this in client-side code (createMCPClient)!
|
|
65
|
+
* The client calls YOUR API routes at apiRouteBase/mcp, which then call the MCP server.
|
|
66
|
+
*
|
|
67
|
+
* This is only used server-side to specify which MCP backend to connect to.
|
|
63
68
|
*
|
|
64
69
|
* @default 'https://mcp.integrate.dev/api/v1/mcp'
|
|
65
70
|
*
|
|
66
71
|
* @example
|
|
67
72
|
* ```typescript
|
|
68
|
-
* //
|
|
69
|
-
*
|
|
73
|
+
* // Server-side only - point to a different MCP backend
|
|
74
|
+
* createMCPServer({
|
|
70
75
|
* serverUrl: 'http://localhost:8080/api/v1/mcp',
|
|
71
76
|
* integrations: [githubIntegration({ ... })]
|
|
72
77
|
* })
|
|
73
78
|
* ```
|
|
79
|
+
*
|
|
80
|
+
* @internal This is primarily for server configuration
|
|
74
81
|
*/
|
|
75
82
|
serverUrl?: string;
|
|
83
|
+
/**
|
|
84
|
+
* Base origin URL for your API routes (client-side configuration)
|
|
85
|
+
* Use this when your API routes are hosted on a different domain than your frontend
|
|
86
|
+
*
|
|
87
|
+
* The client will make requests to:
|
|
88
|
+
* - {apiBaseUrl}{apiRouteBase}/mcp (for tool calls)
|
|
89
|
+
* - {apiBaseUrl}{oauthApiBase}/authorize (for OAuth)
|
|
90
|
+
*
|
|
91
|
+
* @default window.location.origin (browser) or undefined (server)
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* // Frontend on localhost:3000, API on localhost:4000
|
|
96
|
+
* createMCPClient({
|
|
97
|
+
* apiBaseUrl: 'http://localhost:4000',
|
|
98
|
+
* integrations: [githubIntegration({ ... })]
|
|
99
|
+
* })
|
|
100
|
+
* // Will call: http://localhost:4000/api/integrate/mcp
|
|
101
|
+
*
|
|
102
|
+
* // Frontend on app.example.com, API on api.example.com
|
|
103
|
+
* createMCPClient({
|
|
104
|
+
* apiBaseUrl: 'https://api.example.com',
|
|
105
|
+
* integrations: [githubIntegration({ ... })]
|
|
106
|
+
* })
|
|
107
|
+
* // Will call: https://api.example.com/api/integrate/mcp
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
apiBaseUrl?: string;
|
|
76
111
|
/** Optional HTTP headers to include in requests */
|
|
77
112
|
headers?: Record<string, string>;
|
|
78
113
|
/** Request timeout in milliseconds (default: 30000) */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/config/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,4DAA4D;IAC5D,QAAQ,EAAE,MAAM,CAAC;IACjB,iDAAiD;IACjD,KAAK,EAAE,mBAAmB,CAAC;IAC3B,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC,OAAO,CAAC,GA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;;;;;;;;;;;OAaG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAAC,aAAa,SAAS,SAAS,cAAc,EAAE,IAC3E,aAAa,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;AAEzC;;GAEG;AACH,MAAM,MAAM,gBAAgB,CAAC,aAAa,SAAS,SAAS,cAAc,EAAE,IAAI;KAC7E,CAAC,IAAI,aAAa,CAAC,MAAM,CAAC,IAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC;CACnD,CAAC"}
|
|
@@ -14,7 +14,8 @@ export declare class OAuthManager {
|
|
|
14
14
|
private windowManager;
|
|
15
15
|
private flowConfig;
|
|
16
16
|
private oauthApiBase;
|
|
17
|
-
|
|
17
|
+
private apiBaseUrl?;
|
|
18
|
+
constructor(oauthApiBase: string, flowConfig?: Partial<OAuthFlowConfig>, apiBaseUrl?: string);
|
|
18
19
|
/**
|
|
19
20
|
* Initiate OAuth authorization flow
|
|
20
21
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../src/oauth/manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EACV,eAAe,EAEf,UAAU,EAGV,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAIpB;;;GAGG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,YAAY,CAAuC;IAC3D,OAAO,CAAC,cAAc,CAA6C;IACnE,OAAO,CAAC,aAAa,CAAqB;IAC1C,OAAO,CAAC,UAAU,CAAkB;IACpC,OAAO,CAAC,YAAY,CAAS;
|
|
1
|
+
{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AItD;;OAEG;IACH,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,iBAAiB,GAAG,IAAI;IAKtE;;OAEG;IACH,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAW1C;;OAEG;IACH,sBAAsB,IAAI,IAAI;IAe9B;;;OAGG;IACH,oBAAoB,IAAI,IAAI;IAwB5B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAWzB;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAezB;;OAEG;IACH,qBAAqB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI;IAShD;;;;;OAKG;IACH,OAAO,CAAC,wBAAwB;IAWhC;;;OAGG;IACH,OAAO,CAAC,0BAA0B;IAelC;;OAEG;IACH,OAAO,CAAC,4BAA4B;IAWpC;;;OAGG;IACH,OAAO,CAAC,0BAA0B;IAoClC;;;OAGG;YACW,mBAAmB;IAqCjC;;;OAGG;YACW,oBAAoB;IAkClC;;OAEG;IACH,KAAK,IAAI,IAAI;CAGd"}
|
package/index.ts
CHANGED
|
@@ -5,17 +5,64 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
7
|
* ```typescript
|
|
8
|
+
* // Use the default client with all integrations
|
|
9
|
+
* import { client } from 'integrate-sdk';
|
|
10
|
+
*
|
|
11
|
+
* await client.github.listOwnRepos({});
|
|
12
|
+
*
|
|
13
|
+
* // Or create a custom client with different API configuration
|
|
8
14
|
* import { createMCPClient, githubIntegration } from 'integrate-sdk';
|
|
9
15
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
+
* // Example 1: Different API path (same origin)
|
|
17
|
+
* const customClient = createMCPClient({
|
|
18
|
+
* apiRouteBase: '/custom/api/path', // Calls /custom/api/path/mcp
|
|
19
|
+
* integrations: [githubIntegration()],
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // Example 2: Different API domain (cross-origin)
|
|
23
|
+
* const crossOriginClient = createMCPClient({
|
|
24
|
+
* apiBaseUrl: 'https://api.example.com', // API on different domain
|
|
25
|
+
* apiRouteBase: '/api/integrate', // Calls https://api.example.com/api/integrate/mcp
|
|
26
|
+
* integrations: [githubIntegration()],
|
|
16
27
|
* });
|
|
17
28
|
* ```
|
|
18
29
|
*/
|
|
19
30
|
|
|
20
31
|
export * from './src/index.js';
|
|
21
32
|
|
|
33
|
+
// Export default client with all integrations pre-configured
|
|
34
|
+
import { createMCPClient } from './src/client.js';
|
|
35
|
+
import { githubIntegration } from './src/integrations/github.js';
|
|
36
|
+
import { gmailIntegration } from './src/integrations/gmail.js';
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Default MCP Client with all integrations pre-configured
|
|
40
|
+
*
|
|
41
|
+
* This is a singleton client instance that includes GitHub and Gmail integrations.
|
|
42
|
+
* You can use it directly without having to configure integrations.
|
|
43
|
+
*
|
|
44
|
+
* Default configuration:
|
|
45
|
+
* - Calls API routes at: {window.location.origin}/api/integrate/mcp
|
|
46
|
+
* - OAuth routes at: {window.location.origin}/api/integrate/oauth/*
|
|
47
|
+
*
|
|
48
|
+
* For custom configuration (different apiBaseUrl, apiRouteBase, etc.),
|
|
49
|
+
* use `createMCPClient()` instead.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* import { client } from 'integrate-sdk';
|
|
54
|
+
*
|
|
55
|
+
* // Use GitHub integration
|
|
56
|
+
* const repos = await client.github.listOwnRepos({});
|
|
57
|
+
*
|
|
58
|
+
* // Use Gmail integration
|
|
59
|
+
* const messages = await client.gmail.listMessages({});
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export const client = createMCPClient({
|
|
63
|
+
integrations: [
|
|
64
|
+
githubIntegration(),
|
|
65
|
+
gmailIntegration(),
|
|
66
|
+
],
|
|
67
|
+
});
|
|
68
|
+
|