integrate-sdk 0.2.2 → 0.2.4
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 +181 -0
- package/dist/client.d.ts +134 -6
- package/dist/client.d.ts.map +1 -1
- package/dist/config/types.d.ts +65 -0
- package/dist/config/types.d.ts.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +533 -1
- package/dist/oauth/manager.d.ts +91 -0
- package/dist/oauth/manager.d.ts.map +1 -0
- package/dist/oauth/pkce.d.ts +47 -0
- package/dist/oauth/pkce.d.ts.map +1 -0
- package/dist/oauth/types.d.ts +84 -0
- package/dist/oauth/types.d.ts.map +1 -0
- package/dist/oauth/window-manager.d.ts +103 -0
- package/dist/oauth/window-manager.d.ts.map +1 -0
- package/dist/transport/http-session.d.ts +23 -0
- package/dist/transport/http-session.d.ts.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -98,6 +98,187 @@ await client.server.listToolsByIntegration({ integration: "github" });
|
|
|
98
98
|
await client._callToolByName("slack_send_message", { channel: "#general", text: "Hello" });
|
|
99
99
|
```
|
|
100
100
|
|
|
101
|
+
## OAuth Authorization
|
|
102
|
+
|
|
103
|
+
The SDK implements OAuth 2.0 Authorization Code Flow with PKCE for secure third-party service authorization. Users must authorize your application to access their GitHub, Gmail, or other accounts.
|
|
104
|
+
|
|
105
|
+
### How It Works
|
|
106
|
+
|
|
107
|
+
1. **Your App**: Creates client with OAuth configuration
|
|
108
|
+
2. **SDK**: Initiates OAuth flow (popup or redirect)
|
|
109
|
+
3. **User**: Authorizes permissions on provider's website
|
|
110
|
+
4. **Provider**: Redirects back with authorization code
|
|
111
|
+
5. **Your Server**: Exchanges code for tokens and stores them
|
|
112
|
+
6. **SDK**: Includes session token in all API requests
|
|
113
|
+
7. **Your Server**: Uses stored OAuth tokens for API calls
|
|
114
|
+
|
|
115
|
+
### Quick Start
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
import { createMCPClient, githubPlugin } from "integrate-sdk";
|
|
119
|
+
|
|
120
|
+
// Create client with OAuth flow configuration
|
|
121
|
+
const client = createMCPClient({
|
|
122
|
+
plugins: [
|
|
123
|
+
githubPlugin({
|
|
124
|
+
clientId: process.env.GITHUB_CLIENT_ID!,
|
|
125
|
+
clientSecret: process.env.GITHUB_CLIENT_SECRET!,
|
|
126
|
+
scopes: ["repo", "user"],
|
|
127
|
+
redirectUri: "http://localhost:3000/oauth/callback",
|
|
128
|
+
}),
|
|
129
|
+
],
|
|
130
|
+
oauthFlow: {
|
|
131
|
+
mode: 'popup', // or 'redirect'
|
|
132
|
+
popupOptions: { width: 600, height: 700 },
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// Check if authorized
|
|
137
|
+
const isAuthorized = await client.isAuthorized('github');
|
|
138
|
+
|
|
139
|
+
if (!isAuthorized) {
|
|
140
|
+
// Initiate OAuth flow - opens popup or redirects
|
|
141
|
+
await client.authorize('github');
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Now you can use GitHub tools
|
|
145
|
+
const repos = await client.github.listOwnRepos({});
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Popup Flow (Recommended for SPAs)
|
|
149
|
+
|
|
150
|
+
Best for single-page applications - authorization happens in a popup without leaving your app.
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
const client = createMCPClient({
|
|
154
|
+
plugins: [githubPlugin({ ... })],
|
|
155
|
+
oauthFlow: { mode: 'popup' },
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// This opens a popup for authorization
|
|
159
|
+
await client.authorize('github');
|
|
160
|
+
|
|
161
|
+
// After user approves, continues automatically
|
|
162
|
+
const repos = await client.github.listOwnRepos({});
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
**Callback Page**: Create `/oauth/callback.html`:
|
|
166
|
+
|
|
167
|
+
```html
|
|
168
|
+
<!DOCTYPE html>
|
|
169
|
+
<html>
|
|
170
|
+
<head>
|
|
171
|
+
<title>OAuth Callback</title>
|
|
172
|
+
<script type="module">
|
|
173
|
+
import { sendCallbackToOpener } from 'integrate-sdk';
|
|
174
|
+
|
|
175
|
+
const params = new URLSearchParams(window.location.search);
|
|
176
|
+
sendCallbackToOpener({
|
|
177
|
+
code: params.get('code'),
|
|
178
|
+
state: params.get('state'),
|
|
179
|
+
error: params.get('error')
|
|
180
|
+
});
|
|
181
|
+
</script>
|
|
182
|
+
</head>
|
|
183
|
+
<body>
|
|
184
|
+
<p>Authorization successful! Closing...</p>
|
|
185
|
+
</body>
|
|
186
|
+
</html>
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Redirect Flow (Traditional Web Apps)
|
|
190
|
+
|
|
191
|
+
Best for traditional server-rendered applications.
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
// Main page
|
|
195
|
+
const client = createMCPClient({
|
|
196
|
+
plugins: [githubPlugin({ ... })],
|
|
197
|
+
oauthFlow: { mode: 'redirect' },
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
if (!await client.isAuthorized('github')) {
|
|
201
|
+
await client.authorize('github'); // Redirects to GitHub
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Callback page (e.g., /oauth/callback)
|
|
205
|
+
const params = new URLSearchParams(window.location.search);
|
|
206
|
+
await client.handleOAuthCallback({
|
|
207
|
+
code: params.get('code')!,
|
|
208
|
+
state: params.get('state')!
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
// Save session token for future use
|
|
212
|
+
const sessionToken = client.getSessionToken();
|
|
213
|
+
localStorage.setItem('session_token', sessionToken);
|
|
214
|
+
|
|
215
|
+
// Redirect back to main app
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Session Token Management
|
|
219
|
+
|
|
220
|
+
Store and restore sessions to avoid re-authorization:
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
// Restore previous session
|
|
224
|
+
const client = createMCPClient({
|
|
225
|
+
plugins: [githubPlugin({ ... })],
|
|
226
|
+
sessionToken: localStorage.getItem('session_token'),
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// Check if session is still valid
|
|
230
|
+
if (!await client.isAuthorized('github')) {
|
|
231
|
+
await client.authorize('github');
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Store token after new authorization
|
|
235
|
+
const token = client.getSessionToken();
|
|
236
|
+
localStorage.setItem('session_token', token);
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Multiple Providers
|
|
240
|
+
|
|
241
|
+
Authorize multiple services independently:
|
|
242
|
+
|
|
243
|
+
```typescript
|
|
244
|
+
const client = createMCPClient({
|
|
245
|
+
plugins: [
|
|
246
|
+
githubPlugin({ ... }),
|
|
247
|
+
gmailPlugin({ ... }),
|
|
248
|
+
],
|
|
249
|
+
oauthFlow: { mode: 'popup' },
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
// Get list of all authorized providers
|
|
253
|
+
const authorized = await client.authorizedProviders();
|
|
254
|
+
console.log('Authorized:', authorized); // ['github', 'gmail']
|
|
255
|
+
|
|
256
|
+
// Or check and authorize each provider individually
|
|
257
|
+
if (!await client.isAuthorized('github')) {
|
|
258
|
+
await client.authorize('github');
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (!await client.isAuthorized('gmail')) {
|
|
262
|
+
await client.authorize('gmail');
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// Use both services
|
|
266
|
+
const repos = await client.github.listOwnRepos({});
|
|
267
|
+
const messages = await client.gmail.listMessages({});
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### Server Requirements
|
|
271
|
+
|
|
272
|
+
Your MCP server must implement these OAuth endpoints:
|
|
273
|
+
|
|
274
|
+
**GET `/oauth/authorize`** - Returns authorization URL
|
|
275
|
+
**POST `/oauth/callback`** - Exchanges code for tokens, returns session token
|
|
276
|
+
**GET `/oauth/status`** - Checks authorization status
|
|
277
|
+
|
|
278
|
+
All tool endpoints must accept `X-Session-Token` header and use stored OAuth tokens for API calls.
|
|
279
|
+
|
|
280
|
+
[→ View complete OAuth flow implementation guide](/docs/guides/oauth-flow.md)
|
|
281
|
+
|
|
101
282
|
## Built-in Plugins
|
|
102
283
|
|
|
103
284
|
### GitHub Plugin
|
package/dist/client.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { type AuthenticationError } from "./errors.js";
|
|
|
9
9
|
import type { GitHubPluginClient } from "./plugins/github-client.js";
|
|
10
10
|
import type { GmailPluginClient } from "./plugins/gmail-client.js";
|
|
11
11
|
import type { ServerPluginClient } from "./plugins/server-client.js";
|
|
12
|
+
import type { AuthStatus, OAuthCallbackParams } from "./oauth/types.js";
|
|
12
13
|
/**
|
|
13
14
|
* Tool invocation options
|
|
14
15
|
*/
|
|
@@ -52,6 +53,9 @@ export declare class MCPClient<TPlugins extends readonly MCPPlugin[] = readonly
|
|
|
52
53
|
private onReauthRequired?;
|
|
53
54
|
private maxReauthRetries;
|
|
54
55
|
private authState;
|
|
56
|
+
private connectionMode;
|
|
57
|
+
private connecting;
|
|
58
|
+
private oauthManager;
|
|
55
59
|
readonly github: PluginNamespaces<TPlugins> extends {
|
|
56
60
|
github: GitHubPluginClient;
|
|
57
61
|
} ? GitHubPluginClient : never;
|
|
@@ -60,6 +64,10 @@ export declare class MCPClient<TPlugins extends readonly MCPPlugin[] = readonly
|
|
|
60
64
|
} ? GmailPluginClient : never;
|
|
61
65
|
readonly server: ServerPluginClient;
|
|
62
66
|
constructor(config: MCPClientConfig<TPlugins>);
|
|
67
|
+
/**
|
|
68
|
+
* Ensure the client is connected (for lazy connection mode)
|
|
69
|
+
*/
|
|
70
|
+
private ensureConnected;
|
|
63
71
|
/**
|
|
64
72
|
* Create a proxy for a plugin namespace that intercepts method calls
|
|
65
73
|
* and routes them to the appropriate tool
|
|
@@ -163,6 +171,97 @@ export declare class MCPClient<TPlugins extends readonly MCPPlugin[] = readonly
|
|
|
163
171
|
* Check if a specific provider is authenticated
|
|
164
172
|
*/
|
|
165
173
|
isProviderAuthenticated(provider: string): boolean;
|
|
174
|
+
/**
|
|
175
|
+
* Check if a provider is authorized via OAuth
|
|
176
|
+
* Queries the MCP server to verify OAuth token validity
|
|
177
|
+
*
|
|
178
|
+
* @param provider - Provider name (github, gmail, etc.)
|
|
179
|
+
* @returns Authorization status
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* const isAuthorized = await client.isAuthorized('github');
|
|
184
|
+
* if (!isAuthorized) {
|
|
185
|
+
* await client.authorize('github');
|
|
186
|
+
* }
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
isAuthorized(provider: string): Promise<boolean>;
|
|
190
|
+
/**
|
|
191
|
+
* Get list of all authorized providers
|
|
192
|
+
* Checks all configured OAuth providers and returns names of authorized ones
|
|
193
|
+
*
|
|
194
|
+
* @returns Array of authorized provider names
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```typescript
|
|
198
|
+
* const authorized = await client.authorizedProviders();
|
|
199
|
+
* console.log('Authorized services:', authorized); // ['github', 'gmail']
|
|
200
|
+
*
|
|
201
|
+
* // Check if specific service is in the list
|
|
202
|
+
* if (authorized.includes('github')) {
|
|
203
|
+
* const repos = await client.github.listOwnRepos({});
|
|
204
|
+
* }
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
authorizedProviders(): Promise<string[]>;
|
|
208
|
+
/**
|
|
209
|
+
* Get detailed authorization status for a provider
|
|
210
|
+
*
|
|
211
|
+
* @param provider - Provider name
|
|
212
|
+
* @returns Full authorization status including scopes and expiration
|
|
213
|
+
*/
|
|
214
|
+
getAuthorizationStatus(provider: string): Promise<AuthStatus>;
|
|
215
|
+
/**
|
|
216
|
+
* Initiate OAuth authorization flow for a provider
|
|
217
|
+
* Opens authorization URL in popup or redirects based on configuration
|
|
218
|
+
*
|
|
219
|
+
* @param provider - Provider name (github, gmail, etc.)
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* // Popup flow
|
|
224
|
+
* await client.authorize('github');
|
|
225
|
+
*
|
|
226
|
+
* // Redirect flow
|
|
227
|
+
* await client.authorize('github'); // User is redirected away
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
authorize(provider: string): Promise<void>;
|
|
231
|
+
/**
|
|
232
|
+
* Handle OAuth callback after user authorization
|
|
233
|
+
* Call this from your OAuth callback page with code and state from URL
|
|
234
|
+
*
|
|
235
|
+
* @param params - Callback parameters containing code and state
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```typescript
|
|
239
|
+
* // In your callback route (e.g., /oauth/callback)
|
|
240
|
+
* const params = new URLSearchParams(window.location.search);
|
|
241
|
+
* await client.handleOAuthCallback({
|
|
242
|
+
* code: params.get('code')!,
|
|
243
|
+
* state: params.get('state')!
|
|
244
|
+
* });
|
|
245
|
+
*
|
|
246
|
+
* // Now you can use the client
|
|
247
|
+
* const repos = await client.github.listOwnRepos({});
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
handleOAuthCallback(params: OAuthCallbackParams): Promise<void>;
|
|
251
|
+
/**
|
|
252
|
+
* Get the current session token
|
|
253
|
+
* Useful for storing and restoring sessions
|
|
254
|
+
*
|
|
255
|
+
* @returns Session token or undefined if not authorized
|
|
256
|
+
*/
|
|
257
|
+
getSessionToken(): string | undefined;
|
|
258
|
+
/**
|
|
259
|
+
* Set session token manually
|
|
260
|
+
* Use this if you have an existing session token
|
|
261
|
+
*
|
|
262
|
+
* @param token - Session token
|
|
263
|
+
*/
|
|
264
|
+
setSessionToken(token: string): void;
|
|
166
265
|
/**
|
|
167
266
|
* Manually trigger re-authentication for a specific provider
|
|
168
267
|
* Useful if you want to proactively refresh tokens
|
|
@@ -172,24 +271,53 @@ export declare class MCPClient<TPlugins extends readonly MCPPlugin[] = readonly
|
|
|
172
271
|
/**
|
|
173
272
|
* Create a new MCP Client instance
|
|
174
273
|
*
|
|
175
|
-
*
|
|
274
|
+
* By default, uses singleton pattern and lazy connection:
|
|
275
|
+
* - Returns cached instance if one exists with same configuration
|
|
276
|
+
* - Automatically connects on first method call
|
|
277
|
+
* - Automatically cleans up on process exit
|
|
176
278
|
*
|
|
177
279
|
* @example
|
|
178
280
|
* ```typescript
|
|
281
|
+
* // Lazy connection (default) - connects automatically on first use
|
|
179
282
|
* const client = createMCPClient({
|
|
180
283
|
* plugins: [
|
|
181
284
|
* githubPlugin({ clientId: '...', clientSecret: '...' }),
|
|
182
|
-
* gmailPlugin({ clientId: '...', clientSecret: '...' }),
|
|
183
285
|
* ],
|
|
184
286
|
* });
|
|
185
287
|
*
|
|
186
|
-
*
|
|
187
|
-
* const
|
|
188
|
-
*
|
|
189
|
-
*
|
|
288
|
+
* // No need to call connect()!
|
|
289
|
+
* const repos = await client.github.listOwnRepos({});
|
|
290
|
+
*
|
|
291
|
+
* // No need to call disconnect()! (auto-cleanup on exit)
|
|
292
|
+
* ```
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* ```typescript
|
|
296
|
+
* // Manual connection mode (original behavior)
|
|
297
|
+
* const client = createMCPClient({
|
|
298
|
+
* plugins: [githubPlugin({ ... })],
|
|
299
|
+
* connectionMode: 'manual',
|
|
300
|
+
* singleton: false,
|
|
190
301
|
* });
|
|
302
|
+
*
|
|
303
|
+
* await client.connect();
|
|
304
|
+
* const repos = await client.github.listOwnRepos({});
|
|
305
|
+
* await client.disconnect();
|
|
191
306
|
* ```
|
|
192
307
|
*/
|
|
193
308
|
export declare function createMCPClient<TPlugins extends readonly MCPPlugin[]>(config: MCPClientConfig<TPlugins>): MCPClient<TPlugins>;
|
|
309
|
+
/**
|
|
310
|
+
* Clear the client cache and disconnect all cached clients
|
|
311
|
+
* Useful for testing or when you need to force recreation of clients
|
|
312
|
+
*
|
|
313
|
+
* @example
|
|
314
|
+
* ```typescript
|
|
315
|
+
* // In test teardown
|
|
316
|
+
* afterAll(async () => {
|
|
317
|
+
* await clearClientCache();
|
|
318
|
+
* });
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
321
|
+
export declare function clearClientCache(): Promise<void>;
|
|
194
322
|
export {};
|
|
195
323
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/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,EAIpB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,KAAK,EAAE,eAAe,EAAiB,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAGL,KAAK,mBAAmB,EACzB,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EACV,OAAO,EAEP,mBAAmB,EAIpB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,KAAK,EAAE,eAAe,EAAiB,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAGL,KAAK,mBAAmB,EACzB,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,C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AAC,IAAI,CAAC;IAcrE;;;;;OAKG;IACH,eAAe,IAAI,MAAM,GAAG,SAAS;IAIrC;;;;;OAKG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAKpC;;;OAGG;IACG,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CA2BzD;AA4DD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,eAAe,CAAC,QAAQ,SAAS,SAAS,SAAS,EAAE,EACnE,MAAM,EAAE,eAAe,CAAC,QAAQ,CAAC,GAChC,SAAS,CAAC,QAAQ,CAAC,CAwDrB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAetD"}
|
package/dist/config/types.d.ts
CHANGED
|
@@ -63,6 +63,71 @@ export interface MCPClientConfig<TPlugins extends readonly MCPPlugin[]> {
|
|
|
63
63
|
* Set to 0 to disable automatic retries
|
|
64
64
|
*/
|
|
65
65
|
maxReauthRetries?: number;
|
|
66
|
+
/**
|
|
67
|
+
* Connection behavior
|
|
68
|
+
*
|
|
69
|
+
* - 'lazy' (default): Automatically connects on first method call
|
|
70
|
+
* - 'eager': Connects immediately when createMCPClient is called
|
|
71
|
+
* - 'manual': Requires manual connect() call (original behavior)
|
|
72
|
+
*
|
|
73
|
+
* @default 'lazy'
|
|
74
|
+
*/
|
|
75
|
+
connectionMode?: 'lazy' | 'eager' | 'manual';
|
|
76
|
+
/**
|
|
77
|
+
* Whether to use singleton pattern and reuse client instances
|
|
78
|
+
*
|
|
79
|
+
* - true (default): Reuses client with same configuration
|
|
80
|
+
* - false: Always creates a new instance
|
|
81
|
+
*
|
|
82
|
+
* @default true
|
|
83
|
+
*/
|
|
84
|
+
singleton?: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Automatically cleanup (disconnect) on process exit
|
|
87
|
+
*
|
|
88
|
+
* @default true
|
|
89
|
+
*/
|
|
90
|
+
autoCleanup?: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* OAuth flow configuration
|
|
93
|
+
* Controls how OAuth authorization is handled (popup vs redirect)
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const client = createMCPClient({
|
|
98
|
+
* plugins: [githubPlugin({ ... })],
|
|
99
|
+
* oauthFlow: {
|
|
100
|
+
* mode: 'popup',
|
|
101
|
+
* popupOptions: { width: 600, height: 700 }
|
|
102
|
+
* }
|
|
103
|
+
* });
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
oauthFlow?: {
|
|
107
|
+
/** How to display OAuth authorization (default: 'redirect') */
|
|
108
|
+
mode?: 'popup' | 'redirect';
|
|
109
|
+
/** Popup window dimensions (only for popup mode) */
|
|
110
|
+
popupOptions?: {
|
|
111
|
+
width?: number;
|
|
112
|
+
height?: number;
|
|
113
|
+
};
|
|
114
|
+
/** Custom callback handler for receiving auth code */
|
|
115
|
+
onAuthCallback?: (provider: string, code: string, state: string) => Promise<void>;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Session token for authenticated requests
|
|
119
|
+
* Set automatically after OAuth flow completes
|
|
120
|
+
* Can be provided manually if you manage tokens externally
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* const client = createMCPClient({
|
|
125
|
+
* plugins: [githubPlugin({ ... })],
|
|
126
|
+
* sessionToken: 'existing-session-token'
|
|
127
|
+
* });
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
sessionToken?: string;
|
|
66
131
|
}
|
|
67
132
|
/**
|
|
68
133
|
* Helper type to infer enabled tools from plugins
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB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;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAAC,QAAQ,SAAS,SAAS,SAAS,EAAE,IACjE,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;AAEpC;;GAEG;AACH,MAAM,MAAM,gBAAgB,CAAC,QAAQ,SAAS,SAAS,SAAS,EAAE,IAAI;KACnE,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC;CAC/C,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,8 +2,12 @@
|
|
|
2
2
|
* Integrate SDK
|
|
3
3
|
* Type-safe TypeScript SDK for MCP Client
|
|
4
4
|
*/
|
|
5
|
-
export { MCPClient, createMCPClient } from "./client.js";
|
|
5
|
+
export { MCPClient, createMCPClient, clearClientCache } from "./client.js";
|
|
6
6
|
export type { ToolInvocationOptions } from "./client.js";
|
|
7
|
+
export { OAuthManager } from "./oauth/manager.js";
|
|
8
|
+
export { OAuthWindowManager, sendCallbackToOpener } from "./oauth/window-manager.js";
|
|
9
|
+
export { generateCodeVerifier, generateCodeChallenge, generateState } from "./oauth/pkce.js";
|
|
10
|
+
export type { OAuthFlowConfig, PopupOptions, AuthStatus, PendingAuth, AuthorizationUrlResponse, OAuthCallbackResponse, OAuthCallbackParams, } from "./oauth/types.js";
|
|
7
11
|
export type { MCPClientConfig, ReauthContext, ReauthHandler } from "./config/types.js";
|
|
8
12
|
export { IntegrateSDKError, AuthenticationError, AuthorizationError, TokenExpiredError, ConnectionError, ToolCallError, isAuthError, isTokenExpiredError, isAuthorizationError, parseServerError, } from "./errors.js";
|
|
9
13
|
export type { MCPPlugin, OAuthConfig, ExtractPluginIds, ExtractPluginTools, } from "./plugins/types.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC3E,YAAY,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAGzD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACrF,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC7F,YAAY,EACV,eAAe,EACf,YAAY,EACZ,UAAU,EACV,WAAW,EACX,wBAAwB,EACxB,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAG1B,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGvF,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,WAAW,EACX,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAGrB,YAAY,EACV,SAAS,EACT,WAAW,EACX,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,YAAY,EAAE,kBAAkB,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAE/F,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,YAAY,EAAE,iBAAiB,EAAE,UAAU,EAAE,iBAA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