integrate-sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,108 @@
1
+ /**
2
+ * MCP Client
3
+ * Main client class that orchestrates transport, protocol, and plugins
4
+ */
5
+ import type { MCPTool, MCPToolCallResponse } from "./protocol/messages.js";
6
+ import type { MCPPlugin, OAuthConfig } from "./plugins/types.js";
7
+ import type { MCPClientConfig } from "./config/types.js";
8
+ /**
9
+ * Tool invocation options
10
+ */
11
+ export interface ToolInvocationOptions {
12
+ /** Tool name */
13
+ name: string;
14
+ /** Tool arguments */
15
+ arguments?: Record<string, unknown>;
16
+ }
17
+ /**
18
+ * MCP Client Class
19
+ *
20
+ * Provides type-safe access to MCP server tools with plugin-based configuration
21
+ */
22
+ export declare class MCPClient<TPlugins extends readonly MCPPlugin[] = readonly MCPPlugin[]> {
23
+ private transport;
24
+ private plugins;
25
+ private availableTools;
26
+ private enabledToolNames;
27
+ private initialized;
28
+ private clientInfo;
29
+ constructor(config: MCPClientConfig<TPlugins>);
30
+ /**
31
+ * Initialize all plugins
32
+ */
33
+ private initializePlugins;
34
+ /**
35
+ * Connect to the MCP server
36
+ */
37
+ connect(): Promise<void>;
38
+ /**
39
+ * Initialize the MCP protocol
40
+ */
41
+ private initialize;
42
+ /**
43
+ * Discover available tools from the server
44
+ */
45
+ private discoverTools;
46
+ /**
47
+ * Call a tool by name
48
+ */
49
+ callTool(name: string, args?: Record<string, unknown>): Promise<MCPToolCallResponse>;
50
+ /**
51
+ * Get a tool by name
52
+ */
53
+ getTool(name: string): MCPTool | undefined;
54
+ /**
55
+ * Get all available tools
56
+ */
57
+ getAvailableTools(): MCPTool[];
58
+ /**
59
+ * Get all enabled tools (filtered by plugins)
60
+ */
61
+ getEnabledTools(): MCPTool[];
62
+ /**
63
+ * Get OAuth configuration for a plugin
64
+ */
65
+ getOAuthConfig(pluginId: string): OAuthConfig | undefined;
66
+ /**
67
+ * Get all OAuth configurations
68
+ */
69
+ getAllOAuthConfigs(): Map<string, OAuthConfig>;
70
+ /**
71
+ * Register a message handler
72
+ */
73
+ onMessage(handler: (message: unknown) => void): () => void;
74
+ /**
75
+ * Disconnect from the server
76
+ */
77
+ disconnect(): Promise<void>;
78
+ /**
79
+ * Check if client is connected
80
+ */
81
+ isConnected(): boolean;
82
+ /**
83
+ * Check if client is initialized
84
+ */
85
+ isInitialized(): boolean;
86
+ }
87
+ /**
88
+ * Create a new MCP Client instance
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * const client = createMCPClient({
93
+ * serverUrl: 'http://localhost:3000/mcp',
94
+ * plugins: [
95
+ * githubPlugin({ clientId: '...', clientSecret: '...' }),
96
+ * gmailPlugin({ clientId: '...', clientSecret: '...' }),
97
+ * ],
98
+ * });
99
+ *
100
+ * await client.connect();
101
+ * const result = await client.callTool('github/createIssue', {
102
+ * repo: 'owner/repo',
103
+ * title: 'Bug report',
104
+ * });
105
+ * ```
106
+ */
107
+ export declare function createMCPClient<TPlugins extends readonly MCPPlugin[]>(config: MCPClientConfig<TPlugins>): MCPClient<TPlugins>;
108
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +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,EAAE,MAAM,mBAAmB,CAAC;AAEzD;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,gBAAgB;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,qBAAqB;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC;AAED;;;;GAIG;AACH,qBAAa,SAAS,CAAC,QAAQ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Q,CAAC,GAChC,SAAS,CAAC,QAAQ,CAAC,CAErB"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Configuration Types
3
+ * Type-safe configuration with inference
4
+ */
5
+ import type { MCPPlugin } from "../plugins/types.js";
6
+ /**
7
+ * Main client configuration
8
+ */
9
+ export interface MCPClientConfig<TPlugins extends readonly MCPPlugin[]> {
10
+ /** URL of the MCP server */
11
+ serverUrl: string;
12
+ /** Array of plugins to enable */
13
+ plugins: TPlugins;
14
+ /** Optional HTTP headers to include in requests */
15
+ headers?: Record<string, string>;
16
+ /** Request timeout in milliseconds (default: 30000) */
17
+ timeout?: number;
18
+ /** Client information */
19
+ clientInfo?: {
20
+ name: string;
21
+ version: string;
22
+ };
23
+ }
24
+ /**
25
+ * Helper type to infer enabled tools from plugins
26
+ */
27
+ export type InferEnabledTools<TPlugins extends readonly MCPPlugin[]> = TPlugins[number]["tools"][number];
28
+ /**
29
+ * Helper type to create a tools object type from plugin array
30
+ */
31
+ export type InferToolsObject<TPlugins extends readonly MCPPlugin[]> = {
32
+ [K in TPlugins[number] as K["id"]]: K["tools"];
33
+ };
34
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +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,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,QAAQ,SAAS,SAAS,SAAS,EAAE;IACpE,4BAA4B;IAC5B,SAAS,EAAE,MAAM,CAAC;IAElB,iCAAiC;IACjC,OAAO,EAAE,QAAQ,CAAC;IAElB,mDAAmD;IACnD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEjC,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,yBAAyB;IACzB,UAAU,CAAC,EAAE;QACX,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH;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"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Integrate SDK
3
+ * Type-safe TypeScript SDK for MCP Client
4
+ */
5
+ export { MCPClient, createMCPClient } from "./client.js";
6
+ export type { ToolInvocationOptions } from "./client.js";
7
+ export type { MCPClientConfig } from "./config/types.js";
8
+ export type { MCPPlugin, OAuthConfig, ExtractPluginIds, ExtractPluginTools, } from "./plugins/types.js";
9
+ export { githubPlugin } from "./plugins/github.js";
10
+ export type { GitHubPluginConfig, GitHubTools } from "./plugins/github.js";
11
+ export { gmailPlugin } from "./plugins/gmail.js";
12
+ export type { GmailPluginConfig, GmailTools } from "./plugins/gmail.js";
13
+ export { genericOAuthPlugin, createSimplePlugin, } from "./plugins/generic.js";
14
+ export type { GenericOAuthPluginConfig } from "./plugins/generic.js";
15
+ export type { JSONRPCRequest, JSONRPCResponse, JSONRPCSuccessResponse, JSONRPCErrorResponse, JSONRPCNotification, MCPTool, MCPToolsListResponse, MCPToolCallParams, MCPToolCallResponse, MCPInitializeParams, MCPInitializeResponse, } from "./protocol/messages.js";
16
+ export { MCPMethod } from "./protocol/messages.js";
17
+ export { HttpSessionTransport } from "./transport/http-session.js";
18
+ export type { MessageHandler, HttpSessionTransportOptions, } from "./transport/http-session.js";
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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;AACzD,YAAY,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAGzD,YAAY,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGzD,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,MAAM,qBAAqB,CAAC;AAE3E,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,YAAY,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAExE,OAAO,EACL,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAGrE,YAAY,EACV,cAAc,EACd,eAAe,EACf,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,EACnB,OAAO,EACP,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAGnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,YAAY,EACV,cAAc,EACd,2BAA2B,GAC5B,MAAM,6BAA6B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,440 @@
1
+ // src/protocol/jsonrpc.ts
2
+ function parseMessage(message) {
3
+ try {
4
+ return JSON.parse(message);
5
+ } catch (error) {
6
+ throw new Error(`Failed to parse JSON-RPC message: ${error}`);
7
+ }
8
+ }
9
+
10
+ // src/transport/http-session.ts
11
+ class HttpSessionTransport {
12
+ url;
13
+ headers;
14
+ timeout;
15
+ messageHandlers = new Set;
16
+ sessionId;
17
+ sseController;
18
+ connected = false;
19
+ constructor(options) {
20
+ this.url = options.url;
21
+ this.headers = options.headers || {};
22
+ this.timeout = options.timeout || 30000;
23
+ }
24
+ async connect() {
25
+ if (this.connected) {
26
+ return;
27
+ }
28
+ this.connected = true;
29
+ }
30
+ async sendRequest(method, params) {
31
+ if (!this.connected) {
32
+ throw new Error("Not connected to server");
33
+ }
34
+ const request = {
35
+ jsonrpc: "2.0",
36
+ id: Date.now() + Math.random(),
37
+ method,
38
+ params
39
+ };
40
+ const headers = {
41
+ ...this.headers,
42
+ "Content-Type": "application/json"
43
+ };
44
+ if (this.sessionId) {
45
+ headers["mcp-session-id"] = this.sessionId;
46
+ }
47
+ try {
48
+ const controller = new AbortController;
49
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
50
+ const response = await fetch(this.url, {
51
+ method: "POST",
52
+ headers,
53
+ body: JSON.stringify(request),
54
+ signal: controller.signal
55
+ });
56
+ clearTimeout(timeoutId);
57
+ if (!response.ok) {
58
+ throw new Error(`Request failed: ${response.statusText}`);
59
+ }
60
+ if (!this.sessionId) {
61
+ const sid = response.headers.get("mcp-session-id");
62
+ if (sid) {
63
+ this.sessionId = sid;
64
+ console.log("Session established:", sid);
65
+ this.startSSEListener();
66
+ }
67
+ }
68
+ const jsonResponse = await response.json();
69
+ if ("error" in jsonResponse) {
70
+ throw new Error(`JSON-RPC Error ${jsonResponse.error.code}: ${jsonResponse.error.message}`);
71
+ }
72
+ return jsonResponse.result;
73
+ } catch (error) {
74
+ throw error;
75
+ }
76
+ }
77
+ async startSSEListener() {
78
+ if (!this.sessionId || this.sseController) {
79
+ return;
80
+ }
81
+ this.sseController = new AbortController;
82
+ try {
83
+ const response = await fetch(this.url, {
84
+ method: "GET",
85
+ headers: {
86
+ ...this.headers,
87
+ Accept: "text/event-stream",
88
+ "mcp-session-id": this.sessionId
89
+ },
90
+ signal: this.sseController.signal
91
+ });
92
+ if (!response.ok || !response.body) {
93
+ return;
94
+ }
95
+ this.processSSEStream(response.body);
96
+ } catch (error) {
97
+ if (error instanceof Error && error.name === "AbortError") {
98
+ return;
99
+ }
100
+ console.error("SSE connection error:", error);
101
+ }
102
+ }
103
+ async processSSEStream(body) {
104
+ const reader = body.getReader();
105
+ const decoder = new TextDecoder;
106
+ let buffer = "";
107
+ try {
108
+ while (true) {
109
+ const { done, value } = await reader.read();
110
+ if (done)
111
+ break;
112
+ buffer += decoder.decode(value, { stream: true });
113
+ const lines = buffer.split(`
114
+ `);
115
+ buffer = lines.pop() || "";
116
+ for (const line of lines) {
117
+ if (line.startsWith("data: ")) {
118
+ const data = line.slice(6).trim();
119
+ if (data) {
120
+ this.handleNotification(data);
121
+ }
122
+ }
123
+ }
124
+ }
125
+ } catch (error) {
126
+ if (error instanceof Error && error.name === "AbortError") {
127
+ return;
128
+ }
129
+ console.error("SSE stream error:", error);
130
+ } finally {
131
+ reader.releaseLock();
132
+ }
133
+ }
134
+ handleNotification(data) {
135
+ try {
136
+ const message = parseMessage(data);
137
+ this.messageHandlers.forEach((handler) => {
138
+ try {
139
+ handler(message);
140
+ } catch (error) {
141
+ console.error("Error in message handler:", error);
142
+ }
143
+ });
144
+ } catch (error) {
145
+ console.error("Failed to parse notification:", error);
146
+ }
147
+ }
148
+ onMessage(handler) {
149
+ this.messageHandlers.add(handler);
150
+ return () => {
151
+ this.messageHandlers.delete(handler);
152
+ };
153
+ }
154
+ async disconnect() {
155
+ if (!this.connected) {
156
+ return;
157
+ }
158
+ if (this.sseController) {
159
+ this.sseController.abort();
160
+ this.sseController = undefined;
161
+ }
162
+ this.messageHandlers.clear();
163
+ this.sessionId = undefined;
164
+ this.connected = false;
165
+ }
166
+ isConnected() {
167
+ return this.connected;
168
+ }
169
+ getSessionId() {
170
+ return this.sessionId;
171
+ }
172
+ }
173
+
174
+ // src/protocol/messages.ts
175
+ var MCPMethod;
176
+ ((MCPMethod2) => {
177
+ MCPMethod2["INITIALIZE"] = "initialize";
178
+ MCPMethod2["TOOLS_LIST"] = "tools/list";
179
+ MCPMethod2["TOOLS_CALL"] = "tools/call";
180
+ MCPMethod2["RESOURCES_LIST"] = "resources/list";
181
+ MCPMethod2["RESOURCES_READ"] = "resources/read";
182
+ MCPMethod2["PROMPTS_LIST"] = "prompts/list";
183
+ MCPMethod2["PROMPTS_GET"] = "prompts/get";
184
+ })(MCPMethod ||= {});
185
+
186
+ // src/client.ts
187
+ class MCPClient {
188
+ transport;
189
+ plugins;
190
+ availableTools = new Map;
191
+ enabledToolNames = new Set;
192
+ initialized = false;
193
+ clientInfo;
194
+ constructor(config) {
195
+ this.transport = new HttpSessionTransport({
196
+ url: config.serverUrl,
197
+ headers: config.headers,
198
+ timeout: config.timeout
199
+ });
200
+ this.plugins = config.plugins;
201
+ this.clientInfo = config.clientInfo || {
202
+ name: "integrate-sdk",
203
+ version: "0.1.0"
204
+ };
205
+ for (const plugin of this.plugins) {
206
+ for (const toolName of plugin.tools) {
207
+ this.enabledToolNames.add(toolName);
208
+ }
209
+ }
210
+ this.initializePlugins();
211
+ }
212
+ async initializePlugins() {
213
+ for (const plugin of this.plugins) {
214
+ if (plugin.onInit) {
215
+ await plugin.onInit(this);
216
+ }
217
+ }
218
+ }
219
+ async connect() {
220
+ for (const plugin of this.plugins) {
221
+ if (plugin.onBeforeConnect) {
222
+ await plugin.onBeforeConnect(this);
223
+ }
224
+ }
225
+ await this.transport.connect();
226
+ await this.initialize();
227
+ await this.discoverTools();
228
+ for (const plugin of this.plugins) {
229
+ if (plugin.onAfterConnect) {
230
+ await plugin.onAfterConnect(this);
231
+ }
232
+ }
233
+ }
234
+ async initialize() {
235
+ const params = {
236
+ protocolVersion: "2024-11-05",
237
+ capabilities: {
238
+ tools: {}
239
+ },
240
+ clientInfo: this.clientInfo
241
+ };
242
+ const response = await this.transport.sendRequest("initialize" /* INITIALIZE */, params);
243
+ this.initialized = true;
244
+ return response;
245
+ }
246
+ async discoverTools() {
247
+ const response = await this.transport.sendRequest("tools/list" /* TOOLS_LIST */);
248
+ for (const tool of response.tools) {
249
+ this.availableTools.set(tool.name, tool);
250
+ }
251
+ const enabledTools = response.tools.filter((tool) => this.enabledToolNames.has(tool.name));
252
+ console.log(`Discovered ${response.tools.length} tools, ${enabledTools.length} enabled by plugins`);
253
+ }
254
+ async callTool(name, args) {
255
+ if (!this.initialized) {
256
+ throw new Error("Client not initialized. Call connect() first.");
257
+ }
258
+ if (!this.enabledToolNames.has(name)) {
259
+ throw new Error(`Tool "${name}" is not enabled. Enable it by adding the appropriate plugin.`);
260
+ }
261
+ if (!this.availableTools.has(name)) {
262
+ throw new Error(`Tool "${name}" is not available on the server. Available tools: ${Array.from(this.availableTools.keys()).join(", ")}`);
263
+ }
264
+ const params = {
265
+ name,
266
+ arguments: args
267
+ };
268
+ return await this.transport.sendRequest("tools/call" /* TOOLS_CALL */, params);
269
+ }
270
+ getTool(name) {
271
+ return this.availableTools.get(name);
272
+ }
273
+ getAvailableTools() {
274
+ return Array.from(this.availableTools.values());
275
+ }
276
+ getEnabledTools() {
277
+ return Array.from(this.availableTools.values()).filter((tool) => this.enabledToolNames.has(tool.name));
278
+ }
279
+ getOAuthConfig(pluginId) {
280
+ const plugin = this.plugins.find((p) => p.id === pluginId);
281
+ return plugin?.oauth;
282
+ }
283
+ getAllOAuthConfigs() {
284
+ const configs = new Map;
285
+ for (const plugin of this.plugins) {
286
+ if (plugin.oauth) {
287
+ configs.set(plugin.id, plugin.oauth);
288
+ }
289
+ }
290
+ return configs;
291
+ }
292
+ onMessage(handler) {
293
+ return this.transport.onMessage(handler);
294
+ }
295
+ async disconnect() {
296
+ for (const plugin of this.plugins) {
297
+ if (plugin.onDisconnect) {
298
+ await plugin.onDisconnect(this);
299
+ }
300
+ }
301
+ await this.transport.disconnect();
302
+ this.initialized = false;
303
+ }
304
+ isConnected() {
305
+ return this.transport.isConnected();
306
+ }
307
+ isInitialized() {
308
+ return this.initialized;
309
+ }
310
+ }
311
+ function createMCPClient(config) {
312
+ return new MCPClient(config);
313
+ }
314
+ // src/plugins/github.ts
315
+ var GITHUB_TOOLS = [
316
+ "github/createIssue",
317
+ "github/listIssues",
318
+ "github/getIssue",
319
+ "github/updateIssue",
320
+ "github/closeIssue",
321
+ "github/createPullRequest",
322
+ "github/listPullRequests",
323
+ "github/getPullRequest",
324
+ "github/mergePullRequest",
325
+ "github/listRepositories",
326
+ "github/getRepository",
327
+ "github/createRepository",
328
+ "github/listBranches",
329
+ "github/createBranch",
330
+ "github/getUser",
331
+ "github/listCommits",
332
+ "github/getCommit"
333
+ ];
334
+ function githubPlugin(config) {
335
+ const oauth = {
336
+ provider: "github",
337
+ clientId: config.clientId,
338
+ clientSecret: config.clientSecret,
339
+ scopes: config.scopes || ["repo", "user"],
340
+ redirectUri: config.redirectUri,
341
+ config: {
342
+ apiBaseUrl: config.apiBaseUrl || "https://api.github.com",
343
+ ...config
344
+ }
345
+ };
346
+ return {
347
+ id: "github",
348
+ tools: [...GITHUB_TOOLS],
349
+ oauth,
350
+ async onInit(_client) {
351
+ console.log("GitHub plugin initialized");
352
+ },
353
+ async onAfterConnect(_client) {
354
+ console.log("GitHub plugin connected");
355
+ }
356
+ };
357
+ }
358
+ // src/plugins/gmail.ts
359
+ var GMAIL_TOOLS = [
360
+ "gmail/sendEmail",
361
+ "gmail/listEmails",
362
+ "gmail/getEmail",
363
+ "gmail/deleteEmail",
364
+ "gmail/searchEmails",
365
+ "gmail/markAsRead",
366
+ "gmail/markAsUnread",
367
+ "gmail/addLabel",
368
+ "gmail/removeLabel",
369
+ "gmail/listLabels",
370
+ "gmail/createLabel",
371
+ "gmail/getDraft",
372
+ "gmail/createDraft",
373
+ "gmail/updateDraft",
374
+ "gmail/deleteDraft",
375
+ "gmail/sendDraft"
376
+ ];
377
+ function gmailPlugin(config) {
378
+ const oauth = {
379
+ provider: "google",
380
+ clientId: config.clientId,
381
+ clientSecret: config.clientSecret,
382
+ scopes: config.scopes || [
383
+ "https://www.googleapis.com/auth/gmail.send",
384
+ "https://www.googleapis.com/auth/gmail.readonly",
385
+ "https://www.googleapis.com/auth/gmail.modify",
386
+ "https://www.googleapis.com/auth/gmail.labels"
387
+ ],
388
+ redirectUri: config.redirectUri,
389
+ config
390
+ };
391
+ return {
392
+ id: "gmail",
393
+ tools: [...GMAIL_TOOLS],
394
+ oauth,
395
+ async onInit(_client) {
396
+ console.log("Gmail plugin initialized");
397
+ },
398
+ async onAfterConnect(_client) {
399
+ console.log("Gmail plugin connected");
400
+ }
401
+ };
402
+ }
403
+ // src/plugins/generic.ts
404
+ function genericOAuthPlugin(config) {
405
+ const oauth = {
406
+ provider: config.provider,
407
+ clientId: config.clientId,
408
+ clientSecret: config.clientSecret,
409
+ scopes: config.scopes,
410
+ redirectUri: config.redirectUri,
411
+ config
412
+ };
413
+ return {
414
+ id: config.id,
415
+ tools: config.tools,
416
+ oauth,
417
+ onInit: config.onInit,
418
+ onAfterConnect: config.onAfterConnect,
419
+ onDisconnect: config.onDisconnect
420
+ };
421
+ }
422
+ function createSimplePlugin(config) {
423
+ return {
424
+ id: config.id,
425
+ tools: config.tools,
426
+ onInit: config.onInit,
427
+ onAfterConnect: config.onAfterConnect,
428
+ onDisconnect: config.onDisconnect
429
+ };
430
+ }
431
+ export {
432
+ gmailPlugin,
433
+ githubPlugin,
434
+ genericOAuthPlugin,
435
+ createSimplePlugin,
436
+ createMCPClient,
437
+ MCPMethod,
438
+ MCPClient,
439
+ HttpSessionTransport
440
+ };
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Generic OAuth Plugin
3
+ * Template for creating custom OAuth provider plugins
4
+ */
5
+ import type { MCPPlugin } from "./types.js";
6
+ /**
7
+ * Generic OAuth plugin configuration
8
+ */
9
+ export interface GenericOAuthPluginConfig {
10
+ /** Plugin unique identifier */
11
+ id: string;
12
+ /** OAuth provider name */
13
+ provider: string;
14
+ /** OAuth client ID */
15
+ clientId: string;
16
+ /** OAuth client secret */
17
+ clientSecret: string;
18
+ /** OAuth scopes */
19
+ scopes: string[];
20
+ /** Tool names to enable */
21
+ tools: string[];
22
+ /** OAuth redirect URI */
23
+ redirectUri?: string;
24
+ /** Additional provider-specific configuration */
25
+ config?: Record<string, unknown>;
26
+ /** Optional initialization callback */
27
+ onInit?: (client: any) => Promise<void> | void;
28
+ /** Optional after connect callback */
29
+ onAfterConnect?: (client: any) => Promise<void> | void;
30
+ /** Optional disconnect callback */
31
+ onDisconnect?: (client: any) => Promise<void> | void;
32
+ }
33
+ /**
34
+ * Generic OAuth Plugin
35
+ *
36
+ * Use this to create custom plugins for any OAuth provider
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * const slackPlugin = genericOAuthPlugin({
41
+ * id: 'slack',
42
+ * provider: 'slack',
43
+ * clientId: process.env.SLACK_CLIENT_ID!,
44
+ * clientSecret: process.env.SLACK_CLIENT_SECRET!,
45
+ * scopes: ['chat:write', 'channels:read'],
46
+ * tools: [
47
+ * 'slack/sendMessage',
48
+ * 'slack/listChannels',
49
+ * 'slack/getChannel',
50
+ * ],
51
+ * });
52
+ *
53
+ * const client = createMCPClient({
54
+ * serverUrl: 'http://localhost:3000/mcp',
55
+ * plugins: [slackPlugin],
56
+ * });
57
+ * ```
58
+ */
59
+ export declare function genericOAuthPlugin(config: GenericOAuthPluginConfig): MCPPlugin<GenericOAuthPluginConfig>;
60
+ /**
61
+ * Create a simple plugin without OAuth
62
+ * Useful for plugins that just enable certain tools without authentication
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const mathPlugin = createSimplePlugin({
67
+ * id: 'math',
68
+ * tools: ['math/add', 'math/subtract', 'math/multiply', 'math/divide'],
69
+ * });
70
+ * ```
71
+ */
72
+ export declare function createSimplePlugin(config: {
73
+ id: string;
74
+ tools: string[];
75
+ onInit?: (client: any) => Promise<void> | void;
76
+ onAfterConnect?: (client: any) => Promise<void> | void;
77
+ onDisconnect?: (client: any) => Promise<void> | void;
78
+ }): MCPPlugin;
79
+ //#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