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/adapters/auto-routes.d.ts.map +1 -1
- package/dist/adapters/auto-routes.js +152 -74
- package/dist/adapters/base-handler.d.ts.map +1 -1
- package/dist/adapters/index.js +150 -73
- package/dist/adapters/nextjs-oauth-redirect.d.ts.map +1 -1
- package/dist/adapters/nextjs-oauth-redirect.js +16 -11
- package/dist/adapters/nextjs.d.ts.map +1 -1
- package/dist/adapters/nextjs.js +150 -73
- package/dist/adapters/node.js +150 -73
- package/dist/adapters/svelte-kit.js +150 -73
- package/dist/adapters/tanstack-start.js +150 -73
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +155 -76
- package/dist/oauth.js +152 -74
- package/dist/react.js +14 -10
- package/dist/server.js +150 -73
- package/dist/src/adapters/auto-routes.d.ts.map +1 -1
- package/dist/src/adapters/base-handler.d.ts.map +1 -1
- package/dist/src/adapters/nextjs-oauth-redirect.d.ts.map +1 -1
- package/dist/src/adapters/nextjs.d.ts.map +1 -1
- package/dist/src/client.d.ts +6 -0
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/config/types.d.ts +32 -0
- package/dist/src/config/types.d.ts.map +1 -1
- package/dist/src/server.d.ts.map +1 -1
- package/dist/src/utils/logger.d.ts +17 -6
- package/dist/src/utils/logger.d.ts.map +1 -1
- package/index.ts +3 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -20,39 +20,43 @@ function parseMessage(message) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
// src/utils/logger.ts
|
|
23
|
-
function shouldLog(level) {
|
|
24
|
-
return logLevelHierarchy[level] <= logLevelHierarchy[
|
|
23
|
+
function shouldLog(level, context) {
|
|
24
|
+
return logLevelHierarchy[level] <= logLevelHierarchy[contextLogLevels[context]];
|
|
25
25
|
}
|
|
26
|
-
function setLogLevel(level) {
|
|
27
|
-
|
|
26
|
+
function setLogLevel(level, context = "client") {
|
|
27
|
+
contextLogLevels[context] = level;
|
|
28
28
|
}
|
|
29
|
-
function createLogger(namespace) {
|
|
29
|
+
function createLogger(namespace, context = "client") {
|
|
30
30
|
const prefix = `[${namespace}]`;
|
|
31
31
|
return {
|
|
32
32
|
debug: (...args) => {
|
|
33
|
-
if (shouldLog("debug")) {
|
|
33
|
+
if (shouldLog("debug", context)) {
|
|
34
34
|
console.log(prefix, ...args);
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
info: (...args) => {
|
|
38
|
-
if (shouldLog("info")) {
|
|
38
|
+
if (shouldLog("info", context)) {
|
|
39
39
|
console.log(prefix, ...args);
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
42
|
warn: (...args) => {
|
|
43
|
-
if (shouldLog("warn")) {
|
|
43
|
+
if (shouldLog("warn", context)) {
|
|
44
44
|
console.warn(prefix, ...args);
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
47
|
error: (...args) => {
|
|
48
|
-
if (shouldLog("error")) {
|
|
48
|
+
if (shouldLog("error", context)) {
|
|
49
49
|
console.error(prefix, ...args);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
|
-
var
|
|
54
|
+
var contextLogLevels, logLevelHierarchy;
|
|
55
55
|
var init_logger = __esm(() => {
|
|
56
|
+
contextLogLevels = {
|
|
57
|
+
client: "error",
|
|
58
|
+
server: "error"
|
|
59
|
+
};
|
|
56
60
|
logLevelHierarchy = {
|
|
57
61
|
none: 0,
|
|
58
62
|
error: 1,
|
|
@@ -1728,6 +1732,7 @@ class MCPClientBase {
|
|
|
1728
1732
|
apiBaseUrl;
|
|
1729
1733
|
databaseDetected = false;
|
|
1730
1734
|
__configuredIntegrations;
|
|
1735
|
+
__useServerConfig;
|
|
1731
1736
|
oauthCallbackPromise;
|
|
1732
1737
|
server;
|
|
1733
1738
|
trigger;
|
|
@@ -1754,6 +1759,7 @@ class MCPClientBase {
|
|
|
1754
1759
|
return integration;
|
|
1755
1760
|
});
|
|
1756
1761
|
this.__configuredIntegrations = this.integrations;
|
|
1762
|
+
this.__useServerConfig = config.useServerConfig ?? false;
|
|
1757
1763
|
this.clientInfo = config.clientInfo || {
|
|
1758
1764
|
name: "integrate-sdk",
|
|
1759
1765
|
version: "0.1.0"
|
|
@@ -1897,60 +1903,12 @@ class MCPClientBase {
|
|
|
1897
1903
|
get: (_target, methodName) => {
|
|
1898
1904
|
if (methodName === "listConfiguredIntegrations") {
|
|
1899
1905
|
return async (options) => {
|
|
1906
|
+
const transportHeaders = this.transport.headers || {};
|
|
1907
|
+
const hasApiKey = !!transportHeaders["X-API-KEY"];
|
|
1900
1908
|
const serverConfig = this.__oauthConfig;
|
|
1901
|
-
const
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
const integrationsWithMetadata = await parallelWithLimit2(configuredIntegrations, async (integration) => {
|
|
1905
|
-
try {
|
|
1906
|
-
const response = await this.callServerToolInternal("list_tools_by_integration", {
|
|
1907
|
-
integration: integration.id
|
|
1908
|
-
});
|
|
1909
|
-
let toolMetadata = [];
|
|
1910
|
-
if (response.content && Array.isArray(response.content)) {
|
|
1911
|
-
for (const item of response.content) {
|
|
1912
|
-
if (item.type === "text" && item.text) {
|
|
1913
|
-
try {
|
|
1914
|
-
const parsed = JSON.parse(item.text);
|
|
1915
|
-
if (Array.isArray(parsed)) {
|
|
1916
|
-
toolMetadata = parsed;
|
|
1917
|
-
} else if (parsed.tools && Array.isArray(parsed.tools)) {
|
|
1918
|
-
toolMetadata = parsed.tools;
|
|
1919
|
-
}
|
|
1920
|
-
} catch {}
|
|
1921
|
-
}
|
|
1922
|
-
}
|
|
1923
|
-
}
|
|
1924
|
-
return {
|
|
1925
|
-
id: integration.id,
|
|
1926
|
-
name: integration.name || integration.id,
|
|
1927
|
-
logoUrl: integration.logoUrl,
|
|
1928
|
-
tools: integration.tools,
|
|
1929
|
-
hasOAuth: !!integration.oauth,
|
|
1930
|
-
scopes: integration.oauth?.scopes,
|
|
1931
|
-
provider: integration.oauth?.provider,
|
|
1932
|
-
toolMetadata
|
|
1933
|
-
};
|
|
1934
|
-
} catch (error) {
|
|
1935
|
-
logger5.error(`Failed to fetch tool metadata for ${integration.id}:`, error);
|
|
1936
|
-
return {
|
|
1937
|
-
id: integration.id,
|
|
1938
|
-
name: integration.name || integration.id,
|
|
1939
|
-
logoUrl: integration.logoUrl,
|
|
1940
|
-
tools: integration.tools,
|
|
1941
|
-
hasOAuth: !!integration.oauth,
|
|
1942
|
-
scopes: integration.oauth?.scopes,
|
|
1943
|
-
provider: integration.oauth?.provider,
|
|
1944
|
-
toolMetadata: []
|
|
1945
|
-
};
|
|
1946
|
-
}
|
|
1947
|
-
}, 3);
|
|
1948
|
-
return {
|
|
1949
|
-
integrations: integrationsWithMetadata
|
|
1950
|
-
};
|
|
1951
|
-
}
|
|
1952
|
-
return {
|
|
1953
|
-
integrations: configuredIntegrations.map((integration) => ({
|
|
1909
|
+
const localIntegrations = serverConfig?.integrations || this.__configuredIntegrations;
|
|
1910
|
+
const formatLocalIntegrations = (integrations) => ({
|
|
1911
|
+
integrations: integrations.map((integration) => ({
|
|
1954
1912
|
id: integration.id,
|
|
1955
1913
|
name: integration.name || integration.id,
|
|
1956
1914
|
logoUrl: integration.logoUrl,
|
|
@@ -1959,7 +1917,114 @@ class MCPClientBase {
|
|
|
1959
1917
|
scopes: integration.oauth?.scopes,
|
|
1960
1918
|
provider: integration.oauth?.provider
|
|
1961
1919
|
}))
|
|
1962
|
-
};
|
|
1920
|
+
});
|
|
1921
|
+
if (hasApiKey || !this.__useServerConfig) {
|
|
1922
|
+
if (options?.includeToolMetadata) {
|
|
1923
|
+
const { parallelWithLimit: parallelWithLimit2 } = await Promise.resolve().then(() => exports_concurrency);
|
|
1924
|
+
const integrationsWithMetadata = await parallelWithLimit2(localIntegrations, async (integration) => {
|
|
1925
|
+
try {
|
|
1926
|
+
const response = await this.callServerToolInternal("list_tools_by_integration", {
|
|
1927
|
+
integration: integration.id
|
|
1928
|
+
});
|
|
1929
|
+
let toolMetadata = [];
|
|
1930
|
+
if (response.content && Array.isArray(response.content)) {
|
|
1931
|
+
for (const item of response.content) {
|
|
1932
|
+
if (item.type === "text" && item.text) {
|
|
1933
|
+
try {
|
|
1934
|
+
const parsed = JSON.parse(item.text);
|
|
1935
|
+
if (Array.isArray(parsed)) {
|
|
1936
|
+
toolMetadata = parsed;
|
|
1937
|
+
} else if (parsed.tools && Array.isArray(parsed.tools)) {
|
|
1938
|
+
toolMetadata = parsed.tools;
|
|
1939
|
+
}
|
|
1940
|
+
} catch {}
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
return {
|
|
1945
|
+
id: integration.id,
|
|
1946
|
+
name: integration.name || integration.id,
|
|
1947
|
+
logoUrl: integration.logoUrl,
|
|
1948
|
+
tools: integration.tools,
|
|
1949
|
+
hasOAuth: !!integration.oauth,
|
|
1950
|
+
scopes: integration.oauth?.scopes,
|
|
1951
|
+
provider: integration.oauth?.provider,
|
|
1952
|
+
toolMetadata
|
|
1953
|
+
};
|
|
1954
|
+
} catch (error) {
|
|
1955
|
+
logger5.error(`Failed to fetch tool metadata for ${integration.id}:`, error);
|
|
1956
|
+
return {
|
|
1957
|
+
id: integration.id,
|
|
1958
|
+
name: integration.name || integration.id,
|
|
1959
|
+
logoUrl: integration.logoUrl,
|
|
1960
|
+
tools: integration.tools,
|
|
1961
|
+
hasOAuth: !!integration.oauth,
|
|
1962
|
+
scopes: integration.oauth?.scopes,
|
|
1963
|
+
provider: integration.oauth?.provider,
|
|
1964
|
+
toolMetadata: []
|
|
1965
|
+
};
|
|
1966
|
+
}
|
|
1967
|
+
}, 3);
|
|
1968
|
+
return {
|
|
1969
|
+
integrations: integrationsWithMetadata
|
|
1970
|
+
};
|
|
1971
|
+
}
|
|
1972
|
+
return formatLocalIntegrations(localIntegrations);
|
|
1973
|
+
}
|
|
1974
|
+
const url = this.apiBaseUrl ? `${this.apiBaseUrl}${this.apiRouteBase}/integrations` : `${this.apiRouteBase}/integrations`;
|
|
1975
|
+
try {
|
|
1976
|
+
const response = await fetch(url, {
|
|
1977
|
+
method: "GET",
|
|
1978
|
+
headers: {
|
|
1979
|
+
"Content-Type": "application/json"
|
|
1980
|
+
}
|
|
1981
|
+
});
|
|
1982
|
+
if (!response.ok) {
|
|
1983
|
+
logger5.error("Failed to fetch integrations from server, falling back to local config");
|
|
1984
|
+
return formatLocalIntegrations(localIntegrations);
|
|
1985
|
+
}
|
|
1986
|
+
const result = await response.json();
|
|
1987
|
+
if (options?.includeToolMetadata && result.integrations) {
|
|
1988
|
+
const { parallelWithLimit: parallelWithLimit2 } = await Promise.resolve().then(() => exports_concurrency);
|
|
1989
|
+
const integrationsWithMetadata = await parallelWithLimit2(result.integrations, async (integration) => {
|
|
1990
|
+
try {
|
|
1991
|
+
const metadataResponse = await this.callServerToolInternal("list_tools_by_integration", {
|
|
1992
|
+
integration: integration.id
|
|
1993
|
+
});
|
|
1994
|
+
let toolMetadata = [];
|
|
1995
|
+
if (metadataResponse.content && Array.isArray(metadataResponse.content)) {
|
|
1996
|
+
for (const item of metadataResponse.content) {
|
|
1997
|
+
if (item.type === "text" && item.text) {
|
|
1998
|
+
try {
|
|
1999
|
+
const parsed = JSON.parse(item.text);
|
|
2000
|
+
if (Array.isArray(parsed)) {
|
|
2001
|
+
toolMetadata = parsed;
|
|
2002
|
+
} else if (parsed.tools && Array.isArray(parsed.tools)) {
|
|
2003
|
+
toolMetadata = parsed.tools;
|
|
2004
|
+
}
|
|
2005
|
+
} catch {}
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
return {
|
|
2010
|
+
...integration,
|
|
2011
|
+
toolMetadata
|
|
2012
|
+
};
|
|
2013
|
+
} catch (error) {
|
|
2014
|
+
logger5.error(`Failed to fetch tool metadata for ${integration.id}:`, error);
|
|
2015
|
+
return {
|
|
2016
|
+
...integration,
|
|
2017
|
+
toolMetadata: []
|
|
2018
|
+
};
|
|
2019
|
+
}
|
|
2020
|
+
}, 3);
|
|
2021
|
+
return { integrations: integrationsWithMetadata };
|
|
2022
|
+
}
|
|
2023
|
+
return result;
|
|
2024
|
+
} catch (error) {
|
|
2025
|
+
logger5.error("Failed to fetch integrations from server, falling back to local config:", error);
|
|
2026
|
+
return formatLocalIntegrations(localIntegrations);
|
|
2027
|
+
}
|
|
1963
2028
|
};
|
|
1964
2029
|
}
|
|
1965
2030
|
return async (args, options) => {
|
|
@@ -2457,7 +2522,7 @@ function generateCacheKey(config) {
|
|
|
2457
2522
|
return parts.join("|");
|
|
2458
2523
|
}
|
|
2459
2524
|
function createMCPClient(config) {
|
|
2460
|
-
setLogLevel(config.debug ? "debug" : "error");
|
|
2525
|
+
setLogLevel(config.debug ? "debug" : "error", CLIENT_LOG_CONTEXT);
|
|
2461
2526
|
const useSingleton = config.singleton ?? true;
|
|
2462
2527
|
const connectionMode = config.connectionMode ?? "lazy";
|
|
2463
2528
|
const autoCleanup = config.autoCleanup ?? true;
|
|
@@ -2562,14 +2627,14 @@ async function clearClientCache() {
|
|
|
2562
2627
|
}
|
|
2563
2628
|
}));
|
|
2564
2629
|
}
|
|
2565
|
-
var MCP_SERVER_URL = "https://mcp.integrate.dev/api/v1/mcp", logger5, clientCache, cleanupClients, cleanupHandlersRegistered = false;
|
|
2630
|
+
var CLIENT_LOG_CONTEXT = "client", MCP_SERVER_URL = "https://mcp.integrate.dev/api/v1/mcp", logger5, clientCache, cleanupClients, cleanupHandlersRegistered = false;
|
|
2566
2631
|
var init_client = __esm(() => {
|
|
2567
2632
|
init_http_session();
|
|
2568
2633
|
init_messages();
|
|
2569
2634
|
init_errors();
|
|
2570
2635
|
init_logger();
|
|
2571
2636
|
init_manager();
|
|
2572
|
-
logger5 = createLogger("MCPClient");
|
|
2637
|
+
logger5 = createLogger("MCPClient", CLIENT_LOG_CONTEXT);
|
|
2573
2638
|
clientCache = new Map;
|
|
2574
2639
|
cleanupClients = new Set;
|
|
2575
2640
|
});
|
|
@@ -2776,11 +2841,11 @@ function createNextOAuthHandler(config) {
|
|
|
2776
2841
|
};
|
|
2777
2842
|
return handlers;
|
|
2778
2843
|
}
|
|
2779
|
-
var logger6;
|
|
2844
|
+
var SERVER_LOG_CONTEXT = "server", logger6;
|
|
2780
2845
|
var init_nextjs = __esm(() => {
|
|
2781
2846
|
init_base_handler();
|
|
2782
2847
|
init_logger();
|
|
2783
|
-
logger6 = createLogger("NextJSOAuth");
|
|
2848
|
+
logger6 = createLogger("NextJSOAuth", SERVER_LOG_CONTEXT);
|
|
2784
2849
|
});
|
|
2785
2850
|
|
|
2786
2851
|
// src/utils/env.ts
|
|
@@ -10195,7 +10260,7 @@ function getDefaultRedirectUri() {
|
|
|
10195
10260
|
return "http://localhost:3000/api/integrate/oauth/callback";
|
|
10196
10261
|
}
|
|
10197
10262
|
function createMCPServer(config) {
|
|
10198
|
-
setLogLevel(config.debug ? "debug" : "error");
|
|
10263
|
+
setLogLevel(config.debug ? "debug" : "error", SERVER_LOG_CONTEXT2);
|
|
10199
10264
|
if (typeof window !== "undefined") {
|
|
10200
10265
|
throw new Error("createMCPServer() should only be called on the server-side. " + "Use createMCPClient() for client-side code.");
|
|
10201
10266
|
}
|
|
@@ -10339,6 +10404,18 @@ function createMCPServer(config) {
|
|
|
10339
10404
|
return Response.json({ error: error.message || "Failed to execute tool call" }, { status: error.statusCode || 500 });
|
|
10340
10405
|
}
|
|
10341
10406
|
}
|
|
10407
|
+
if (action === "integrations" && method === "GET") {
|
|
10408
|
+
const integrations = updatedIntegrations.map((integration) => ({
|
|
10409
|
+
id: integration.id,
|
|
10410
|
+
name: integration.name || integration.id,
|
|
10411
|
+
logoUrl: integration.logoUrl,
|
|
10412
|
+
tools: integration.tools,
|
|
10413
|
+
hasOAuth: !!integration.oauth,
|
|
10414
|
+
scopes: integration.oauth?.scopes,
|
|
10415
|
+
provider: integration.oauth?.provider
|
|
10416
|
+
}));
|
|
10417
|
+
return Response.json({ integrations });
|
|
10418
|
+
}
|
|
10342
10419
|
if (segments.length >= 1 && segments[0] === "triggers") {
|
|
10343
10420
|
if (!config.triggers) {
|
|
10344
10421
|
return Response.json({ error: "Triggers not configured. Add triggers callbacks to createMCPServer config." }, { status: 501 });
|
|
@@ -10952,7 +11029,7 @@ function toSvelteKitHandler(clientOrHandlerOrOptions, _redirectOptions) {
|
|
|
10952
11029
|
}
|
|
10953
11030
|
};
|
|
10954
11031
|
}
|
|
10955
|
-
var logger30, globalServerConfig = null, codeVerifierStorage, POST = async (req, context) => {
|
|
11032
|
+
var SERVER_LOG_CONTEXT2 = "server", logger30, globalServerConfig = null, codeVerifierStorage, POST = async (req, context) => {
|
|
10956
11033
|
if (!globalServerConfig) {
|
|
10957
11034
|
return Response.json({ error: "OAuth not configured. Call createMCPServer() in your server initialization file first." }, { status: 500 });
|
|
10958
11035
|
}
|
|
@@ -11000,7 +11077,7 @@ var init_server = __esm(() => {
|
|
|
11000
11077
|
init_anthropic();
|
|
11001
11078
|
init_google();
|
|
11002
11079
|
init_ai();
|
|
11003
|
-
logger30 = createLogger("MCPServer");
|
|
11080
|
+
logger30 = createLogger("MCPServer", SERVER_LOG_CONTEXT2);
|
|
11004
11081
|
codeVerifierStorage = new Map;
|
|
11005
11082
|
});
|
|
11006
11083
|
|
|
@@ -11563,10 +11640,10 @@ class OAuthHandler {
|
|
|
11563
11640
|
return jsonRpcResponse.result;
|
|
11564
11641
|
}
|
|
11565
11642
|
}
|
|
11566
|
-
var logger31, MCP_SERVER_URL2 = "https://mcp.integrate.dev/api/v1/mcp";
|
|
11643
|
+
var SERVER_LOG_CONTEXT3 = "server", logger31, MCP_SERVER_URL2 = "https://mcp.integrate.dev/api/v1/mcp";
|
|
11567
11644
|
var init_base_handler = __esm(() => {
|
|
11568
11645
|
init_logger();
|
|
11569
|
-
logger31 = createLogger("OAuthHandler");
|
|
11646
|
+
logger31 = createLogger("OAuthHandler", SERVER_LOG_CONTEXT3);
|
|
11570
11647
|
});
|
|
11571
11648
|
|
|
11572
11649
|
// src/index.ts
|
|
@@ -11578,7 +11655,8 @@ init_nextjs();
|
|
|
11578
11655
|
|
|
11579
11656
|
// src/adapters/nextjs-oauth-redirect.ts
|
|
11580
11657
|
init_logger();
|
|
11581
|
-
var
|
|
11658
|
+
var SERVER_LOG_CONTEXT4 = "server";
|
|
11659
|
+
var logger32 = createLogger("OAuthRedirect", SERVER_LOG_CONTEXT4);
|
|
11582
11660
|
function createOAuthRedirectHandler(config) {
|
|
11583
11661
|
const defaultRedirectUrl = config?.redirectUrl || "/";
|
|
11584
11662
|
const errorRedirectUrl = config?.errorRedirectUrl || "/auth-error";
|
|
@@ -11728,7 +11806,8 @@ var client = createMCPClient({
|
|
|
11728
11806
|
hubspotIntegration(),
|
|
11729
11807
|
youtubeIntegration(),
|
|
11730
11808
|
cursorIntegration()
|
|
11731
|
-
]
|
|
11809
|
+
],
|
|
11810
|
+
useServerConfig: true
|
|
11732
11811
|
});
|
|
11733
11812
|
export {
|
|
11734
11813
|
zendeskIntegration,
|