integrate-sdk 0.8.52-dev.0 → 0.8.54-dev.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/dist/oauth.js CHANGED
@@ -11,39 +11,43 @@ var __export = (target, all) => {
11
11
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
12
12
 
13
13
  // src/utils/logger.ts
14
- function shouldLog(level) {
15
- return logLevelHierarchy[level] <= logLevelHierarchy[globalLogLevel];
14
+ function shouldLog(level, context) {
15
+ return logLevelHierarchy[level] <= logLevelHierarchy[contextLogLevels[context]];
16
16
  }
17
- function setLogLevel(level) {
18
- globalLogLevel = level;
17
+ function setLogLevel(level, context = "client") {
18
+ contextLogLevels[context] = level;
19
19
  }
20
- function createLogger(namespace) {
20
+ function createLogger(namespace, context = "client") {
21
21
  const prefix = `[${namespace}]`;
22
22
  return {
23
23
  debug: (...args) => {
24
- if (shouldLog("debug")) {
24
+ if (shouldLog("debug", context)) {
25
25
  console.log(prefix, ...args);
26
26
  }
27
27
  },
28
28
  info: (...args) => {
29
- if (shouldLog("info")) {
29
+ if (shouldLog("info", context)) {
30
30
  console.log(prefix, ...args);
31
31
  }
32
32
  },
33
33
  warn: (...args) => {
34
- if (shouldLog("warn")) {
34
+ if (shouldLog("warn", context)) {
35
35
  console.warn(prefix, ...args);
36
36
  }
37
37
  },
38
38
  error: (...args) => {
39
- if (shouldLog("error")) {
39
+ if (shouldLog("error", context)) {
40
40
  console.error(prefix, ...args);
41
41
  }
42
42
  }
43
43
  };
44
44
  }
45
- var globalLogLevel = "error", logLevelHierarchy;
45
+ var contextLogLevels, logLevelHierarchy;
46
46
  var init_logger = __esm(() => {
47
+ contextLogLevels = {
48
+ client: "error",
49
+ server: "error"
50
+ };
47
51
  logLevelHierarchy = {
48
52
  none: 0,
49
53
  error: 1,
@@ -1700,6 +1704,7 @@ class MCPClientBase {
1700
1704
  apiBaseUrl;
1701
1705
  databaseDetected = false;
1702
1706
  __configuredIntegrations;
1707
+ __useServerConfig;
1703
1708
  oauthCallbackPromise;
1704
1709
  server;
1705
1710
  trigger;
@@ -1726,6 +1731,7 @@ class MCPClientBase {
1726
1731
  return integration;
1727
1732
  });
1728
1733
  this.__configuredIntegrations = this.integrations;
1734
+ this.__useServerConfig = config.useServerConfig ?? false;
1729
1735
  this.clientInfo = config.clientInfo || {
1730
1736
  name: "integrate-sdk",
1731
1737
  version: "0.1.0"
@@ -1869,60 +1875,12 @@ class MCPClientBase {
1869
1875
  get: (_target, methodName) => {
1870
1876
  if (methodName === "listConfiguredIntegrations") {
1871
1877
  return async (options) => {
1878
+ const transportHeaders = this.transport.headers || {};
1879
+ const hasApiKey = !!transportHeaders["X-API-KEY"];
1872
1880
  const serverConfig = this.__oauthConfig;
1873
- const configuredIntegrations = serverConfig?.integrations || this.__configuredIntegrations;
1874
- if (options?.includeToolMetadata) {
1875
- const { parallelWithLimit: parallelWithLimit2 } = await Promise.resolve().then(() => exports_concurrency);
1876
- const integrationsWithMetadata = await parallelWithLimit2(configuredIntegrations, async (integration) => {
1877
- try {
1878
- const response = await this.callServerToolInternal("list_tools_by_integration", {
1879
- integration: integration.id
1880
- });
1881
- let toolMetadata = [];
1882
- if (response.content && Array.isArray(response.content)) {
1883
- for (const item of response.content) {
1884
- if (item.type === "text" && item.text) {
1885
- try {
1886
- const parsed = JSON.parse(item.text);
1887
- if (Array.isArray(parsed)) {
1888
- toolMetadata = parsed;
1889
- } else if (parsed.tools && Array.isArray(parsed.tools)) {
1890
- toolMetadata = parsed.tools;
1891
- }
1892
- } catch {}
1893
- }
1894
- }
1895
- }
1896
- return {
1897
- id: integration.id,
1898
- name: integration.name || integration.id,
1899
- logoUrl: integration.logoUrl,
1900
- tools: integration.tools,
1901
- hasOAuth: !!integration.oauth,
1902
- scopes: integration.oauth?.scopes,
1903
- provider: integration.oauth?.provider,
1904
- toolMetadata
1905
- };
1906
- } catch (error) {
1907
- logger5.error(`Failed to fetch tool metadata for ${integration.id}:`, error);
1908
- return {
1909
- id: integration.id,
1910
- name: integration.name || integration.id,
1911
- logoUrl: integration.logoUrl,
1912
- tools: integration.tools,
1913
- hasOAuth: !!integration.oauth,
1914
- scopes: integration.oauth?.scopes,
1915
- provider: integration.oauth?.provider,
1916
- toolMetadata: []
1917
- };
1918
- }
1919
- }, 3);
1920
- return {
1921
- integrations: integrationsWithMetadata
1922
- };
1923
- }
1924
- return {
1925
- integrations: configuredIntegrations.map((integration) => ({
1881
+ const localIntegrations = serverConfig?.integrations || this.__configuredIntegrations;
1882
+ const formatLocalIntegrations = (integrations) => ({
1883
+ integrations: integrations.map((integration) => ({
1926
1884
  id: integration.id,
1927
1885
  name: integration.name || integration.id,
1928
1886
  logoUrl: integration.logoUrl,
@@ -1931,7 +1889,114 @@ class MCPClientBase {
1931
1889
  scopes: integration.oauth?.scopes,
1932
1890
  provider: integration.oauth?.provider
1933
1891
  }))
1934
- };
1892
+ });
1893
+ if (hasApiKey || !this.__useServerConfig) {
1894
+ if (options?.includeToolMetadata) {
1895
+ const { parallelWithLimit: parallelWithLimit2 } = await Promise.resolve().then(() => exports_concurrency);
1896
+ const integrationsWithMetadata = await parallelWithLimit2(localIntegrations, async (integration) => {
1897
+ try {
1898
+ const response = await this.callServerToolInternal("list_tools_by_integration", {
1899
+ integration: integration.id
1900
+ });
1901
+ let toolMetadata = [];
1902
+ if (response.content && Array.isArray(response.content)) {
1903
+ for (const item of response.content) {
1904
+ if (item.type === "text" && item.text) {
1905
+ try {
1906
+ const parsed = JSON.parse(item.text);
1907
+ if (Array.isArray(parsed)) {
1908
+ toolMetadata = parsed;
1909
+ } else if (parsed.tools && Array.isArray(parsed.tools)) {
1910
+ toolMetadata = parsed.tools;
1911
+ }
1912
+ } catch {}
1913
+ }
1914
+ }
1915
+ }
1916
+ return {
1917
+ id: integration.id,
1918
+ name: integration.name || integration.id,
1919
+ logoUrl: integration.logoUrl,
1920
+ tools: integration.tools,
1921
+ hasOAuth: !!integration.oauth,
1922
+ scopes: integration.oauth?.scopes,
1923
+ provider: integration.oauth?.provider,
1924
+ toolMetadata
1925
+ };
1926
+ } catch (error) {
1927
+ logger5.error(`Failed to fetch tool metadata for ${integration.id}:`, error);
1928
+ return {
1929
+ id: integration.id,
1930
+ name: integration.name || integration.id,
1931
+ logoUrl: integration.logoUrl,
1932
+ tools: integration.tools,
1933
+ hasOAuth: !!integration.oauth,
1934
+ scopes: integration.oauth?.scopes,
1935
+ provider: integration.oauth?.provider,
1936
+ toolMetadata: []
1937
+ };
1938
+ }
1939
+ }, 3);
1940
+ return {
1941
+ integrations: integrationsWithMetadata
1942
+ };
1943
+ }
1944
+ return formatLocalIntegrations(localIntegrations);
1945
+ }
1946
+ const url = this.apiBaseUrl ? `${this.apiBaseUrl}${this.apiRouteBase}/integrations` : `${this.apiRouteBase}/integrations`;
1947
+ try {
1948
+ const response = await fetch(url, {
1949
+ method: "GET",
1950
+ headers: {
1951
+ "Content-Type": "application/json"
1952
+ }
1953
+ });
1954
+ if (!response.ok) {
1955
+ logger5.error("Failed to fetch integrations from server, falling back to local config");
1956
+ return formatLocalIntegrations(localIntegrations);
1957
+ }
1958
+ const result = await response.json();
1959
+ if (options?.includeToolMetadata && result.integrations) {
1960
+ const { parallelWithLimit: parallelWithLimit2 } = await Promise.resolve().then(() => exports_concurrency);
1961
+ const integrationsWithMetadata = await parallelWithLimit2(result.integrations, async (integration) => {
1962
+ try {
1963
+ const metadataResponse = await this.callServerToolInternal("list_tools_by_integration", {
1964
+ integration: integration.id
1965
+ });
1966
+ let toolMetadata = [];
1967
+ if (metadataResponse.content && Array.isArray(metadataResponse.content)) {
1968
+ for (const item of metadataResponse.content) {
1969
+ if (item.type === "text" && item.text) {
1970
+ try {
1971
+ const parsed = JSON.parse(item.text);
1972
+ if (Array.isArray(parsed)) {
1973
+ toolMetadata = parsed;
1974
+ } else if (parsed.tools && Array.isArray(parsed.tools)) {
1975
+ toolMetadata = parsed.tools;
1976
+ }
1977
+ } catch {}
1978
+ }
1979
+ }
1980
+ }
1981
+ return {
1982
+ ...integration,
1983
+ toolMetadata
1984
+ };
1985
+ } catch (error) {
1986
+ logger5.error(`Failed to fetch tool metadata for ${integration.id}:`, error);
1987
+ return {
1988
+ ...integration,
1989
+ toolMetadata: []
1990
+ };
1991
+ }
1992
+ }, 3);
1993
+ return { integrations: integrationsWithMetadata };
1994
+ }
1995
+ return result;
1996
+ } catch (error) {
1997
+ logger5.error("Failed to fetch integrations from server, falling back to local config:", error);
1998
+ return formatLocalIntegrations(localIntegrations);
1999
+ }
1935
2000
  };
1936
2001
  }
1937
2002
  return async (args, options) => {
@@ -2384,14 +2449,14 @@ class MCPClientBase {
2384
2449
  return success;
2385
2450
  }
2386
2451
  }
2387
- var MCP_SERVER_URL = "https://mcp.integrate.dev/api/v1/mcp", logger5, clientCache, cleanupClients;
2452
+ var CLIENT_LOG_CONTEXT = "client", MCP_SERVER_URL = "https://mcp.integrate.dev/api/v1/mcp", logger5, clientCache, cleanupClients;
2388
2453
  var init_client = __esm(() => {
2389
2454
  init_http_session();
2390
2455
  init_messages();
2391
2456
  init_errors();
2392
2457
  init_logger();
2393
2458
  init_manager();
2394
- logger5 = createLogger("MCPClient");
2459
+ logger5 = createLogger("MCPClient", CLIENT_LOG_CONTEXT);
2395
2460
  clientCache = new Map;
2396
2461
  cleanupClients = new Set;
2397
2462
  });
@@ -2598,11 +2663,11 @@ function createNextOAuthHandler(config) {
2598
2663
  };
2599
2664
  return handlers;
2600
2665
  }
2601
- var logger6;
2666
+ var SERVER_LOG_CONTEXT = "server", logger6;
2602
2667
  var init_nextjs = __esm(() => {
2603
2668
  init_base_handler();
2604
2669
  init_logger();
2605
- logger6 = createLogger("NextJSOAuth");
2670
+ logger6 = createLogger("NextJSOAuth", SERVER_LOG_CONTEXT);
2606
2671
  });
2607
2672
 
2608
2673
  // src/utils/env.ts
@@ -10029,7 +10094,7 @@ function getDefaultRedirectUri() {
10029
10094
  return "http://localhost:3000/api/integrate/oauth/callback";
10030
10095
  }
10031
10096
  function createMCPServer(config) {
10032
- setLogLevel(config.debug ? "debug" : "error");
10097
+ setLogLevel(config.debug ? "debug" : "error", SERVER_LOG_CONTEXT2);
10033
10098
  if (typeof window !== "undefined") {
10034
10099
  throw new Error("createMCPServer() should only be called on the server-side. " + "Use createMCPClient() for client-side code.");
10035
10100
  }
@@ -10173,6 +10238,18 @@ function createMCPServer(config) {
10173
10238
  return Response.json({ error: error.message || "Failed to execute tool call" }, { status: error.statusCode || 500 });
10174
10239
  }
10175
10240
  }
10241
+ if (action === "integrations" && method === "GET") {
10242
+ const integrations = updatedIntegrations.map((integration) => ({
10243
+ id: integration.id,
10244
+ name: integration.name || integration.id,
10245
+ logoUrl: integration.logoUrl,
10246
+ tools: integration.tools,
10247
+ hasOAuth: !!integration.oauth,
10248
+ scopes: integration.oauth?.scopes,
10249
+ provider: integration.oauth?.provider
10250
+ }));
10251
+ return Response.json({ integrations });
10252
+ }
10176
10253
  if (segments.length >= 1 && segments[0] === "triggers") {
10177
10254
  if (!config.triggers) {
10178
10255
  return Response.json({ error: "Triggers not configured. Add triggers callbacks to createMCPServer config." }, { status: 501 });
@@ -10786,7 +10863,7 @@ function toSvelteKitHandler(clientOrHandlerOrOptions, _redirectOptions) {
10786
10863
  }
10787
10864
  };
10788
10865
  }
10789
- var logger30, globalServerConfig = null, codeVerifierStorage, POST = async (req, context) => {
10866
+ var SERVER_LOG_CONTEXT2 = "server", logger30, globalServerConfig = null, codeVerifierStorage, POST = async (req, context) => {
10790
10867
  if (!globalServerConfig) {
10791
10868
  return Response.json({ error: "OAuth not configured. Call createMCPServer() in your server initialization file first." }, { status: 500 });
10792
10869
  }
@@ -10834,7 +10911,7 @@ var init_server = __esm(() => {
10834
10911
  init_anthropic();
10835
10912
  init_google();
10836
10913
  init_ai();
10837
- logger30 = createLogger("MCPServer");
10914
+ logger30 = createLogger("MCPServer", SERVER_LOG_CONTEXT2);
10838
10915
  codeVerifierStorage = new Map;
10839
10916
  });
10840
10917
 
@@ -11397,16 +11474,17 @@ class OAuthHandler {
11397
11474
  return jsonRpcResponse.result;
11398
11475
  }
11399
11476
  }
11400
- var logger31, MCP_SERVER_URL2 = "https://mcp.integrate.dev/api/v1/mcp";
11477
+ var SERVER_LOG_CONTEXT3 = "server", logger31, MCP_SERVER_URL2 = "https://mcp.integrate.dev/api/v1/mcp";
11401
11478
  var init_base_handler = __esm(() => {
11402
11479
  init_logger();
11403
- logger31 = createLogger("OAuthHandler");
11480
+ logger31 = createLogger("OAuthHandler", SERVER_LOG_CONTEXT3);
11404
11481
  });
11405
11482
 
11406
11483
  // src/adapters/auto-routes.ts
11407
11484
  init_base_handler();
11408
11485
  init_logger();
11409
- var logger32 = createLogger("AutoRoutes");
11486
+ var SERVER_LOG_CONTEXT4 = "server";
11487
+ var logger32 = createLogger("AutoRoutes", SERVER_LOG_CONTEXT4);
11410
11488
  var globalOAuthConfig = null;
11411
11489
  async function POST2(req, context) {
11412
11490
  if (!globalOAuthConfig) {
package/dist/react.js CHANGED
@@ -11,39 +11,43 @@ var __export = (target, all) => {
11
11
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
12
12
 
13
13
  // src/utils/logger.ts
14
- function shouldLog(level) {
15
- return logLevelHierarchy[level] <= logLevelHierarchy[globalLogLevel];
14
+ function shouldLog(level, context) {
15
+ return logLevelHierarchy[level] <= logLevelHierarchy[contextLogLevels[context]];
16
16
  }
17
- function setLogLevel(level) {
18
- globalLogLevel = level;
17
+ function setLogLevel(level, context = "client") {
18
+ contextLogLevels[context] = level;
19
19
  }
20
- function createLogger(namespace) {
20
+ function createLogger(namespace, context = "client") {
21
21
  const prefix = `[${namespace}]`;
22
22
  return {
23
23
  debug: (...args) => {
24
- if (shouldLog("debug")) {
24
+ if (shouldLog("debug", context)) {
25
25
  console.log(prefix, ...args);
26
26
  }
27
27
  },
28
28
  info: (...args) => {
29
- if (shouldLog("info")) {
29
+ if (shouldLog("info", context)) {
30
30
  console.log(prefix, ...args);
31
31
  }
32
32
  },
33
33
  warn: (...args) => {
34
- if (shouldLog("warn")) {
34
+ if (shouldLog("warn", context)) {
35
35
  console.warn(prefix, ...args);
36
36
  }
37
37
  },
38
38
  error: (...args) => {
39
- if (shouldLog("error")) {
39
+ if (shouldLog("error", context)) {
40
40
  console.error(prefix, ...args);
41
41
  }
42
42
  }
43
43
  };
44
44
  }
45
- var globalLogLevel = "error", logLevelHierarchy;
45
+ var contextLogLevels, logLevelHierarchy;
46
46
  var init_logger = __esm(() => {
47
+ contextLogLevels = {
48
+ client: "error",
49
+ server: "error"
50
+ };
47
51
  logLevelHierarchy = {
48
52
  none: 0,
49
53
  error: 1,