integrate-sdk 0.6.8 → 0.7.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.
@@ -8,6 +8,7 @@ var __export = (target, all) => {
8
8
  set: (newValue) => all[name] = () => newValue
9
9
  });
10
10
  };
11
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
11
12
 
12
13
  // src/adapters/base-handler.ts
13
14
  var MCP_SERVER_URL = "https://mcp.integrate.dev/api/v1/mcp";
@@ -138,6 +139,41 @@ class OAuthHandler {
138
139
  const data = await response.json();
139
140
  return data;
140
141
  }
142
+ async handleToolCall(request, authHeader) {
143
+ const url = new URL("/tools/call", this.serverUrl);
144
+ const headers = this.getHeaders({
145
+ "Content-Type": "application/json"
146
+ });
147
+ if (authHeader && authHeader.startsWith("Bearer ")) {
148
+ headers["Authorization"] = authHeader;
149
+ }
150
+ const jsonRpcRequest = {
151
+ jsonrpc: "2.0",
152
+ id: Date.now() + Math.random(),
153
+ method: "tools/call",
154
+ params: {
155
+ name: request.name,
156
+ arguments: request.arguments || {}
157
+ }
158
+ };
159
+ const response = await fetch(url.toString(), {
160
+ method: "POST",
161
+ headers,
162
+ body: JSON.stringify(jsonRpcRequest)
163
+ });
164
+ if (!response.ok) {
165
+ const error = await response.text();
166
+ throw new Error(`MCP server failed to execute tool call: ${error}`);
167
+ }
168
+ const jsonRpcResponse = await response.json();
169
+ if (jsonRpcResponse.error) {
170
+ const error = new Error(jsonRpcResponse.error.message || "Tool call failed");
171
+ error.code = jsonRpcResponse.error.code;
172
+ error.data = jsonRpcResponse.error.data;
173
+ throw error;
174
+ }
175
+ return jsonRpcResponse.result;
176
+ }
141
177
  }
142
178
 
143
179
  // src/adapters/auto-routes.ts
@@ -8,6 +8,7 @@ var __export = (target, all) => {
8
8
  set: (newValue) => all[name] = () => newValue
9
9
  });
10
10
  };
11
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
11
12
 
12
13
  // src/adapters/base-handler.ts
13
14
  var MCP_SERVER_URL = "https://mcp.integrate.dev/api/v1/mcp";
@@ -138,6 +139,41 @@ class OAuthHandler {
138
139
  const data = await response.json();
139
140
  return data;
140
141
  }
142
+ async handleToolCall(request, authHeader) {
143
+ const url = new URL("/tools/call", this.serverUrl);
144
+ const headers = this.getHeaders({
145
+ "Content-Type": "application/json"
146
+ });
147
+ if (authHeader && authHeader.startsWith("Bearer ")) {
148
+ headers["Authorization"] = authHeader;
149
+ }
150
+ const jsonRpcRequest = {
151
+ jsonrpc: "2.0",
152
+ id: Date.now() + Math.random(),
153
+ method: "tools/call",
154
+ params: {
155
+ name: request.name,
156
+ arguments: request.arguments || {}
157
+ }
158
+ };
159
+ const response = await fetch(url.toString(), {
160
+ method: "POST",
161
+ headers,
162
+ body: JSON.stringify(jsonRpcRequest)
163
+ });
164
+ if (!response.ok) {
165
+ const error = await response.text();
166
+ throw new Error(`MCP server failed to execute tool call: ${error}`);
167
+ }
168
+ const jsonRpcResponse = await response.json();
169
+ if (jsonRpcResponse.error) {
170
+ const error = new Error(jsonRpcResponse.error.message || "Tool call failed");
171
+ error.code = jsonRpcResponse.error.code;
172
+ error.data = jsonRpcResponse.error.data;
173
+ throw error;
174
+ }
175
+ return jsonRpcResponse.result;
176
+ }
141
177
  }
142
178
  export {
143
179
  OAuthHandler
@@ -8,6 +8,7 @@ var __export = (target, all) => {
8
8
  set: (newValue) => all[name] = () => newValue
9
9
  });
10
10
  };
11
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
11
12
 
12
13
  // src/oauth/pkce.ts
13
14
  var exports_pkce = {};
@@ -8,6 +8,7 @@ var __export = (target, all) => {
8
8
  set: (newValue) => all[name] = () => newValue
9
9
  });
10
10
  };
11
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
11
12
 
12
13
  // src/oauth/pkce.ts
13
14
  var exports_pkce = {};
@@ -234,6 +235,41 @@ class OAuthHandler {
234
235
  const data = await response.json();
235
236
  return data;
236
237
  }
