integrate-sdk 0.1.2 → 0.1.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 CHANGED
@@ -1,19 +1,51 @@
1
1
  # Integrate SDK
2
2
 
3
- A type-safe TypeScript SDK for building MCP (Model Context Protocol) clients with plugin-based OAuth provider configuration.
3
+ 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, plugin-based API.
4
+
5
+ **Server:** `https://mcp.integrate.dev/api/v1/mcp`
6
+
7
+ ## Table of Contents
8
+
9
+ - [What is this SDK?](#what-is-this-sdk)
10
+ - [Features](#features)
11
+ - [Installation](#installation)
12
+ - [Quick Start](#quick-start)
13
+ - [Built-in Plugins](#built-in-plugins)
14
+ - [GitHub Plugin](#github-plugin)
15
+ - [Gmail Plugin](#gmail-plugin)
16
+ - [Creating Custom Plugins](#creating-custom-plugins)
17
+ - [Integration with Vercel AI SDK](#integration-with-vercel-ai-sdk)
18
+ - [Advanced Usage](#advanced-usage)
19
+ - [API Reference](#api-reference)
20
+ - [Architecture](#architecture)
21
+ - [How It Works](#how-it-works)
22
+
23
+ ## What is this SDK?
24
+
25
+ This SDK is a **client library** that connects to the Integrate MCP server to access various third-party integrations.
26
+
27
+ **Key concepts:**
28
+ 1. **Connect to the Integrate MCP server** - The SDK connects to `https://mcp.integrate.dev/api/v1/mcp`
29
+ 2. **Configure OAuth credentials** - You provide your own OAuth app credentials for each integration (GitHub, Gmail, etc.)
30
+ 3. **Call tools** - Execute actions like creating GitHub issues, sending emails, searching Notion pages
31
+ 4. **OAuth flow happens server-side** - The SDK sends your OAuth config to the server, which handles the actual authentication flow
32
+
33
+ **Important:** You need to create your own OAuth apps (e.g., GitHub OAuth app, Google OAuth app) and provide the credentials to the SDK. The SDK does not provide OAuth credentials.
4
34
 
5
35
  ## Features
6
36
 
7
- - 🔌 **Plugin-Based Architecture** - Enable only the tools you need with a BetterAuth-inspired plugin pattern
8
- - 🔒 **Type-Safe Configuration** - Full TypeScript support with IntelliSense for tools and configurations
9
- - 🌊 **HTTP Streaming** - Real-time bidirectional communication via HTTP streaming with newline-delimited JSON (NDJSON)
10
- - 🔐 **OAuth Support** - Built-in OAuth configuration for multiple providers
11
- - 🛠️ **Extensible** - Easy to create custom plugins for any OAuth provider or tool set
12
- - 📦 **Zero Dependencies** - Lightweight with no external runtime dependencies
37
+ - 🔌 **Plugin-Based Architecture** - Enable only the integrations you need
38
+ - 🔒 **Type-Safe** - Full TypeScript support with IntelliSense
39
+ - 🌊 **Real-time Communication** - HTTP streaming with NDJSON
40
+ - 🔐 **OAuth Ready** - Configure OAuth credentials for each provider
41
+ - 🛠️ **Extensible** - Create custom plugins for new integrations
42
+ - 📦 **Zero Dependencies** - Lightweight implementation
13
43
 
14
44
  ## Installation
15
45
 
16
46
  ```bash
47
+ npm install integrate-sdk
48
+ # or
17
49
  bun add integrate-sdk
18
50
  ```
19
51
 
@@ -133,10 +165,10 @@ const slackPlugin = genericOAuthPlugin({
133
165
  clientSecret: process.env.SLACK_CLIENT_SECRET!,
134
166
  scopes: ['chat:write', 'channels:read', 'users:read'],
135
167
  tools: [
136
- 'slack/sendMessage',
137
- 'slack/listChannels',
138
- 'slack/getChannel',
139
- 'slack/inviteUser',
168
+ 'slack_send_message',
169
+ 'slack_list_channels',
170
+ 'slack_get_channel',
171
+ 'slack_invite_user',
140
172
  ],
141
173
  redirectUri: 'https://your-app.com/callback',
142
174
  });
@@ -155,7 +187,7 @@ import { createSimplePlugin } from 'integrate-sdk';
155
187
 
156
188
  const mathPlugin = createSimplePlugin({
157
189
  id: 'math',
158
- tools: ['math/add', 'math/subtract', 'math/multiply', 'math/divide'],
190
+ tools: ['math_add', 'math_subtract', 'math_multiply', 'math_divide'],
159
191
  onInit: async (client) => {
160
192
  console.log('Math plugin initialized');
161
193
  },
@@ -170,7 +202,7 @@ import type { MCPPlugin } from 'integrate-sdk';
170
202
  export function customPlugin(config: CustomConfig): MCPPlugin {
171
203
  return {
172
204
  id: 'custom',
173
- tools: ['custom/tool1', 'custom/tool2'],
205
+ tools: ['custom_tool1', 'custom_tool2'],
174
206
  oauth: {
175
207
  provider: 'custom-provider',
176
208
  clientId: config.clientId,
@@ -198,6 +230,57 @@ export function customPlugin(config: CustomConfig): MCPPlugin {
198
230
  }
199
231
  ```
200
232
 
233
+ ## Integration with Vercel AI SDK
234
+
235
+ The SDK includes built-in support for Vercel's AI SDK, allowing you to give AI models access to all your integrations.
236
+
237
+ ### Quick Example
238
+
239
+ ```typescript
240
+ import { createMCPClient, githubPlugin, getVercelAITools } from 'integrate-sdk';
241
+ import { generateText } from 'ai';
242
+ import { openai } from '@ai-sdk/openai';
243
+
244
+ // 1. Create and connect MCP client
245
+ const mcpClient = createMCPClient({
246
+ plugins: [
247
+ githubPlugin({
248
+ clientId: process.env.GITHUB_CLIENT_ID!,
249
+ clientSecret: process.env.GITHUB_CLIENT_SECRET!,
250
+ }),
251
+ ],
252
+ });
253
+
254
+ await mcpClient.connect();
255
+
256
+ // 2. Get tools in Vercel AI SDK format
257
+ const tools = getVercelAITools(mcpClient);
258
+
259
+ // 3. Use with AI models
260
+ const result = await generateText({
261
+ model: openai('gpt-4'),
262
+ prompt: 'Create a GitHub issue titled "Bug in login" in myrepo',
263
+ tools,
264
+ maxToolRoundtrips: 5,
265
+ });
266
+
267
+ console.log(result.text);
268
+ ```
269
+
270
+ ### How It Works
271
+
272
+ 1. **`getVercelAITools(client)`** - Converts all enabled MCP tools to Vercel AI SDK format
273
+ 2. **Automatic execution** - When the AI calls a tool, it executes through your MCP client
274
+ 3. **Type-safe** - Full TypeScript support with proper types
275
+
276
+ ### Available Functions
277
+
278
+ - **`getVercelAITools(client)`** - Get all enabled tools in Vercel AI SDK format
279
+ - **`convertMCPToolsToVercelAI(client)`** - Same as above, alternative name
280
+ - **`convertMCPToolToVercelAI(tool, client)`** - Convert a single MCP tool
281
+
282
+ See `examples/vercel-ai-integration.ts` for a complete working example.
283
+
201
284
  ## Advanced Usage
202
285
 
203
286
  ### Accessing OAuth Configurations
@@ -345,29 +428,21 @@ The SDK uses HTTP streaming with newline-delimited JSON (NDJSON) for bidirection
345
428
  - Automatic heartbeat to keep connection alive
346
429
  - Compatible with MCP's `StreamableHTTPServer`
347
430
 
348
- ## MCP Server Requirements
349
-
350
- Your MCP server should implement HTTP streaming transport compatible with MCP's `StreamableHTTPServer`:
431
+ ## How It Works
351
432
 
352
- - A single streaming endpoint (e.g., `POST /api/v1/mcp`) that:
353
- - Accepts HTTP POST with streaming request body (NDJSON format)
354
- - Returns streaming response body (NDJSON format)
355
- - Supports bidirectional communication over a single persistent connection
356
- - Messages are newline-delimited JSON (one JSON object per line)
433
+ 1. **Client Configuration**: You configure the SDK with plugins for the integrations you want to use (GitHub, Gmail, etc.)
434
+ 2. **Connection**: The SDK connects to `https://mcp.integrate.dev/api/v1/mcp` using HTTP streaming (NDJSON)
435
+ 3. **Tool Discovery**: The SDK fetches available tools from the server and filters them based on your enabled plugins
436
+ 4. **OAuth Configuration**: Your OAuth credentials are stored in the client configuration (not sent to the server yet)
437
+ 5. **Tool Calls**: When you call a tool, the SDK sends a JSON-RPC request to the server
438
+ 6. **OAuth Flow**: The server uses your OAuth configuration to authenticate and execute the tool
357
439
 
358
- And support these MCP protocol methods:
359
- - `initialize` - Initialize the protocol connection
360
- - `tools/list` - List available tools
361
- - `tools/call` - Invoke a tool
440
+ ## Server Information
362
441
 
363
- **Example Go server setup:**
364
- ```go
365
- httpServer := server.NewStreamableHTTPServer(s,
366
- server.WithEndpointPath("/api/v1/mcp"),
367
- server.WithHeartbeatInterval(30*time.Second),
368
- server.WithStateLess(false),
369
- )
370
- ```
442
+ **Endpoint:** `https://mcp.integrate.dev/api/v1/mcp`
443
+ **Protocol:** MCP (Model Context Protocol) over HTTP streaming
444
+ **Format:** Newline-delimited JSON (NDJSON)
445
+ **Methods:** `initialize`, `tools/list`, `tools/call`
371
446
 
372
447
  ## TypeScript Support
373
448
 
@@ -394,9 +469,9 @@ const result: MCPToolCallResponse = await client.callTool('github_create_issue',
394
469
  });
395
470
  ```
396
471
 
397
- # Test Suite
472
+ ## Contributing
398
473
 
399
- Comprehensive test suite for the Integrate SDK.
474
+ Contributions are welcome! Please see the tests in the `tests/` directory for examples of how to test new features.
400
475
 
401
476
  ## Test Structure
402
477
 
package/dist/index.d.ts CHANGED
@@ -12,6 +12,8 @@ export { gmailPlugin } from "./plugins/gmail.js";
12
12
  export type { GmailPluginConfig, GmailTools } from "./plugins/gmail.js";
13
13
  export { genericOAuthPlugin, createSimplePlugin, } from "./plugins/generic.js";
14
14
  export type { GenericOAuthPluginConfig } from "./plugins/generic.js";
15
+ export { convertMCPToolToVercelAI, convertMCPToolsToVercelAI, getVercelAITools, } from "./integrations/vercel-ai.js";
16
+ export type { VercelAITool } from "./integrations/vercel-ai.js";
15
17
  export type { JSONRPCRequest, JSONRPCResponse, JSONRPCSuccessResponse, JSONRPCErrorResponse, JSONRPCNotification, MCPTool, MCPToolsListResponse, MCPToolCallParams, MCPToolCallResponse, MCPInitializeParams, MCPInitializeResponse, } from "./protocol/messages.js";
16
18
  export { MCPMethod } from "./protocol/messages.js";
17
19
  export { HttpSessionTransport } from "./transport/http-session.js";
@@ -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;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,qB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CAAC;AAC9B,YAAY,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAGrE,OAAO,EACL,wBAAwB,EACxB,yBAAyB,EACzB,gBAAgB,GACjB,MAAM,6BAA6B,CAAC;AACrC,YAAY,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAGhE,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 CHANGED
@@ -431,12 +431,40 @@ function createSimplePlugin(config) {
431
431
  onDisconnect: config.onDisconnect
432
432
  };
433
433
  }
434
+ // src/integrations/vercel-ai.ts
435
+ function convertMCPSchemaToParameters(inputSchema) {
436
+ return inputSchema;
437
+ }
438
+ function convertMCPToolToVercelAI(mcpTool, client) {
439
+ return {
440
+ description: mcpTool.description || `Execute ${mcpTool.name}`,
441
+ parameters: convertMCPSchemaToParameters(mcpTool.inputSchema),
442
+ execute: async (args) => {
443
+ const result = await client.callTool(mcpTool.name, args);
444
+ return result;
445
+ }
446
+ };
447
+ }
448
+ function convertMCPToolsToVercelAI(client) {
449
+ const mcpTools = client.getEnabledTools();
450
+ const vercelTools = {};
451
+ for (const mcpTool of mcpTools) {
452
+ vercelTools[mcpTool.name] = convertMCPToolToVercelAI(mcpTool, client);
453
+ }
454
+ return vercelTools;
455
+ }
456
+ function getVercelAITools(client) {
457
+ return convertMCPToolsToVercelAI(client);
458
+ }
434
459
  export {
435
460
  gmailPlugin,
436
461
  githubPlugin,
462
+ getVercelAITools,
437
463
  genericOAuthPlugin,
438
464
  createSimplePlugin,
439
465
  createMCPClient,
466
+ convertMCPToolsToVercelAI,
467
+ convertMCPToolToVercelAI,
440
468
  MCPMethod,
441
469
  MCPClient,
442
470
  HttpSessionTransport
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Vercel AI SDK Integration
3
+ *
4
+ * Helper functions to convert MCP tools to Vercel AI SDK format
5
+ */
6
+ import type { MCPClient } from "../client.js";
7
+ import type { MCPTool } from "../protocol/messages.js";
8
+ /**
9
+ * Tool definition for Vercel AI SDK
10
+ */
11
+ export interface VercelAITool {
12
+ description: string;
13
+ parameters: Record<string, unknown>;
14
+ execute: (args: Record<string, unknown>) => Promise<unknown>;
15
+ }
16
+ /**
17
+ * Convert a single MCP tool to Vercel AI SDK format
18
+ *
19
+ * @param mcpTool - The MCP tool definition
20
+ * @param client - The MCP client instance (used for executing the tool)
21
+ * @returns Vercel AI SDK compatible tool definition
22
+ */
23
+ export declare function convertMCPToolToVercelAI(mcpTool: MCPTool, client: MCPClient): VercelAITool;
24
+ /**
25
+ * Convert all enabled MCP tools to Vercel AI SDK format
26
+ *
27
+ * @param client - The MCP client instance (must be connected)
28
+ * @returns Object mapping tool names to Vercel AI SDK tool definitions
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * import { createMCPClient, githubPlugin } from 'integrate-sdk';
33
+ * import { convertMCPToolsToVercelAI } from 'integrate-sdk/vercel-ai';
34
+ * import { generateText } from 'ai';
35
+ *
36
+ * const mcpClient = createMCPClient({
37
+ * plugins: [githubPlugin({ clientId: '...', clientSecret: '...' })],
38
+ * });
39
+ *
40
+ * await mcpClient.connect();
41
+ *
42
+ * const tools = convertMCPToolsToVercelAI(mcpClient);
43
+ *
44
+ * const result = await generateText({
45
+ * model: openai('gpt-4'),
46
+ * prompt: 'Create a GitHub issue in my repo',
47
+ * tools,
48
+ * });
49
+ * ```
50
+ */
51
+ export declare function convertMCPToolsToVercelAI(client: MCPClient): Record<string, VercelAITool>;
52
+ /**
53
+ * Get tools in a format compatible with Vercel AI SDK's tools parameter
54
+ *
55
+ * This is an alternative that returns the tools in the exact format expected by ai.generateText()
56
+ *
57
+ * @param client - The MCP client instance (must be connected)
58
+ * @returns Tools object ready to pass to generateText({ tools: ... })
59
+ */
60
+ export declare function getVercelAITools(client: MCPClient): Record<string, VercelAITool>;
61
+ //# sourceMappingURL=vercel-ai.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vercel-ai.d.ts","sourceRoot":"","sources":["../../src/integrations/vercel-ai.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAC9D;AAcD;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,SAAS,GAChB,YAAY,CASd;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,SAAS,GAChB,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAS9B;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,gCAEjD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "integrate-sdk",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Type-safe TypeScript SDK for MCP Client with plugin-based OAuth provider configuration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -28,11 +28,11 @@
28
28
  "build:types": "tsc --emitDeclarationOnly --declaration --declarationMap",
29
29
  "dev": "bun --watch src/index.ts",
30
30
  "type-check": "tsc --noEmit",
31
- "test": "bun test tests/protocol tests/plugins tests/client tests/integration/simple-integration.test.ts",
32
- "test:watch": "bun test --watch tests/protocol tests/plugins tests/client tests/integration/simple-integration.test.ts",
33
- "test:unit": "bun test tests/protocol tests/plugins tests/client",
31
+ "test": "bun test tests/protocol tests/plugins tests/client tests/integrations tests/integration/simple-integration.test.ts",
32
+ "test:watch": "bun test --watch tests/protocol tests/plugins tests/client tests/integrations tests/integration/simple-integration.test.ts",
33
+ "test:unit": "bun test tests/protocol tests/plugins tests/client tests/integrations",
34
34
  "test:integration": "bun test tests/integration/simple-integration.test.ts",
35
- "test:coverage": "bun test --coverage tests/protocol tests/plugins tests/client tests/integration/simple-integration.test.ts"
35
+ "test:coverage": "bun test --coverage tests/protocol tests/plugins tests/client tests/integrations tests/integration/simple-integration.test.ts"
36
36
  },
37
37
  "keywords": [
38
38
  "mcp",