integrate-sdk 0.1.5 → 0.2.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.
- package/LICENSE +1 -1
- package/README.md +114 -584
- package/dist/client.d.ts +88 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/config/types.d.ts +45 -0
- package/dist/config/types.d.ts.map +1 -1
- package/dist/errors.d.ts +67 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +336 -7
- package/dist/integrations/vercel-ai.d.ts +1 -1
- package/dist/integrations/vercel-ai.d.ts.map +1 -1
- package/dist/plugins/generic.d.ts +17 -10
- package/dist/plugins/generic.d.ts.map +1 -1
- package/dist/plugins/github-client.d.ts +320 -0
- package/dist/plugins/github-client.d.ts.map +1 -0
- package/dist/plugins/github.d.ts +4 -1
- package/dist/plugins/github.d.ts.map +1 -1
- package/dist/plugins/gmail-client.d.ts +200 -0
- package/dist/plugins/gmail-client.d.ts.map +1 -0
- package/dist/plugins/gmail.d.ts +4 -1
- package/dist/plugins/gmail.d.ts.map +1 -1
- package/dist/plugins/server-client.d.ts +18 -0
- package/dist/plugins/server-client.d.ts.map +1 -0
- package/dist/plugins/types.d.ts +4 -4
- package/dist/plugins/types.d.ts.map +1 -1
- package/dist/transport/http-session.d.ts.map +1 -1
- package/dist/utils/naming.d.ts +37 -0
- package/dist/utils/naming.d.ts.map +1 -0
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -6,43 +6,16 @@
|
|
|
6
6
|
|
|
7
7
|
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.
|
|
8
8
|
|
|
9
|
-
**Server:** `https://mcp.integrate.dev/api/v1/mcp`
|
|
10
|
-
|
|
11
|
-
## Table of Contents
|
|
12
|
-
|
|
13
|
-
- [What is this SDK?](#what-is-this-sdk)
|
|
14
|
-
- [Features](#features)
|
|
15
|
-
- [Installation](#installation)
|
|
16
|
-
- [Quick Start](#quick-start)
|
|
17
|
-
- [Built-in Plugins](#built-in-plugins)
|
|
18
|
-
- [GitHub Plugin](#github-plugin)
|
|
19
|
-
- [Gmail Plugin](#gmail-plugin)
|
|
20
|
-
- [Creating Custom Plugins](#creating-custom-plugins)
|
|
21
|
-
- [Integration with Vercel AI SDK](#integration-with-vercel-ai-sdk)
|
|
22
|
-
- [Advanced Usage](#advanced-usage)
|
|
23
|
-
- [API Reference](#api-reference)
|
|
24
|
-
- [Architecture](#architecture)
|
|
25
|
-
- [How It Works](#how-it-works)
|
|
26
|
-
|
|
27
|
-
## What is this SDK?
|
|
28
|
-
|
|
29
|
-
This SDK is a **client library** that connects to the Integrate MCP server to access various third-party integrations.
|
|
30
|
-
|
|
31
|
-
**Key concepts:**
|
|
32
|
-
1. **Connect to the Integrate MCP server** - The SDK connects to `https://mcp.integrate.dev/api/v1/mcp`
|
|
33
|
-
2. **Configure OAuth credentials** - You provide your own OAuth app credentials for each integration (GitHub, Gmail, etc.)
|
|
34
|
-
3. **Call tools** - Execute actions like creating GitHub issues, sending emails, searching Notion pages
|
|
35
|
-
4. **OAuth flow happens server-side** - The SDK sends your OAuth config to the server, which handles the actual authentication flow
|
|
36
|
-
|
|
37
|
-
**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.
|
|
9
|
+
**📚 [Full Documentation](https://integrate.dev)** | **Server:** `https://mcp.integrate.dev/api/v1/mcp`
|
|
38
10
|
|
|
39
11
|
## Features
|
|
40
12
|
|
|
41
13
|
- 🔌 **Plugin-Based Architecture** - Enable only the integrations you need
|
|
42
|
-
- 🔒 **
|
|
14
|
+
- 🔒 **Fully Typed API** - Type-safe methods with autocomplete (e.g., `client.github.createIssue()`)
|
|
15
|
+
- 💡 **IntelliSense Support** - Full TypeScript support with parameter hints
|
|
43
16
|
- 🌊 **Real-time Communication** - HTTP streaming with NDJSON
|
|
44
17
|
- 🔐 **OAuth Ready** - Configure OAuth credentials for each provider
|
|
45
|
-
- 🛠️ **Extensible** -
|
|
18
|
+
- 🛠️ **Extensible** - Configure plugins for any server-supported integration
|
|
46
19
|
- 📦 **Zero Dependencies** - Lightweight implementation
|
|
47
20
|
|
|
48
21
|
## Installation
|
|
@@ -56,7 +29,7 @@ bun add integrate-sdk
|
|
|
56
29
|
## Quick Start
|
|
57
30
|
|
|
58
31
|
```typescript
|
|
59
|
-
import { createMCPClient, githubPlugin
|
|
32
|
+
import { createMCPClient, githubPlugin } from "integrate-sdk";
|
|
60
33
|
|
|
61
34
|
// Create a client with plugins
|
|
62
35
|
const client = createMCPClient({
|
|
@@ -64,11 +37,7 @@ const client = createMCPClient({
|
|
|
64
37
|
githubPlugin({
|
|
65
38
|
clientId: process.env.GITHUB_CLIENT_ID!,
|
|
66
39
|
clientSecret: process.env.GITHUB_CLIENT_SECRET!,
|
|
67
|
-
scopes: [
|
|
68
|
-
}),
|
|
69
|
-
gmailPlugin({
|
|
70
|
-
clientId: process.env.GMAIL_CLIENT_ID!,
|
|
71
|
-
clientSecret: process.env.GMAIL_CLIENT_SECRET!,
|
|
40
|
+
scopes: ["repo", "user"],
|
|
72
41
|
}),
|
|
73
42
|
],
|
|
74
43
|
});
|
|
@@ -76,636 +45,197 @@ const client = createMCPClient({
|
|
|
76
45
|
// Connect to the server
|
|
77
46
|
await client.connect();
|
|
78
47
|
|
|
79
|
-
// Call
|
|
80
|
-
const result = await client.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
48
|
+
// Call GitHub methods with full type safety
|
|
49
|
+
const result = await client.github.createIssue({
|
|
50
|
+
owner: "owner",
|
|
51
|
+
repo: "repo",
|
|
52
|
+
title: "Bug report",
|
|
53
|
+
body: "Description of the bug",
|
|
84
54
|
});
|
|
85
55
|
|
|
86
|
-
console.log(
|
|
56
|
+
console.log("Issue created:", result);
|
|
57
|
+
|
|
58
|
+
// Call server-level tools with typed methods
|
|
59
|
+
const tools = await client.server.listToolsByIntegration({
|
|
60
|
+
integration: "github",
|
|
61
|
+
});
|
|
87
62
|
|
|
88
63
|
// Disconnect when done
|
|
89
64
|
await client.disconnect();
|
|
90
65
|
```
|
|
91
66
|
|
|
67
|
+
**Need help?** Check out the [complete documentation](https://integrate.dev) for detailed guides, examples, and API reference.
|
|
68
|
+
|
|
69
|
+
## Why Use Integrate SDK?
|
|
70
|
+
|
|
71
|
+
### Typed Plugin Methods
|
|
72
|
+
|
|
73
|
+
Instead of generic tool calls, use typed methods with full autocomplete:
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
// ✅ New: Typed methods with autocomplete
|
|
77
|
+
await client.github.createIssue({ owner: "user", repo: "project", title: "Bug" });
|
|
78
|
+
await client.gmail.sendEmail({ to: "user@example.com", subject: "Hello" });
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Benefits
|
|
82
|
+
|
|
83
|
+
- **Type Safety**: Parameters are validated at compile time
|
|
84
|
+
- **Autocomplete**: Your IDE suggests available methods and parameters
|
|
85
|
+
- **Documentation**: Inline JSDoc comments for every method
|
|
86
|
+
- **Refactoring**: Rename methods safely across your codebase
|
|
87
|
+
|
|
88
|
+
### Three Ways to Call Tools
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
// 1. Typed plugin methods (recommended for built-in plugins like GitHub/Gmail)
|
|
92
|
+
await client.github.createIssue({ owner: "user", repo: "project", title: "Bug" });
|
|
93
|
+
await client.gmail.sendEmail({ to: "user@example.com", subject: "Hello" });
|
|
94
|
+
|
|
95
|
+
// 2. Typed server methods (for server-level tools)
|
|
96
|
+
await client.server.listToolsByIntegration({ integration: "github" });
|
|
97
|
+
|
|
98
|
+
// 3. Direct tool calls (for other server-supported integrations)
|
|
99
|
+
await client._callToolByName("slack_send_message", { channel: "#general", text: "Hello" });
|
|
100
|
+
```
|
|
101
|
+
|
|
92
102
|
## Built-in Plugins
|
|
93
103
|
|
|
94
104
|
### GitHub Plugin
|
|
95
105
|
|
|
96
|
-
|
|
97
|
-
import { createMCPClient, githubPlugin } from 'integrate-sdk';
|
|
106
|
+
Access GitHub repositories, issues, pull requests, and more.
|
|
98
107
|
|
|
108
|
+
```typescript
|
|
99
109
|
const client = createMCPClient({
|
|
100
110
|
plugins: [
|
|
101
111
|
githubPlugin({
|
|
102
112
|
clientId: process.env.GITHUB_CLIENT_ID!,
|
|
103
113
|
clientSecret: process.env.GITHUB_CLIENT_SECRET!,
|
|
104
|
-
scopes: [
|
|
105
|
-
redirectUri: 'http://localhost:3000/callback', // Optional
|
|
114
|
+
scopes: ["repo", "user"],
|
|
106
115
|
}),
|
|
107
116
|
],
|
|
108
117
|
});
|
|
118
|
+
|
|
119
|
+
await client.connect();
|
|
120
|
+
|
|
121
|
+
// Use typed methods
|
|
122
|
+
await client.github.getRepo({ owner: "facebook", repo: "react" });
|
|
123
|
+
await client.github.createIssue({ owner: "user", repo: "repo", title: "Bug" });
|
|
124
|
+
await client.github.listPullRequests({ owner: "user", repo: "repo", state: "open" });
|
|
109
125
|
```
|
|
110
126
|
|
|
111
|
-
|
|
112
|
-
- `github_create_issue`
|
|
113
|
-
- `github_list_issues`
|
|
114
|
-
- `github_get_issue`
|
|
115
|
-
- `github_update_issue`
|
|
116
|
-
- `github_close_issue`
|
|
117
|
-
- `github_create_pull_request`
|
|
118
|
-
- `github_list_pull_requests`
|
|
119
|
-
- `github_get_pull_request`
|
|
120
|
-
- `github_merge_pull_request`
|
|
121
|
-
- `github_list_repos`
|
|
122
|
-
- `github_list_own_repos`
|
|
123
|
-
- `github_get_repo`
|
|
124
|
-
- `github_create_repo`
|
|
125
|
-
- And more...
|
|
127
|
+
[→ View GitHub plugin documentation](https://integrate.dev/docs/plugins/github)
|
|
126
128
|
|
|
127
129
|
### Gmail Plugin
|
|
128
130
|
|
|
129
|
-
|
|
130
|
-
import { createMCPClient, gmailPlugin } from 'integrate-sdk';
|
|
131
|
+
Send emails, manage labels, and search messages.
|
|
131
132
|
|
|
133
|
+
```typescript
|
|
132
134
|
const client = createMCPClient({
|
|
133
135
|
plugins: [
|
|
134
136
|
gmailPlugin({
|
|
135
137
|
clientId: process.env.GMAIL_CLIENT_ID!,
|
|
136
138
|
clientSecret: process.env.GMAIL_CLIENT_SECRET!,
|
|
137
|
-
scopes: [ // Optional, defaults to common Gmail scopes
|
|
138
|
-
'https://www.googleapis.com/auth/gmail.send',
|
|
139
|
-
'https://www.googleapis.com/auth/gmail.readonly',
|
|
140
|
-
],
|
|
141
139
|
}),
|
|
142
140
|
],
|
|
143
141
|
});
|
|
142
|
+
|
|
143
|
+
await client.connect();
|
|
144
|
+
|
|
145
|
+
// Use typed methods
|
|
146
|
+
await client.gmail.sendEmail({ to: "user@example.com", subject: "Hello", body: "Hi!" });
|
|
147
|
+
await client.gmail.listEmails({ maxResults: 10, q: "is:unread" });
|
|
148
|
+
await client.gmail.searchEmails({ query: "from:notifications@github.com" });
|
|
144
149
|
```
|
|
145
150
|
|
|
146
|
-
|
|
147
|
-
- `gmail_send_email`
|
|
148
|
-
- `gmail_list_emails`
|
|
149
|
-
- `gmail_get_email`
|
|
150
|
-
- `gmail_delete_email`
|
|
151
|
-
- `gmail_search_emails`
|
|
152
|
-
- `gmail_mark_as_read`
|
|
153
|
-
- `gmail_mark_as_unread`
|
|
154
|
-
- `gmail_list_labels`
|
|
155
|
-
- `gmail_create_label`
|
|
156
|
-
- And more...
|
|
151
|
+
[→ View Gmail plugin documentation](https://integrate.dev/docs/plugins/gmail)
|
|
157
152
|
|
|
158
|
-
|
|
153
|
+
### Configure Additional Integrations
|
|
159
154
|
|
|
160
|
-
|
|
155
|
+
The server may support additional integrations beyond GitHub and Gmail. You can configure OAuth and enable these tools using `genericOAuthPlugin`:
|
|
161
156
|
|
|
162
157
|
```typescript
|
|
163
|
-
import {
|
|
158
|
+
import { genericOAuthPlugin } from "integrate-sdk";
|
|
164
159
|
|
|
160
|
+
// Configure a plugin for any server-supported integration
|
|
165
161
|
const slackPlugin = genericOAuthPlugin({
|
|
166
|
-
id:
|
|
167
|
-
provider:
|
|
162
|
+
id: "slack",
|
|
163
|
+
provider: "slack",
|
|
168
164
|
clientId: process.env.SLACK_CLIENT_ID!,
|
|
169
165
|
clientSecret: process.env.SLACK_CLIENT_SECRET!,
|
|
170
|
-
scopes: [
|
|
171
|
-
tools: [
|
|
172
|
-
'slack_send_message',
|
|
173
|
-
'slack_list_channels',
|
|
174
|
-
'slack_get_channel',
|
|
175
|
-
'slack_invite_user',
|
|
176
|
-
],
|
|
177
|
-
redirectUri: 'https://your-app.com/callback',
|
|
166
|
+
scopes: ["chat:write", "channels:read"],
|
|
167
|
+
tools: ["slack_send_message", "slack_list_channels"], // Must exist on server
|
|
178
168
|
});
|
|
179
169
|
|
|
180
170
|
const client = createMCPClient({
|
|
181
171
|
plugins: [slackPlugin],
|
|
182
172
|
});
|
|
183
|
-
```
|
|
184
173
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
For tools that don't require OAuth:
|
|
174
|
+
await client.connect();
|
|
188
175
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
id: 'math',
|
|
194
|
-
tools: ['math_add', 'math_subtract', 'math_multiply', 'math_divide'],
|
|
195
|
-
onInit: async (client) => {
|
|
196
|
-
console.log('Math plugin initialized');
|
|
197
|
-
},
|
|
176
|
+
// Use _callToolByName to call the tools
|
|
177
|
+
await client._callToolByName("slack_send_message", {
|
|
178
|
+
channel: "#general",
|
|
179
|
+
text: "Hello!"
|
|
198
180
|
});
|
|
199
181
|
```
|
|
200
182
|
|
|
201
|
-
|
|
183
|
+
**Note**: Plugins configure access to server-provided tools - they don't create new tools. All tool implementations must exist on the Integrate MCP server.
|
|
202
184
|
|
|
203
|
-
|
|
204
|
-
import type { MCPPlugin } from 'integrate-sdk';
|
|
205
|
-
|
|
206
|
-
export function customPlugin(config: CustomConfig): MCPPlugin {
|
|
207
|
-
return {
|
|
208
|
-
id: 'custom',
|
|
209
|
-
tools: ['custom_tool1', 'custom_tool2'],
|
|
210
|
-
oauth: {
|
|
211
|
-
provider: 'custom-provider',
|
|
212
|
-
clientId: config.clientId,
|
|
213
|
-
clientSecret: config.clientSecret,
|
|
214
|
-
scopes: config.scopes,
|
|
215
|
-
},
|
|
216
|
-
|
|
217
|
-
async onInit(client) {
|
|
218
|
-
// Called when plugin is initialized
|
|
219
|
-
console.log('Custom plugin initialized');
|
|
220
|
-
},
|
|
221
|
-
|
|
222
|
-
async onBeforeConnect(client) {
|
|
223
|
-
// Called before connecting to server
|
|
224
|
-
},
|
|
225
|
-
|
|
226
|
-
async onAfterConnect(client) {
|
|
227
|
-
// Called after successful connection
|
|
228
|
-
},
|
|
229
|
-
|
|
230
|
-
async onDisconnect(client) {
|
|
231
|
-
// Called when disconnecting
|
|
232
|
-
},
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
```
|
|
185
|
+
## Vercel AI SDK Integration
|
|
236
186
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
The SDK includes built-in support for Vercel's AI SDK, allowing you to give AI models access to all your integrations.
|
|
240
|
-
|
|
241
|
-
### Quick Example
|
|
187
|
+
Give AI models access to all your integrations with built-in Vercel AI SDK support.
|
|
242
188
|
|
|
243
189
|
```typescript
|
|
244
|
-
import {
|
|
245
|
-
import { generateText } from
|
|
246
|
-
import { openai } from
|
|
247
|
-
|
|
248
|
-
// 1. Create and connect MCP client
|
|
249
|
-
const mcpClient = createMCPClient({
|
|
250
|
-
plugins: [
|
|
251
|
-
githubPlugin({
|
|
252
|
-
clientId: process.env.GITHUB_CLIENT_ID!,
|
|
253
|
-
clientSecret: process.env.GITHUB_CLIENT_SECRET!,
|
|
254
|
-
}),
|
|
255
|
-
],
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
await mcpClient.connect();
|
|
190
|
+
import { getVercelAITools } from "integrate-sdk";
|
|
191
|
+
import { generateText } from "ai";
|
|
192
|
+
import { openai } from "@ai-sdk/openai";
|
|
259
193
|
|
|
260
|
-
//
|
|
194
|
+
// Convert MCP tools to Vercel AI SDK format
|
|
261
195
|
const tools = getVercelAITools(mcpClient);
|
|
262
196
|
|
|
263
|
-
//
|
|
197
|
+
// Use with AI models
|
|
264
198
|
const result = await generateText({
|
|
265
|
-
model: openai(
|
|
266
|
-
prompt:
|
|
199
|
+
model: openai("gpt-5"),
|
|
200
|
+
prompt: "Create a GitHub issue about the login bug",
|
|
267
201
|
tools,
|
|
268
202
|
maxToolRoundtrips: 5,
|
|
269
203
|
});
|
|
270
|
-
|
|
271
|
-
console.log(result.text);
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
### How It Works
|
|
275
|
-
|
|
276
|
-
1. **`getVercelAITools(client)`** - Converts all enabled MCP tools to Vercel AI SDK format
|
|
277
|
-
2. **Automatic execution** - When the AI calls a tool, it executes through your MCP client
|
|
278
|
-
3. **Type-safe** - Full TypeScript support with proper types
|
|
279
|
-
|
|
280
|
-
### Available Functions
|
|
281
|
-
|
|
282
|
-
- **`getVercelAITools(client)`** - Get all enabled tools in Vercel AI SDK format
|
|
283
|
-
- **`convertMCPToolsToVercelAI(client)`** - Same as above, alternative name
|
|
284
|
-
- **`convertMCPToolToVercelAI(tool, client)`** - Convert a single MCP tool
|
|
285
|
-
|
|
286
|
-
See `examples/vercel-ai-integration.ts` for a complete working example.
|
|
287
|
-
|
|
288
|
-
## Advanced Usage
|
|
289
|
-
|
|
290
|
-
### Accessing OAuth Configurations
|
|
291
|
-
|
|
292
|
-
```typescript
|
|
293
|
-
// Get OAuth config for a specific plugin
|
|
294
|
-
const githubOAuth = client.getOAuthConfig('github');
|
|
295
|
-
console.log('GitHub OAuth scopes:', githubOAuth?.scopes);
|
|
296
|
-
|
|
297
|
-
// Get all OAuth configs
|
|
298
|
-
const allConfigs = client.getAllOAuthConfigs();
|
|
299
|
-
for (const [pluginId, config] of allConfigs) {
|
|
300
|
-
console.log(`${pluginId}: ${config.provider}`);
|
|
301
|
-
}
|
|
302
|
-
```
|
|
303
|
-
|
|
304
|
-
### Listing Available Tools
|
|
305
|
-
|
|
306
|
-
```typescript
|
|
307
|
-
await client.connect();
|
|
308
|
-
|
|
309
|
-
// Get all enabled tools (filtered by plugins)
|
|
310
|
-
const enabledTools = client.getEnabledTools();
|
|
311
|
-
console.log('Enabled tools:', enabledTools.map(t => t.name));
|
|
312
|
-
|
|
313
|
-
// Get all available tools from server
|
|
314
|
-
const allTools = client.getAvailableTools();
|
|
315
|
-
console.log('All tools:', allTools.map(t => t.name));
|
|
316
|
-
|
|
317
|
-
// Get a specific tool
|
|
318
|
-
const tool = client.getTool('github_create_issue');
|
|
319
|
-
console.log('Tool schema:', tool?.inputSchema);
|
|
320
|
-
```
|
|
321
|
-
|
|
322
|
-
### Handling Messages and Notifications
|
|
323
|
-
|
|
324
|
-
```typescript
|
|
325
|
-
// Listen for server messages and notifications
|
|
326
|
-
const unsubscribe = client.onMessage((message) => {
|
|
327
|
-
console.log('Received message:', message);
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
// Unsubscribe when done
|
|
331
|
-
unsubscribe();
|
|
332
|
-
```
|
|
333
|
-
|
|
334
|
-
### Error Handling
|
|
335
|
-
|
|
336
|
-
```typescript
|
|
337
|
-
try {
|
|
338
|
-
await client.connect();
|
|
339
|
-
const result = await client.callTool('github_create_issue', {
|
|
340
|
-
repo: 'owner/repo',
|
|
341
|
-
title: 'Bug report',
|
|
342
|
-
});
|
|
343
|
-
} catch (error) {
|
|
344
|
-
if (error.message.includes('not enabled')) {
|
|
345
|
-
console.error('Tool is not enabled. Add the appropriate plugin.');
|
|
346
|
-
} else if (error.message.includes('not available')) {
|
|
347
|
-
console.error('Tool is not available on the server.');
|
|
348
|
-
} else {
|
|
349
|
-
console.error('Unexpected error:', error);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
```
|
|
353
|
-
|
|
354
|
-
### Custom Headers and Timeouts
|
|
355
|
-
|
|
356
|
-
```typescript
|
|
357
|
-
const client = createMCPClient({
|
|
358
|
-
plugins: [/* ... */],
|
|
359
|
-
|
|
360
|
-
// Custom headers
|
|
361
|
-
headers: {
|
|
362
|
-
'Authorization': 'Bearer token',
|
|
363
|
-
'X-Custom-Header': 'value',
|
|
364
|
-
},
|
|
365
|
-
|
|
366
|
-
// Request timeout (default: 30000ms)
|
|
367
|
-
timeout: 60000,
|
|
368
|
-
|
|
369
|
-
// Custom client info
|
|
370
|
-
clientInfo: {
|
|
371
|
-
name: 'my-app',
|
|
372
|
-
version: '1.0.0',
|
|
373
|
-
},
|
|
374
|
-
});
|
|
375
|
-
```
|
|
376
|
-
|
|
377
|
-
## API Reference
|
|
378
|
-
|
|
379
|
-
### `createMCPClient(config)`
|
|
380
|
-
|
|
381
|
-
Creates a new MCP client instance.
|
|
382
|
-
|
|
383
|
-
**Parameters:**
|
|
384
|
-
- `config.plugins` (MCPPlugin[]): Array of plugins to enable
|
|
385
|
-
- `config.headers` (object, optional): Custom HTTP headers
|
|
386
|
-
- `config.timeout` (number, optional): Request timeout in milliseconds
|
|
387
|
-
- `config.clientInfo` (object, optional): Client name and version
|
|
388
|
-
|
|
389
|
-
**Returns:** `MCPClient` instance
|
|
390
|
-
|
|
391
|
-
### `MCPClient` Methods
|
|
392
|
-
|
|
393
|
-
- `connect()`: Connect to the MCP server
|
|
394
|
-
- `disconnect()`: Disconnect from the server
|
|
395
|
-
- `callTool(name, args)`: Invoke a tool by name
|
|
396
|
-
- `getTool(name)`: Get tool definition by name
|
|
397
|
-
- `getEnabledTools()`: Get all enabled tools
|
|
398
|
-
- `getAvailableTools()`: Get all available tools
|
|
399
|
-
- `getOAuthConfig(pluginId)`: Get OAuth config for a plugin
|
|
400
|
-
- `getAllOAuthConfigs()`: Get all OAuth configurations
|
|
401
|
-
- `onMessage(handler)`: Register a message handler
|
|
402
|
-
- `isConnected()`: Check if connected
|
|
403
|
-
- `isInitialized()`: Check if initialized
|
|
404
|
-
|
|
405
|
-
## Architecture
|
|
406
|
-
|
|
407
|
-
The SDK is built with a modular architecture:
|
|
408
|
-
|
|
409
204
|
```
|
|
410
|
-
integrate-sdk/
|
|
411
|
-
├── src/
|
|
412
|
-
│ ├── client.ts # Main MCPClient class
|
|
413
|
-
│ ├── index.ts # Public exports
|
|
414
|
-
│ ├── config/
|
|
415
|
-
│ │ └── types.ts # Configuration types
|
|
416
|
-
│ ├── transport/
|
|
417
|
-
│ │ └── http-stream.ts # HTTP streaming transport (NDJSON)
|
|
418
|
-
│ ├── protocol/
|
|
419
|
-
│ │ ├── messages.ts # MCP message types
|
|
420
|
-
│ │ └── jsonrpc.ts # JSON-RPC implementation
|
|
421
|
-
│ └── plugins/
|
|
422
|
-
│ ├── types.ts # Plugin interface
|
|
423
|
-
│ ├── github.ts # GitHub plugin
|
|
424
|
-
│ ├── gmail.ts # Gmail plugin
|
|
425
|
-
│ └── generic.ts # Generic OAuth plugin
|
|
426
|
-
```
|
|
427
|
-
|
|
428
|
-
**Transport Layer:**
|
|
429
|
-
The SDK uses HTTP streaming with newline-delimited JSON (NDJSON) for bidirectional communication:
|
|
430
|
-
- Single persistent HTTP connection
|
|
431
|
-
- Messages sent as JSON followed by newline (`\n`)
|
|
432
|
-
- Automatic heartbeat to keep connection alive
|
|
433
|
-
- Compatible with MCP's `StreamableHTTPServer`
|
|
434
205
|
|
|
435
|
-
|
|
206
|
+
[→ View Vercel AI SDK integration guide](https://integrate.dev/docs/integrations/vercel-ai)
|
|
436
207
|
|
|
437
|
-
|
|
438
|
-
2. **Connection**: The SDK connects to `https://mcp.integrate.dev/api/v1/mcp` using HTTP streaming (NDJSON)
|
|
439
|
-
3. **Tool Discovery**: The SDK fetches available tools from the server and filters them based on your enabled plugins
|
|
440
|
-
4. **OAuth Configuration**: Your OAuth credentials are stored in the client configuration (not sent to the server yet)
|
|
441
|
-
5. **Tool Calls**: When you call a tool, the SDK sends a JSON-RPC request to the server
|
|
442
|
-
6. **OAuth Flow**: The server uses your OAuth configuration to authenticate and execute the tool
|
|
208
|
+
## Documentation
|
|
443
209
|
|
|
444
|
-
|
|
210
|
+
For detailed guides, API reference, and examples, visit the [complete documentation](https://integrate.dev):
|
|
445
211
|
|
|
446
|
-
**
|
|
447
|
-
**
|
|
448
|
-
**
|
|
449
|
-
**
|
|
212
|
+
- **[Getting Started](https://integrate.dev/docs/getting-started/installation)** - Installation and quick start
|
|
213
|
+
- **[Plugins](https://integrate.dev/docs/plugins)** - Built-in plugins and configuration
|
|
214
|
+
- **[Vercel AI SDK](https://integrate.dev/docs/integrations/vercel-ai)** - AI model integration
|
|
215
|
+
- **[Advanced Usage](https://integrate.dev/docs/guides/advanced-usage)** - Error handling, retries, and more
|
|
216
|
+
- **[API Reference](https://integrate.dev/docs/reference/api-reference)** - Complete API documentation
|
|
217
|
+
- **[Architecture](https://integrate.dev/docs/reference/architecture)** - How the SDK works
|
|
450
218
|
|
|
451
219
|
## TypeScript Support
|
|
452
220
|
|
|
453
|
-
The SDK is built with TypeScript and provides full type safety
|
|
454
|
-
|
|
455
|
-
```typescript
|
|
456
|
-
import { createMCPClient, githubPlugin } from 'integrate-sdk';
|
|
457
|
-
import type { MCPToolCallResponse } from 'integrate-sdk';
|
|
458
|
-
|
|
459
|
-
const client = createMCPClient({
|
|
460
|
-
plugins: [
|
|
461
|
-
githubPlugin({
|
|
462
|
-
clientId: process.env.GITHUB_CLIENT_ID!,
|
|
463
|
-
clientSecret: process.env.GITHUB_CLIENT_SECRET!,
|
|
464
|
-
}),
|
|
465
|
-
],
|
|
466
|
-
});
|
|
467
|
-
|
|
468
|
-
// Full type inference and IntelliSense support
|
|
469
|
-
await client.connect();
|
|
470
|
-
const result: MCPToolCallResponse = await client.callTool('github_create_issue', {
|
|
471
|
-
repo: 'owner/repo',
|
|
472
|
-
title: 'Bug report',
|
|
473
|
-
});
|
|
474
|
-
```
|
|
221
|
+
The SDK is built with TypeScript and provides full type safety with IntelliSense support out of the box.
|
|
475
222
|
|
|
476
223
|
## Contributing
|
|
477
224
|
|
|
478
|
-
Contributions are welcome! Please
|
|
479
|
-
|
|
480
|
-
## Test Structure
|
|
481
|
-
|
|
482
|
-
```
|
|
483
|
-
tests/
|
|
484
|
-
├── protocol/ # Protocol and JSON-RPC tests
|
|
485
|
-
│ └── jsonrpc.test.ts
|
|
486
|
-
├── plugins/ # Plugin system tests
|
|
487
|
-
│ └── plugin-system.test.ts
|
|
488
|
-
├── client/ # Client functionality tests
|
|
489
|
-
│ └── client.test.ts
|
|
490
|
-
├── integration/ # Integration tests with mock server
|
|
491
|
-
│ ├── mock-server.ts
|
|
492
|
-
│ └── integration.test.ts
|
|
493
|
-
├── setup.ts # Test setup and utilities
|
|
494
|
-
└── README.md # This file
|
|
495
|
-
```
|
|
225
|
+
Contributions are welcome! Please check the [issues](https://github.com/Revyo/integrate-sdk/issues) for ways to contribute.
|
|
496
226
|
|
|
497
|
-
##
|
|
227
|
+
## Testing
|
|
498
228
|
|
|
499
|
-
### All Tests
|
|
500
229
|
```bash
|
|
230
|
+
# Run all tests
|
|
501
231
|
bun test
|
|
502
|
-
```
|
|
503
|
-
|
|
504
|
-
### Unit Tests Only
|
|
505
|
-
```bash
|
|
506
|
-
bun run test:unit
|
|
507
|
-
```
|
|
508
232
|
|
|
509
|
-
|
|
510
|
-
```bash
|
|
511
|
-
bun run test:integration
|
|
512
|
-
```
|
|
513
|
-
|
|
514
|
-
### Watch Mode
|
|
515
|
-
```bash
|
|
516
|
-
bun run test:watch
|
|
517
|
-
```
|
|
518
|
-
|
|
519
|
-
### With Coverage
|
|
520
|
-
```bash
|
|
233
|
+
# Run with coverage
|
|
521
234
|
bun run test:coverage
|
|
522
235
|
```
|
|
523
236
|
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
### 1. Protocol Tests (`tests/protocol/`)
|
|
527
|
-
Tests for JSON-RPC 2.0 protocol implementation:
|
|
528
|
-
- Request/response formatting
|
|
529
|
-
- Notification handling
|
|
530
|
-
- Error responses
|
|
531
|
-
- Message parsing and serialization
|
|
532
|
-
- ID generation
|
|
533
|
-
|
|
534
|
-
### 2. Plugin System Tests (`tests/plugins/`)
|
|
535
|
-
Tests for the plugin architecture:
|
|
536
|
-
- GitHub plugin configuration
|
|
537
|
-
- Gmail plugin configuration
|
|
538
|
-
- Generic OAuth plugin creation
|
|
539
|
-
- Simple plugin creation
|
|
540
|
-
- OAuth config type guards
|
|
541
|
-
- Plugin lifecycle hooks
|
|
542
|
-
|
|
543
|
-
### 3. Client Tests (`tests/client/`)
|
|
544
|
-
Tests for the main MCP client:
|
|
545
|
-
- Client creation and configuration
|
|
546
|
-
- Plugin initialization
|
|
547
|
-
- OAuth configuration management
|
|
548
|
-
- Tool management
|
|
549
|
-
- Connection state tracking
|
|
550
|
-
- Error handling
|
|
551
|
-
- Message handlers
|
|
552
|
-
|
|
553
|
-
### 4. Integration Tests (`tests/integration/`)
|
|
554
|
-
End-to-end tests with a mock MCP server:
|
|
555
|
-
- Connection establishment
|
|
556
|
-
- Tool discovery
|
|
557
|
-
- Tool filtering by plugins
|
|
558
|
-
- Tool invocation
|
|
559
|
-
- Plugin lifecycle hooks
|
|
560
|
-
- Concurrent requests
|
|
561
|
-
- Error scenarios
|
|
562
|
-
- Connection timeout
|
|
563
|
-
|
|
564
|
-
## Mock Server
|
|
565
|
-
|
|
566
|
-
The integration tests use a mock MCP server that:
|
|
567
|
-
- Implements HTTP streaming with NDJSON
|
|
568
|
-
- Supports `initialize`, `tools/list`, and `tools/call` methods
|
|
569
|
-
- Returns configurable tools
|
|
570
|
-
- Handles heartbeat/ping messages
|
|
571
|
-
- Runs on a random port to avoid conflicts
|
|
572
|
-
|
|
573
|
-
Example usage:
|
|
574
|
-
```typescript
|
|
575
|
-
import { MockMCPServer } from './tests/integration/mock-server';
|
|
576
|
-
|
|
577
|
-
const server = new MockMCPServer({
|
|
578
|
-
port: 3456,
|
|
579
|
-
tools: [
|
|
580
|
-
{
|
|
581
|
-
name: 'test/echo',
|
|
582
|
-
description: 'Echo test tool',
|
|
583
|
-
inputSchema: { /* ... */ }
|
|
584
|
-
}
|
|
585
|
-
]
|
|
586
|
-
});
|
|
587
|
-
|
|
588
|
-
await server.start();
|
|
589
|
-
// Run tests...
|
|
590
|
-
await server.stop();
|
|
591
|
-
```
|
|
592
|
-
|
|
593
|
-
## Writing New Tests
|
|
594
|
-
|
|
595
|
-
### Unit Test Example
|
|
596
|
-
|
|
597
|
-
```typescript
|
|
598
|
-
import { describe, test, expect } from "bun:test";
|
|
599
|
-
import { myFunction } from "../../src/module.js";
|
|
600
|
-
|
|
601
|
-
describe("My Module", () => {
|
|
602
|
-
test("does something correctly", () => {
|
|
603
|
-
const result = myFunction("input");
|
|
604
|
-
expect(result).toBe("expected output");
|
|
605
|
-
});
|
|
606
|
-
});
|
|
607
|
-
```
|
|
608
|
-
|
|
609
|
-
### Integration Test Example
|
|
610
|
-
|
|
611
|
-
```typescript
|
|
612
|
-
import { describe, test, expect, beforeAll, afterAll } from "bun:test";
|
|
613
|
-
import { createMCPClient } from "../../src/client.js";
|
|
614
|
-
import { MockMCPServer } from "./mock-server.js";
|
|
615
|
-
|
|
616
|
-
describe("Integration Test", () => {
|
|
617
|
-
let server: MockMCPServer;
|
|
618
|
-
|
|
619
|
-
beforeAll(async () => {
|
|
620
|
-
server = new MockMCPServer({ port: 3456 });
|
|
621
|
-
await server.start();
|
|
622
|
-
});
|
|
623
|
-
|
|
624
|
-
afterAll(async () => {
|
|
625
|
-
await server.stop();
|
|
626
|
-
});
|
|
627
|
-
|
|
628
|
-
test("connects and calls tool", async () => {
|
|
629
|
-
const client = createMCPClient({
|
|
630
|
-
plugins: [/* ... */],
|
|
631
|
-
});
|
|
632
|
-
|
|
633
|
-
await client.connect();
|
|
634
|
-
const result = await client.callTool("test/tool");
|
|
635
|
-
expect(result).toBeDefined();
|
|
636
|
-
await client.disconnect();
|
|
637
|
-
});
|
|
638
|
-
});
|
|
639
|
-
```
|
|
640
|
-
|
|
641
|
-
## Test Coverage
|
|
642
|
-
|
|
643
|
-
The test suite covers:
|
|
644
|
-
- ✅ JSON-RPC protocol implementation
|
|
645
|
-
- ✅ Plugin system and configuration
|
|
646
|
-
- ✅ Client initialization and lifecycle
|
|
647
|
-
- ✅ Tool discovery and filtering
|
|
648
|
-
- ✅ Tool invocation
|
|
649
|
-
- ✅ OAuth configuration management
|
|
650
|
-
- ✅ Error handling
|
|
651
|
-
- ✅ Connection management
|
|
652
|
-
- ✅ Concurrent requests
|
|
653
|
-
- ✅ Plugin lifecycle hooks
|
|
654
|
-
|
|
655
|
-
## Debugging Tests
|
|
656
|
-
|
|
657
|
-
Run tests with debug output:
|
|
658
|
-
```bash
|
|
659
|
-
DEBUG=1 bun test
|
|
660
|
-
```
|
|
661
|
-
|
|
662
|
-
Run specific test file:
|
|
663
|
-
```bash
|
|
664
|
-
bun test tests/protocol/jsonrpc.test.ts
|
|
665
|
-
```
|
|
666
|
-
|
|
667
|
-
Run specific test:
|
|
668
|
-
```bash
|
|
669
|
-
bun test -t "creates valid JSON-RPC request"
|
|
670
|
-
```
|
|
671
|
-
|
|
672
|
-
## Continuous Integration
|
|
673
|
-
|
|
674
|
-
Tests run automatically on:
|
|
675
|
-
- Push to `main` or `develop` branches
|
|
676
|
-
- Pull requests to `main` or `develop`
|
|
677
|
-
|
|
678
|
-
The CI pipeline runs:
|
|
679
|
-
1. Type checking
|
|
680
|
-
2. Unit tests
|
|
681
|
-
3. Integration tests
|
|
682
|
-
4. Build verification
|
|
683
|
-
|
|
684
|
-
See `.github/workflows/test.yml` for details.
|
|
685
|
-
|
|
686
|
-
## Common Issues
|
|
687
|
-
|
|
688
|
-
### Port Already in Use
|
|
689
|
-
Integration tests use port 3456. If this conflicts, modify `MockMCPServer` constructor.
|
|
690
|
-
|
|
691
|
-
### Test Timeouts
|
|
692
|
-
Integration tests have 10s timeout. Increase if needed:
|
|
693
|
-
```typescript
|
|
694
|
-
test("my test", async () => {
|
|
695
|
-
// test code
|
|
696
|
-
}, 20000); // 20 second timeout
|
|
697
|
-
```
|
|
698
|
-
|
|
699
|
-
### Console Logs
|
|
700
|
-
Console logs are suppressed during tests unless `DEBUG=1` is set.
|
|
701
|
-
|
|
702
|
-
## Contributing
|
|
703
|
-
|
|
704
|
-
When adding new features:
|
|
705
|
-
1. Write unit tests for individual components
|
|
706
|
-
2. Write integration tests for end-to-end flows
|
|
707
|
-
3. Ensure all tests pass before submitting PR
|
|
708
|
-
4. Maintain test coverage above 80%
|
|
709
|
-
|
|
237
|
+
See the `tests/` directory for unit and integration test examples.
|
|
710
238
|
|
|
239
|
+
## License
|
|
711
240
|
|
|
241
|
+
MIT © [Revyo](https://github.com/Revyo)
|