238
+ async handleToolCall(request, authHeader) {
239
+ const url = new URL("/tools/call", this.serverUrl);
240
+ const headers = this.getHeaders({
241
+ "Content-Type": "application/json"
242
+ });
243
+ if (authHeader && authHeader.startsWith("Bearer ")) {
244
+ headers["Authorization"] = authHeader;
245
+ }
246
+ const jsonRpcRequest = {
247
+ jsonrpc: "2.0",
248
+ id: Date.now() + Math.random(),
249
+ method: "tools/call",
250
+ params: {
251
+ name: request.name,
252
+ arguments: request.arguments || {}
253
+ }
254
+ };
255
+ const response = await fetch(url.toString(), {
256
+ method: "POST",
257
+ headers,
258
+ body: JSON.stringify(jsonRpcRequest)
259
+ });
260
+ if (!response.ok) {
261
+ const error = await response.text();
262
+ throw new Error(`MCP server failed to execute tool call: ${error}`);
263
+ }
264
+ const jsonRpcResponse = await response.json();
265
+ if (jsonRpcResponse.error) {
266
+ const error = new Error(jsonRpcResponse.error.message || "Tool call failed");
267
+ error.code = jsonRpcResponse.error.code;
268
+ error.data = jsonRpcResponse.error.data;
269
+ throw error;
270
+ }
271
+ return jsonRpcResponse.result;
272
+ }
237
273
  }
238
274
 
239
275
  // src/adapters/nextjs.ts
@@ -311,6 +347,9 @@ function createNextOAuthHandler(config) {
311
347
  if (action === "disconnect") {
312
348
  return handlers.disconnect(req);
313
349
  }
350
+ if (action === "mcp") {
351
+ return handlers.mcp(req);
352
+ }
314
353
  return Response.json({ error: `Unknown action: ${action}` }, { status: 404 });
315
354
  },
316
355
  async GET(req, context) {
@@ -323,6 +362,17 @@ function createNextOAuthHandler(config) {
323
362
  }
324
363
  };
325
364
  },
365
+ async mcp(req) {
366
+ try {
367
+ const body = await req.json();
368
+ const authHeader = req.headers.get("authorization");
369
+ const result = await handler.handleToolCall(body, authHeader);
370
+ return Response.json(result);
371
+ } catch (error) {
372
+ console.error("[MCP Tool Call] Error:", error);
373
+ return Response.json({ error: error.message || "Failed to execute tool call" }, { status: error.statusCode || 500 });
374
+ }
375
+ },
326
376
  toNextJsHandler(redirectConfig) {
327
377
  const defaultRedirectUrl = redirectConfig?.redirectUrl || "/";
328
378
  const errorRedirectUrl = redirectConfig?.errorRedirectUrl || "/auth-error";
@@ -343,6 +393,9 @@ function createNextOAuthHandler(config) {
343
393
  }
344
394
  return Response.json({ error: `Unknown action: ${action}` }, { status: 404 });
345
395
  }
396
+ if (segments.length === 1 && segments[0] === "mcp") {
397
+ return handlers.mcp(req);
398
+ }
346
399
  return Response.json({ error: `Invalid route: /${segments.join("/")}` }, { status: 404 });
347
400
  },
348
401
  async GET(req, context) {
@@ -8,6 +8,7 @@ var __export = (target, all) => {
8
8
  set: (newValue) => all[name] = () => newValue
9
9
  });
10
10
  };
11
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
11
12
 
12
13
  // src/adapters/base-handler.ts
13
14
  var MCP_SERVER_URL = "https://mcp.integrate.dev/api/v1/mcp";
@@ -138,6 +139,41 @@ class OAuthHandler {
138
139
  const data = await response.json();
139
140
  return data;
140
141
  }
142
+ async handleToolCall(request, authHeader) {
143
+ const url = new URL("/tools/call", this.serverUrl);
144
+ const headers = this.getHeaders({
145
+ "Content-Type": "application/json"
146
+ });
147
+ if (authHeader && authHeader.startsWith("Bearer ")) {
148
+ headers["Authorization"] = authHeader;
149
+ }
150
+ const jsonRpcRequest = {
151
+ jsonrpc: "2.0",
152
+ id: Date.now() + Math.random(),
153
+ method: "tools/call",
154
+ params: {
155
+ name: request.name,
156
+ arguments: request.arguments || {}
157
+ }
158
+ };
159
+ const response = await fetch(url.toString(), {
160
+ method: "POST",
161
+ headers,
162
+ body: JSON.stringify(jsonRpcRequest)
163
+ });
164
+ if (!response.ok) {
165
+ const error = await response.text();
166
+ throw new Error(`MCP server failed to execute tool call: ${error}`);
167
+ }
168
+ const jsonRpcResponse = await response.json();
169
+ if (jsonRpcResponse.error) {
170
+ const error = new Error(jsonRpcResponse.error.message || "Tool call failed");
171
+ error.code = jsonRpcResponse.error.code;
172
+ error.data = jsonRpcResponse.error.data;
173
+ throw error;
174
+ }
175
+ return jsonRpcResponse.result;
176
+ }
141
177
  }
142
178
 
143
179
  // src/adapters/node.ts