integrate-sdk 0.7.18 → 0.7.20
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/README.md +30 -30
- package/dist/adapters/solid-start.js +56 -56
- package/dist/adapters/svelte-kit.js +56 -56
- package/dist/index.d.ts +4 -4
- package/dist/index.js +85 -85
- package/dist/server.d.ts +1 -1
- package/dist/server.js +83 -83
- package/dist/src/adapters/svelte-kit.d.ts +6 -6
- package/dist/src/adapters/tanstack-start.d.ts +3 -3
- package/dist/src/{integrations → ai}/anthropic.d.ts +6 -6
- package/dist/src/ai/anthropic.d.ts.map +1 -0
- package/dist/src/{integrations → ai}/cloudflare.d.ts +6 -6
- package/dist/src/ai/cloudflare.d.ts.map +1 -0
- package/dist/src/{integrations → ai}/google.d.ts +6 -6
- package/dist/src/ai/google.d.ts.map +1 -0
- package/dist/src/{integrations → ai}/index.d.ts +4 -4
- package/dist/src/ai/index.d.ts.map +1 -0
- package/dist/src/{integrations → ai}/langchain.d.ts +6 -6
- package/dist/src/ai/langchain.d.ts.map +1 -0
- package/dist/src/{integrations → ai}/llamaindex.d.ts +6 -6
- package/dist/src/ai/llamaindex.d.ts.map +1 -0
- package/dist/src/{integrations → ai}/mastra.d.ts +6 -6
- package/dist/src/ai/mastra.d.ts.map +1 -0
- package/dist/src/{integrations → ai}/openai-agents.d.ts +6 -6
- package/dist/src/ai/openai-agents.d.ts.map +1 -0
- package/dist/src/{integrations → ai}/openai.d.ts +6 -6
- package/dist/src/ai/openai.d.ts.map +1 -0
- package/dist/src/{integrations → ai}/utils.d.ts +1 -1
- package/dist/src/ai/utils.d.ts.map +1 -0
- package/dist/src/{integrations → ai}/vercel-ai.d.ts +4 -4
- package/dist/src/ai/vercel-ai.d.ts.map +1 -0
- package/dist/src/client.d.ts +39 -39
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/config/types.d.ts +24 -24
- package/dist/src/config/types.d.ts.map +1 -1
- package/dist/src/index.d.ts +10 -10
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/{plugins → integrations}/generic.d.ts +14 -14
- package/dist/src/integrations/generic.d.ts.map +1 -0
- package/dist/src/{plugins → integrations}/github-client.d.ts +4 -4
- package/dist/src/integrations/github-client.d.ts.map +1 -0
- package/dist/src/{plugins → integrations}/github.d.ts +17 -17
- package/dist/src/integrations/github.d.ts.map +1 -0
- package/dist/src/{plugins → integrations}/gmail-client.d.ts +4 -4
- package/dist/src/integrations/gmail-client.d.ts.map +1 -0
- package/dist/src/{plugins → integrations}/gmail.d.ts +17 -17
- package/dist/src/integrations/gmail.d.ts.map +1 -0
- package/dist/src/{plugins → integrations}/server-client.d.ts +4 -4
- package/dist/src/integrations/server-client.d.ts.map +1 -0
- package/dist/src/{plugins → integrations}/types.d.ts +15 -15
- package/dist/src/integrations/types.d.ts.map +1 -0
- package/dist/src/oauth/manager.d.ts +1 -1
- package/dist/src/oauth/manager.d.ts.map +1 -1
- package/dist/src/react/hooks.d.ts +5 -5
- package/dist/src/server.d.ts +25 -25
- package/dist/src/server.d.ts.map +1 -1
- package/dist/src/utils/naming.d.ts +3 -3
- package/dist/src/utils/naming.d.ts.map +1 -1
- package/index.ts +4 -4
- package/package.json +27 -27
- package/server.ts +1 -1
- package/dist/src/integrations/anthropic.d.ts.map +0 -1
- package/dist/src/integrations/cloudflare.d.ts.map +0 -1
- package/dist/src/integrations/google.d.ts.map +0 -1
- package/dist/src/integrations/index.d.ts.map +0 -1
- package/dist/src/integrations/langchain.d.ts.map +0 -1
- package/dist/src/integrations/llamaindex.d.ts.map +0 -1
- package/dist/src/integrations/mastra.d.ts.map +0 -1
- package/dist/src/integrations/openai-agents.d.ts.map +0 -1
- package/dist/src/integrations/openai.d.ts.map +0 -1
- package/dist/src/integrations/utils.d.ts.map +0 -1
- package/dist/src/integrations/vercel-ai.d.ts.map +0 -1
- package/dist/src/plugins/generic.d.ts.map +0 -1
- package/dist/src/plugins/github-client.d.ts.map +0 -1
- package/dist/src/plugins/github.d.ts.map +0 -1
- package/dist/src/plugins/gmail-client.d.ts.map +0 -1
- package/dist/src/plugins/gmail.d.ts.map +0 -1
- package/dist/src/plugins/server-client.d.ts.map +0 -1
- package/dist/src/plugins/types.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -3,19 +3,19 @@
|
|
|
3
3
|
[](https://github.com/Revyo/integrate-sdk/actions/workflows/test.yml)
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
|
|
6
|
-
A type-safe TypeScript SDK for connecting to the Integrate MCP (Model Context Protocol) server. Access GitHub, Gmail, Notion, and other integrations through a simple,
|
|
6
|
+
A type-safe TypeScript SDK for connecting to the Integrate MCP (Model Context Protocol) server. Access GitHub, Gmail, Notion, and other integrations through a simple, integration-based API.
|
|
7
7
|
|
|
8
8
|
**📚 [Full Documentation](https://integrate.dev)** | **Server:** `https://mcp.integrate.dev/api/v1/mcp`
|
|
9
9
|
|
|
10
10
|
## Features
|
|
11
11
|
|
|
12
|
-
- 🔌 **
|
|
12
|
+
- 🔌 **Integration-Based Architecture** - Enable only the integrations you need
|
|
13
13
|
- 🔒 **Fully Typed API** - Type-safe methods with autocomplete (e.g., `client.github.createIssue()`)
|
|
14
14
|
- 💡 **IntelliSense Support** - Full TypeScript support with parameter hints
|
|
15
15
|
- ⚡ **Automatic Connection Management** - Lazy connection, auto-cleanup, singleton pattern
|
|
16
16
|
- 🔐 **Complete OAuth Flow** - Built-in OAuth 2.0 with PKCE (popup/redirect modes)
|
|
17
17
|
- 🌍 **Universal** - Works in browser and Node.js environments
|
|
18
|
-
- 🛠️ **Extensible** - Configure
|
|
18
|
+
- 🛠️ **Extensible** - Configure integrations for any server-supported integration
|
|
19
19
|
- 📦 **Zero Dependencies** - Lightweight implementation
|
|
20
20
|
|
|
21
21
|
## Installation
|
|
@@ -43,24 +43,24 @@ For production, use: `https://yourdomain.com/api/integrate/oauth/callback`
|
|
|
43
43
|
|
|
44
44
|
### 1. Create Server Config
|
|
45
45
|
|
|
46
|
-
Define your OAuth providers once.
|
|
46
|
+
Define your OAuth providers once. Integrations automatically read credentials from environment variables:
|
|
47
47
|
|
|
48
48
|
```typescript
|
|
49
49
|
// lib/integrate-server.ts (server-side only!)
|
|
50
50
|
import {
|
|
51
51
|
createMCPServer,
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
githubIntegration,
|
|
53
|
+
gmailIntegration,
|
|
54
54
|
} from "integrate-sdk/server";
|
|
55
55
|
|
|
56
|
-
//
|
|
56
|
+
// Integrations automatically use GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET,
|
|
57
57
|
// GMAIL_CLIENT_ID, GMAIL_CLIENT_SECRET from environment
|
|
58
58
|
export const { client: serverClient } = createMCPServer({
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
integrations: [
|
|
60
|
+
githubIntegration({
|
|
61
61
|
scopes: ["repo", "user"],
|
|
62
62
|
}),
|
|
63
|
-
|
|
63
|
+
gmailIntegration({
|
|
64
64
|
scopes: ["gmail.readonly"],
|
|
65
65
|
}),
|
|
66
66
|
],
|
|
@@ -105,11 +105,11 @@ Use in your client components (no secrets needed):
|
|
|
105
105
|
|
|
106
106
|
```typescript
|
|
107
107
|
"use client";
|
|
108
|
-
import { createMCPClient,
|
|
108
|
+
import { createMCPClient, githubIntegration } from "integrate-sdk";
|
|
109
109
|
|
|
110
110
|
const client = createMCPClient({
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
integrations: [
|
|
112
|
+
githubIntegration({
|
|
113
113
|
scopes: ["repo", "user"],
|
|
114
114
|
// No clientId or clientSecret needed!
|
|
115
115
|
}),
|
|
@@ -150,10 +150,10 @@ The SDK automatically manages connections for you - no manual `connect()` or `di
|
|
|
150
150
|
|
|
151
151
|
```typescript
|
|
152
152
|
// ✅ Default behavior - automatic connection
|
|
153
|
-
//
|
|
153
|
+
// Integrations automatically use GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET from environment
|
|
154
154
|
const client = createMCPClient({
|
|
155
|
-
|
|
156
|
-
|
|
155
|
+
integrations: [
|
|
156
|
+
githubIntegration({
|
|
157
157
|
scopes: ["repo", "user"],
|
|
158
158
|
}),
|
|
159
159
|
],
|
|
@@ -165,7 +165,7 @@ await client.github.listRepos({ username: "octocat" });
|
|
|
165
165
|
|
|
166
166
|
// ✅ Want manual control? Use manual mode
|
|
167
167
|
const manualClient = createMCPClient({
|
|
168
|
-
|
|
168
|
+
integrations: [githubIntegration({ scopes: ["repo"] })],
|
|
169
169
|
connectionMode: "manual",
|
|
170
170
|
singleton: false,
|
|
171
171
|
});
|
|
@@ -189,7 +189,7 @@ See [Quick Start](#quick-start) above for complete examples.
|
|
|
189
189
|
|
|
190
190
|
## Why Use Integrate SDK?
|
|
191
191
|
|
|
192
|
-
### Typed
|
|
192
|
+
### Typed Integration Methods
|
|
193
193
|
|
|
194
194
|
Instead of generic tool calls, use typed methods with full autocomplete:
|
|
195
195
|
|
|
@@ -213,7 +213,7 @@ await client.gmail.sendEmail({ to: "user@example.com", subject: "Hello" });
|
|
|
213
213
|
### Three Ways to Call Tools
|
|
214
214
|
|
|
215
215
|
```typescript
|
|
216
|
-
// 1. Typed
|
|
216
|
+
// 1. Typed integration methods (recommended for built-in integrations like GitHub/Gmail)
|
|
217
217
|
await client.github.createIssue({
|
|
218
218
|
owner: "user",
|
|
219
219
|
repo: "project",
|
|
@@ -263,9 +263,9 @@ For complete OAuth setup including:
|
|
|
263
263
|
|
|
264
264
|
See the [`/examples`](/examples) directory or [OAuth documentation](https://integrate.dev/docs/guides/oauth-flow).
|
|
265
265
|
|
|
266
|
-
## Built-in
|
|
266
|
+
## Built-in Integrations
|
|
267
267
|
|
|
268
|
-
### GitHub
|
|
268
|
+
### GitHub Integration
|
|
269
269
|
|
|
270
270
|
Access GitHub repositories, issues, pull requests, and more with type-safe methods.
|
|
271
271
|
|
|
@@ -281,9 +281,9 @@ await client.github.listPullRequests({
|
|
|
281
281
|
await client.github.listOwnRepos({});
|
|
282
282
|
```
|
|
283
283
|
|
|
284
|
-
[→ GitHub
|
|
284
|
+
[→ GitHub integration documentation](https://integrate.dev/docs/integrations/github)
|
|
285
285
|
|
|
286
|
-
### Gmail
|
|
286
|
+
### Gmail Integration
|
|
287
287
|
|
|
288
288
|
Send emails, manage labels, and search messages with type-safe methods.
|
|
289
289
|
|
|
@@ -298,17 +298,17 @@ await client.gmail.listEmails({ maxResults: 10, q: "is:unread" });
|
|
|
298
298
|
await client.gmail.searchEmails({ query: "from:notifications@github.com" });
|
|
299
299
|
```
|
|
300
300
|
|
|
301
|
-
[→ Gmail
|
|
301
|
+
[→ Gmail integration documentation](https://integrate.dev/docs/integrations/gmail)
|
|
302
302
|
|
|
303
303
|
### Additional Integrations
|
|
304
304
|
|
|
305
|
-
Use `
|
|
305
|
+
Use `genericOAuthIntegration` to configure any server-supported integration:
|
|
306
306
|
|
|
307
307
|
```typescript
|
|
308
|
-
import {
|
|
308
|
+
import { genericOAuthIntegration } from "integrate-sdk/server";
|
|
309
309
|
|
|
310
310
|
// Automatically uses SLACK_CLIENT_ID and SLACK_CLIENT_SECRET from environment
|
|
311
|
-
const
|
|
311
|
+
const slackIntegration = genericOAuthIntegration({
|
|
312
312
|
id: "slack",
|
|
313
313
|
provider: "slack",
|
|
314
314
|
scopes: ["chat:write", "channels:read"],
|
|
@@ -339,7 +339,7 @@ const result = await generateText({
|
|
|
339
339
|
});
|
|
340
340
|
```
|
|
341
341
|
|
|
342
|
-
[→ View Vercel AI SDK integration guide](https://integrate.dev/docs/
|
|
342
|
+
[→ View Vercel AI SDK integration guide](https://integrate.dev/docs/ai/vercel-ai)
|
|
343
343
|
|
|
344
344
|
## Documentation
|
|
345
345
|
|
|
@@ -347,8 +347,8 @@ For detailed guides, API reference, and examples, visit the [complete documentat
|
|
|
347
347
|
|
|
348
348
|
- **[Getting Started](https://integrate.dev/docs/getting-started/installation)** - Installation and quick start
|
|
349
349
|
- **[OAuth Flow](https://integrate.dev/docs/guides/oauth-flow)** - OAuth 2.0 authorization guide
|
|
350
|
-
- **[
|
|
351
|
-
- **[Vercel AI SDK](https://integrate.dev/docs/
|
|
350
|
+
- **[Integrations](https://integrate.dev/docs/integrations)** - Built-in integrations and configuration
|
|
351
|
+
- **[Vercel AI SDK](https://integrate.dev/docs/ai/vercel-ai)** - AI model integration
|
|
352
352
|
- **[Advanced Usage](https://integrate.dev/docs/guides/advanced-usage)** - Error handling, retries, and more
|
|
353
353
|
- **[API Reference](https://integrate.dev/docs/reference/api-reference)** - Complete API documentation
|
|
354
354
|
- **[Architecture](https://integrate.dev/docs/reference/architecture)** - How the SDK works
|
|
@@ -796,9 +796,9 @@ init_errors();
|
|
|
796
796
|
function camelToSnake(str) {
|
|
797
797
|
return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
798
798
|
}
|
|
799
|
-
function methodToToolName(methodName,
|
|
799
|
+
function methodToToolName(methodName, integrationId) {
|
|
800
800
|
const snakeCaseMethod = camelToSnake(methodName);
|
|
801
|
-
return `${
|
|
801
|
+
return `${integrationId}_${snakeCaseMethod}`;
|
|
802
802
|
}
|
|
803
803
|
// src/oauth/window-manager.ts
|
|
804
804
|
function isBrowser() {
|
|
@@ -1318,7 +1318,7 @@ var clientCache = new Map;
|
|
|
1318
1318
|
var cleanupClients = new Set;
|
|
1319
1319
|
class MCPClient {
|
|
1320
1320
|
transport;
|
|
1321
|
-
|
|
1321
|
+
integrations;
|
|
1322
1322
|
availableTools = new Map;
|
|
1323
1323
|
enabledToolNames = new Set;
|
|
1324
1324
|
initialized = false;
|
|
@@ -1341,17 +1341,17 @@ class MCPClient {
|
|
|
1341
1341
|
const oauthApiBase = config.oauthApiBase || "/api/integrate/oauth";
|
|
1342
1342
|
const defaultRedirectUri = this.getDefaultRedirectUri(oauthApiBase);
|
|
1343
1343
|
this.apiRouteBase = config.apiRouteBase || "/api/integrate";
|
|
1344
|
-
this.
|
|
1345
|
-
if (
|
|
1344
|
+
this.integrations = config.integrations.map((integration) => {
|
|
1345
|
+
if (integration.oauth && !integration.oauth.redirectUri) {
|
|
1346
1346
|
return {
|
|
1347
|
-
...
|
|
1347
|
+
...integration,
|
|
1348
1348
|
oauth: {
|
|
1349
|
-
...
|
|
1349
|
+
...integration.oauth,
|
|
1350
1350
|
redirectUri: defaultRedirectUri
|
|
1351
1351
|
}
|
|
1352
1352
|
};
|
|
1353
1353
|
}
|
|
1354
|
-
return
|
|
1354
|
+
return integration;
|
|
1355
1355
|
});
|
|
1356
1356
|
this.clientInfo = config.clientInfo || {
|
|
1357
1357
|
name: "integrate-sdk",
|
|
@@ -1360,21 +1360,21 @@ class MCPClient {
|
|
|
1360
1360
|
this.onReauthRequired = config.onReauthRequired;
|
|
1361
1361
|
this.maxReauthRetries = config.maxReauthRetries ?? 1;
|
|
1362
1362
|
this.oauthManager = new OAuthManager(oauthApiBase, config.oauthFlow);
|
|
1363
|
-
const providers = this.
|
|
1363
|
+
const providers = this.integrations.filter((p) => p.oauth).map((p) => p.oauth.provider);
|
|
1364
1364
|
this.oauthManager.loadAllProviderTokens(providers);
|
|
1365
|
-
for (const
|
|
1366
|
-
for (const toolName of
|
|
1365
|
+
for (const integration of this.integrations) {
|
|
1366
|
+
for (const toolName of integration.tools) {
|
|
1367
1367
|
this.enabledToolNames.add(toolName);
|
|
1368
1368
|
}
|
|
1369
|
-
if (
|
|
1370
|
-
const hasToken = this.oauthManager.getProviderToken(
|
|
1371
|
-
this.authState.set(
|
|
1369
|
+
if (integration.oauth) {
|
|
1370
|
+
const hasToken = this.oauthManager.getProviderToken(integration.oauth.provider) !== undefined;
|
|
1371
|
+
this.authState.set(integration.oauth.provider, { authenticated: hasToken });
|
|
1372
1372
|
}
|
|
1373
1373
|
}
|
|
1374
|
-
this.github = this.
|
|
1375
|
-
this.gmail = this.
|
|
1374
|
+
this.github = this.createIntegrationProxy("github");
|
|
1375
|
+
this.gmail = this.createIntegrationProxy("gmail");
|
|
1376
1376
|
this.server = this.createServerProxy();
|
|
1377
|
-
this.
|
|
1377
|
+
this.initializeIntegrations();
|
|
1378
1378
|
}
|
|
1379
1379
|
getDefaultRedirectUri(oauthApiBase) {
|
|
1380
1380
|
if (typeof window === "undefined" || !window.location) {
|
|
@@ -1384,11 +1384,11 @@ class MCPClient {
|
|
|
1384
1384
|
const normalizedPath = oauthApiBase.replace(/\/$/, "");
|
|
1385
1385
|
return `${origin}${normalizedPath}/callback`;
|
|
1386
1386
|
}
|
|
1387
|
-
|
|
1387
|
+
createIntegrationProxy(integrationId) {
|
|
1388
1388
|
return new Proxy({}, {
|
|
1389
1389
|
get: (_target, methodName) => {
|
|
1390
1390
|
return async (args) => {
|
|
1391
|
-
const toolName = methodToToolName(methodName,
|
|
1391
|
+
const toolName = methodToToolName(methodName, integrationId);
|
|
1392
1392
|
return await this.callToolWithRetry(toolName, args, 0);
|
|
1393
1393
|
};
|
|
1394
1394
|
}
|
|
@@ -1414,25 +1414,25 @@ class MCPClient {
|
|
|
1414
1414
|
throw parsedError;
|
|
1415
1415
|
}
|
|
1416
1416
|
}
|
|
1417
|
-
async
|
|
1418
|
-
for (const
|
|
1419
|
-
if (
|
|
1420
|
-
await
|
|
1417
|
+
async initializeIntegrations() {
|
|
1418
|
+
for (const integration of this.integrations) {
|
|
1419
|
+
if (integration.onInit) {
|
|
1420
|
+
await integration.onInit(this);
|
|
1421
1421
|
}
|
|
1422
1422
|
}
|
|
1423
1423
|
}
|
|
1424
1424
|
async connect() {
|
|
1425
|
-
for (const
|
|
1426
|
-
if (
|
|
1427
|
-
await
|
|
1425
|
+
for (const integration of this.integrations) {
|
|
1426
|
+
if (integration.onBeforeConnect) {
|
|
1427
|
+
await integration.onBeforeConnect(this);
|
|
1428
1428
|
}
|
|
1429
1429
|
}
|
|
1430
1430
|
await this.transport.connect();
|
|
1431
1431
|
await this.initialize();
|
|
1432
1432
|
await this.discoverTools();
|
|
1433
|
-
for (const
|
|
1434
|
-
if (
|
|
1435
|
-
await
|
|
1433
|
+
for (const integration of this.integrations) {
|
|
1434
|
+
if (integration.onAfterConnect) {
|
|
1435
|
+
await integration.onAfterConnect(this);
|
|
1436
1436
|
}
|
|
1437
1437
|
}
|
|
1438
1438
|
}
|
|
@@ -1454,7 +1454,7 @@ class MCPClient {
|
|
|
1454
1454
|
this.availableTools.set(tool.name, tool);
|
|
1455
1455
|
}
|
|
1456
1456
|
const enabledTools = response.tools.filter((tool) => this.enabledToolNames.has(tool.name));
|
|
1457
|
-
console.log(`Discovered ${response.tools.length} tools, ${enabledTools.length} enabled by
|
|
1457
|
+
console.log(`Discovered ${response.tools.length} tools, ${enabledTools.length} enabled by integrations`);
|
|
1458
1458
|
}
|
|
1459
1459
|
async _callToolByName(name, args) {
|
|
1460
1460
|
return await this.callToolWithRetry(name, args, 0);
|
|
@@ -1514,7 +1514,7 @@ class MCPClient {
|
|
|
1514
1514
|
}
|
|
1515
1515
|
async callToolWithRetry(name, args, retryCount = 0) {
|
|
1516
1516
|
if (!this.enabledToolNames.has(name)) {
|
|
1517
|
-
throw new Error(`Tool "${name}" is not enabled. Enable it by adding the appropriate
|
|
1517
|
+
throw new Error(`Tool "${name}" is not enabled. Enable it by adding the appropriate integration.`);
|
|
1518
1518
|
}
|
|
1519
1519
|
const provider = this.getProviderForTool(name);
|
|
1520
1520
|
try {
|
|
@@ -1547,9 +1547,9 @@ class MCPClient {
|
|
|
1547
1547
|
}
|
|
1548
1548
|
}
|
|
1549
1549
|
getProviderForTool(toolName) {
|
|
1550
|
-
for (const
|
|
1551
|
-
if (
|
|
1552
|
-
return
|
|
1550
|
+
for (const integration of this.integrations) {
|
|
1551
|
+
if (integration.tools.includes(toolName) && integration.oauth) {
|
|
1552
|
+
return integration.oauth.provider;
|
|
1553
1553
|
}
|
|
1554
1554
|
}
|
|
1555
1555
|
return;
|
|
@@ -1566,15 +1566,15 @@ class MCPClient {
|
|
|
1566
1566
|
getEnabledTools() {
|
|
1567
1567
|
return Array.from(this.availableTools.values()).filter((tool) => this.enabledToolNames.has(tool.name));
|
|
1568
1568
|
}
|
|
1569
|
-
getOAuthConfig(
|
|
1570
|
-
const
|
|
1571
|
-
return
|
|
1569
|
+
getOAuthConfig(integrationId) {
|
|
1570
|
+
const integration = this.integrations.find((p) => p.id === integrationId);
|
|
1571
|
+
return integration?.oauth;
|
|
1572
1572
|
}
|
|
1573
1573
|
getAllOAuthConfigs() {
|
|
1574
1574
|
const configs = new Map;
|
|
1575
|
-
for (const
|
|
1576
|
-
if (
|
|
1577
|
-
configs.set(
|
|
1575
|
+
for (const integration of this.integrations) {
|
|
1576
|
+
if (integration.oauth) {
|
|
1577
|
+
configs.set(integration.id, integration.oauth);
|
|
1578
1578
|
}
|
|
1579
1579
|
}
|
|
1580
1580
|
return configs;
|
|
@@ -1592,8 +1592,8 @@ class MCPClient {
|
|
|
1592
1592
|
this.oauthManager.clearAllProviderTokens();
|
|
1593
1593
|
}
|
|
1594
1594
|
async disconnectProvider(provider) {
|
|
1595
|
-
const
|
|
1596
|
-
if (!
|
|
1595
|
+
const integration = this.integrations.find((p) => p.oauth?.provider === provider);
|
|
1596
|
+
if (!integration?.oauth) {
|
|
1597
1597
|
throw new Error(`No OAuth configuration found for provider: ${provider}`);
|
|
1598
1598
|
}
|
|
1599
1599
|
try {
|
|
@@ -1612,17 +1612,17 @@ class MCPClient {
|
|
|
1612
1612
|
this.clearSessionToken();
|
|
1613
1613
|
this.oauthManager.clearAllPendingAuths();
|
|
1614
1614
|
this.authState.clear();
|
|
1615
|
-
for (const
|
|
1616
|
-
if (
|
|
1617
|
-
this.authState.set(
|
|
1615
|
+
for (const integration of this.integrations) {
|
|
1616
|
+
if (integration.oauth) {
|
|
1617
|
+
this.authState.set(integration.oauth.provider, { authenticated: false });
|
|
1618
1618
|
}
|
|
1619
1619
|
}
|
|
1620
1620
|
this.eventEmitter.emit("auth:logout", {});
|
|
1621
1621
|
}
|
|
1622
1622
|
async disconnect() {
|
|
1623
|
-
for (const
|
|
1624
|
-
if (
|
|
1625
|
-
await
|
|
1623
|
+
for (const integration of this.integrations) {
|
|
1624
|
+
if (integration.onDisconnect) {
|
|
1625
|
+
await integration.onDisconnect(this);
|
|
1626
1626
|
}
|
|
1627
1627
|
}
|
|
1628
1628
|
await this.transport.disconnect();
|
|
@@ -1646,11 +1646,11 @@ class MCPClient {
|
|
|
1646
1646
|
}
|
|
1647
1647
|
async authorizedProviders() {
|
|
1648
1648
|
const authorized = [];
|
|
1649
|
-
for (const
|
|
1650
|
-
if (
|
|
1651
|
-
const status = await this.oauthManager.checkAuthStatus(
|
|
1649
|
+
for (const integration of this.integrations) {
|
|
1650
|
+
if (integration.oauth) {
|
|
1651
|
+
const status = await this.oauthManager.checkAuthStatus(integration.oauth.provider);
|
|
1652
1652
|
if (status.authorized) {
|
|
1653
|
-
authorized.push(
|
|
1653
|
+
authorized.push(integration.oauth.provider);
|
|
1654
1654
|
}
|
|
1655
1655
|
}
|
|
1656
1656
|
}
|
|
@@ -1660,15 +1660,15 @@ class MCPClient {
|
|
|
1660
1660
|
return await this.oauthManager.checkAuthStatus(provider);
|
|
1661
1661
|
}
|
|
1662
1662
|
async authorize(provider, options) {
|
|
1663
|
-
const
|
|
1664
|
-
if (!
|
|
1663
|
+
const integration = this.integrations.find((p) => p.oauth?.provider === provider);
|
|
1664
|
+
if (!integration?.oauth) {
|
|
1665
1665
|
const error = new Error(`No OAuth configuration found for provider: ${provider}`);
|
|
1666
1666
|
this.eventEmitter.emit("auth:error", { provider, error });
|
|
1667
1667
|
throw error;
|
|
1668
1668
|
}
|
|
1669
1669
|
this.eventEmitter.emit("auth:started", { provider });
|
|
1670
1670
|
try {
|
|
1671
|
-
await this.oauthManager.initiateFlow(provider,
|
|
1671
|
+
await this.oauthManager.initiateFlow(provider, integration.oauth, options?.returnUrl);
|
|
1672
1672
|
const tokenData = this.oauthManager.getProviderToken(provider);
|
|
1673
1673
|
if (tokenData) {
|
|
1674
1674
|
this.eventEmitter.emit("auth:complete", {
|
|
@@ -1718,7 +1718,7 @@ class MCPClient {
|
|
|
1718
1718
|
async reauthenticate(provider) {
|
|
1719
1719
|
const state = this.authState.get(provider);
|
|
1720
1720
|
if (!state) {
|
|
1721
|
-
throw new Error(`Provider "${provider}" not found in configured
|
|
1721
|
+
throw new Error(`Provider "${provider}" not found in configured integrations`);
|
|
1722
1722
|
}
|
|
1723
1723
|
if (!this.onReauthRequired) {
|
|
1724
1724
|
throw new Error("No re-authentication handler configured. Set onReauthRequired in client config.");
|