integrate-sdk 0.6.6 → 0.6.8
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/svelte-kit.js +1 -1
- package/dist/index.js +68 -33
- package/dist/server.js +67 -11
- package/dist/src/adapters/node.d.ts +1 -1
- package/dist/src/adapters/solid-start.d.ts +1 -1
- package/dist/src/adapters/svelte-kit.d.ts +2 -2
- package/dist/src/adapters/svelte-kit.d.ts.map +1 -1
- package/dist/src/adapters/tanstack-start.d.ts +2 -2
- package/dist/src/integrations/anthropic.d.ts +208 -0
- package/dist/src/integrations/anthropic.d.ts.map +1 -0
- package/dist/src/integrations/cloudflare.d.ts +158 -0
- package/dist/src/integrations/cloudflare.d.ts.map +1 -0
- package/dist/src/integrations/google.d.ts +159 -0
- package/dist/src/integrations/google.d.ts.map +1 -0
- package/dist/src/integrations/index.d.ts +79 -0
- package/dist/src/integrations/index.d.ts.map +1 -0
- package/dist/src/integrations/langchain.d.ts +139 -0
- package/dist/src/integrations/langchain.d.ts.map +1 -0
- package/dist/src/integrations/llamaindex.d.ts +125 -0
- package/dist/src/integrations/llamaindex.d.ts.map +1 -0
- package/dist/src/integrations/mastra.d.ts +138 -0
- package/dist/src/integrations/mastra.d.ts.map +1 -0
- package/dist/src/integrations/openai-agents.d.ts +117 -0
- package/dist/src/integrations/openai-agents.d.ts.map +1 -0
- package/dist/src/integrations/openai.d.ts +158 -0
- package/dist/src/integrations/openai.d.ts.map +1 -0
- package/dist/src/integrations/utils.d.ts +56 -0
- package/dist/src/integrations/utils.d.ts.map +1 -0
- package/dist/src/integrations/vercel-ai.d.ts +2 -16
- package/dist/src/integrations/vercel-ai.d.ts.map +1 -1
- package/dist/src/plugins/generic.d.ts.map +1 -1
- package/dist/src/plugins/github.d.ts.map +1 -1
- package/dist/src/plugins/gmail.d.ts.map +1 -1
- package/dist/src/server.d.ts +7 -0
- package/dist/src/server.d.ts.map +1 -1
- package/dist/src/utils/env.d.ts +18 -0
- package/dist/src/utils/env.d.ts.map +1 -0
- package/integrations.ts +9 -0
- package/package.json +77 -4
package/dist/index.js
CHANGED
|
@@ -2043,7 +2043,7 @@ async function svelteKitHandler({
|
|
|
2043
2043
|
authConfig,
|
|
2044
2044
|
event,
|
|
2045
2045
|
resolve,
|
|
2046
|
-
basePath = "/api/
|
|
2046
|
+
basePath = "/api/integrate"
|
|
2047
2047
|
}) {
|
|
2048
2048
|
const { url } = event;
|
|
2049
2049
|
const baseUrl = new URL(basePath, url.origin);
|
|
@@ -2072,6 +2072,33 @@ var createTanStackOAuthHandler = toTanStackStartHandler;
|
|
|
2072
2072
|
// src/index.ts
|
|
2073
2073
|
init_errors();
|
|
2074
2074
|
|
|
2075
|
+
// src/utils/env.ts
|
|
2076
|
+
function getEnv(key) {
|
|
2077
|
+
try {
|
|
2078
|
+
const getMetaEnv = () => {
|
|
2079
|
+
try {
|
|
2080
|
+
return typeof import.meta !== "undefined" ? import.meta.env : undefined;
|
|
2081
|
+
} catch {
|
|
2082
|
+
return;
|
|
2083
|
+
}
|
|
2084
|
+
};
|
|
2085
|
+
const metaEnv = getMetaEnv();
|
|
2086
|
+
if (metaEnv && typeof metaEnv === "object" && metaEnv !== null) {
|
|
2087
|
+
const value = metaEnv[key];
|
|
2088
|
+
if (value !== undefined && value !== null && value !== "") {
|
|
2089
|
+
return String(value);
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
} catch {}
|
|
2093
|
+
if (typeof process !== "undefined" && process.env) {
|
|
2094
|
+
const value = process.env[key];
|
|
2095
|
+
if (value !== undefined && value !== null && value !== "") {
|
|
2096
|
+
return value;
|
|
2097
|
+
}
|
|
2098
|
+
}
|
|
2099
|
+
return;
|
|
2100
|
+
}
|
|
2101
|
+
|
|
2075
2102
|
// src/plugins/github.ts
|
|
2076
2103
|
var GITHUB_TOOLS = [
|
|
2077
2104
|
"github_create_issue",
|
|
@@ -2096,8 +2123,8 @@ var GITHUB_TOOLS = [
|
|
|
2096
2123
|
function githubPlugin(config = {}) {
|
|
2097
2124
|
const oauth = {
|
|
2098
2125
|
provider: "github",
|
|
2099
|
-
clientId: config.clientId ??
|
|
2100
|
-
clientSecret: config.clientSecret ??
|
|
2126
|
+
clientId: config.clientId ?? getEnv("GITHUB_CLIENT_ID"),
|
|
2127
|
+
clientSecret: config.clientSecret ?? getEnv("GITHUB_CLIENT_SECRET"),
|
|
2101
2128
|
scopes: config.scopes || ["repo", "user"],
|
|
2102
2129
|
redirectUri: config.redirectUri,
|
|
2103
2130
|
config: {
|
|
@@ -2127,8 +2154,8 @@ var GMAIL_TOOLS = [
|
|
|
2127
2154
|
function gmailPlugin(config = {}) {
|
|
2128
2155
|
const oauth = {
|
|
2129
2156
|
provider: "gmail",
|
|
2130
|
-
clientId: config.clientId ??
|
|
2131
|
-
clientSecret: config.clientSecret ??
|
|
2157
|
+
clientId: config.clientId ?? getEnv("GMAIL_CLIENT_ID"),
|
|
2158
|
+
clientSecret: config.clientSecret ?? getEnv("GMAIL_CLIENT_SECRET"),
|
|
2132
2159
|
scopes: config.scopes || [
|
|
2133
2160
|
"https://www.googleapis.com/auth/gmail.send",
|
|
2134
2161
|
"https://www.googleapis.com/auth/gmail.readonly",
|
|
@@ -2155,8 +2182,8 @@ function genericOAuthPlugin(config) {
|
|
|
2155
2182
|
const providerUpper = config.provider.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
2156
2183
|
const oauth = {
|
|
2157
2184
|
provider: config.provider,
|
|
2158
|
-
clientId: config.clientId ??
|
|
2159
|
-
clientSecret: config.clientSecret ??
|
|
2185
|
+
clientId: config.clientId ?? getEnv(`${providerUpper}_CLIENT_ID`),
|
|
2186
|
+
clientSecret: config.clientSecret ?? getEnv(`${providerUpper}_CLIENT_SECRET`),
|
|
2160
2187
|
scopes: config.scopes,
|
|
2161
2188
|
redirectUri: config.redirectUri,
|
|
2162
2189
|
config
|
|
@@ -6152,7 +6179,7 @@ var coerce = {
|
|
|
6152
6179
|
date: (arg) => ZodDate.create({ ...arg, coerce: true })
|
|
6153
6180
|
};
|
|
6154
6181
|
var NEVER = INVALID;
|
|
6155
|
-
// src/integrations/
|
|
6182
|
+
// src/integrations/utils.ts
|
|
6156
6183
|
function getProviderForTool(client, toolName) {
|
|
6157
6184
|
return client.getProviderForTool?.(toolName);
|
|
6158
6185
|
}
|
|
@@ -6266,33 +6293,43 @@ function jsonSchemaToZod(schema) {
|
|
|
6266
6293
|
}
|
|
6267
6294
|
return exports_external.object({});
|
|
6268
6295
|
}
|
|
6296
|
+
async function executeToolWithToken(client, toolName, args, options) {
|
|
6297
|
+
if (options?.providerTokens) {
|
|
6298
|
+
const provider = getProviderForTool(client, toolName);
|
|
6299
|
+
if (provider && options.providerTokens[provider]) {
|
|
6300
|
+
const transport = client.transport;
|
|
6301
|
+
if (transport && typeof transport.setHeader === "function") {
|
|
6302
|
+
const previousAuthHeader = transport.headers?.["Authorization"];
|
|
6303
|
+
try {
|
|
6304
|
+
transport.setHeader("Authorization", `Bearer ${options.providerTokens[provider]}`);
|
|
6305
|
+
const result2 = await client._callToolByName(toolName, args);
|
|
6306
|
+
return result2;
|
|
6307
|
+
} finally {
|
|
6308
|
+
if (previousAuthHeader) {
|
|
6309
|
+
transport.setHeader("Authorization", previousAuthHeader);
|
|
6310
|
+
} else if (transport.removeHeader) {
|
|
6311
|
+
transport.removeHeader("Authorization");
|
|
6312
|
+
}
|
|
6313
|
+
}
|
|
6314
|
+
}
|
|
6315
|
+
}
|
|
6316
|
+
}
|
|
6317
|
+
const result = await client._callToolByName(toolName, args);
|
|
6318
|
+
return result;
|
|
6319
|
+
}
|
|
6320
|
+
async function ensureClientConnected(client) {
|
|
6321
|
+
if (!client.isConnected()) {
|
|
6322
|
+
await client.connect();
|
|
6323
|
+
}
|
|
6324
|
+
}
|
|
6325
|
+
|
|
6326
|
+
// src/integrations/vercel-ai.ts
|
|
6269
6327
|
function convertMCPToolToVercelAI(mcpTool, client, options) {
|
|
6270
6328
|
return {
|
|
6271
6329
|
description: mcpTool.description || `Execute ${mcpTool.name}`,
|
|
6272
6330
|
inputSchema: jsonSchemaToZod(mcpTool.inputSchema),
|
|
6273
6331
|
execute: async (args) => {
|
|
6274
|
-
|
|
6275
|
-
const provider = getProviderForTool(client, mcpTool.name);
|
|
6276
|
-
if (provider && options.providerTokens[provider]) {
|
|
6277
|
-
const transport = client.transport;
|
|
6278
|
-
if (transport && typeof transport.setHeader === "function") {
|
|
6279
|
-
const previousAuthHeader = transport.headers?.["Authorization"];
|
|
6280
|
-
try {
|
|
6281
|
-
transport.setHeader("Authorization", `Bearer ${options.providerTokens[provider]}`);
|
|
6282
|
-
const result2 = await client._callToolByName(mcpTool.name, args);
|
|
6283
|
-
return result2;
|
|
6284
|
-
} finally {
|
|
6285
|
-
if (previousAuthHeader) {
|
|
6286
|
-
transport.setHeader("Authorization", previousAuthHeader);
|
|
6287
|
-
} else if (transport.removeHeader) {
|
|
6288
|
-
transport.removeHeader("Authorization");
|
|
6289
|
-
}
|
|
6290
|
-
}
|
|
6291
|
-
}
|
|
6292
|
-
}
|
|
6293
|
-
}
|
|
6294
|
-
const result = await client._callToolByName(mcpTool.name, args);
|
|
6295
|
-
return result;
|
|
6332
|
+
return await executeToolWithToken(client, mcpTool.name, args, options);
|
|
6296
6333
|
}
|
|
6297
6334
|
};
|
|
6298
6335
|
}
|
|
@@ -6305,9 +6342,7 @@ function convertMCPToolsToVercelAI(client, options) {
|
|
|
6305
6342
|
return vercelTools;
|
|
6306
6343
|
}
|
|
6307
6344
|
async function getVercelAITools(client, options) {
|
|
6308
|
-
|
|
6309
|
-
await client.connect();
|
|
6310
|
-
}
|
|
6345
|
+
await ensureClientConnected(client);
|
|
6311
6346
|
return convertMCPToolsToVercelAI(client, options);
|
|
6312
6347
|
}
|
|
6313
6348
|
export {
|
package/dist/server.js
CHANGED
|
@@ -1852,6 +1852,33 @@ function createNextOAuthHandler(config) {
|
|
|
1852
1852
|
return handlers;
|
|
1853
1853
|
}
|
|
1854
1854
|
|
|
1855
|
+
// src/utils/env.ts
|
|
1856
|
+
function getEnv(key) {
|
|
1857
|
+
try {
|
|
1858
|
+
const getMetaEnv = () => {
|
|
1859
|
+
try {
|
|
1860
|
+
return typeof import.meta !== "undefined" ? import.meta.env : undefined;
|
|
1861
|
+
} catch {
|
|
1862
|
+
return;
|
|
1863
|
+
}
|
|
1864
|
+
};
|
|
1865
|
+
const metaEnv = getMetaEnv();
|
|
1866
|
+
if (metaEnv && typeof metaEnv === "object" && metaEnv !== null) {
|
|
1867
|
+
const value = metaEnv[key];
|
|
1868
|
+
if (value !== undefined && value !== null && value !== "") {
|
|
1869
|
+
return String(value);
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
} catch {}
|
|
1873
|
+
if (typeof process !== "undefined" && process.env) {
|
|
1874
|
+
const value = process.env[key];
|
|
1875
|
+
if (value !== undefined && value !== null && value !== "") {
|
|
1876
|
+
return value;
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
return;
|
|
1880
|
+
}
|
|
1881
|
+
|
|
1855
1882
|
// src/plugins/github.ts
|
|
1856
1883
|
var GITHUB_TOOLS = [
|
|
1857
1884
|
"github_create_issue",
|
|
@@ -1876,8 +1903,8 @@ var GITHUB_TOOLS = [
|
|
|
1876
1903
|
function githubPlugin(config = {}) {
|
|
1877
1904
|
const oauth = {
|
|
1878
1905
|
provider: "github",
|
|
1879
|
-
clientId: config.clientId ??
|
|
1880
|
-
clientSecret: config.clientSecret ??
|
|
1906
|
+
clientId: config.clientId ?? getEnv("GITHUB_CLIENT_ID"),
|
|
1907
|
+
clientSecret: config.clientSecret ?? getEnv("GITHUB_CLIENT_SECRET"),
|
|
1881
1908
|
scopes: config.scopes || ["repo", "user"],
|
|
1882
1909
|
redirectUri: config.redirectUri,
|
|
1883
1910
|
config: {
|
|
@@ -1907,8 +1934,8 @@ var GMAIL_TOOLS = [
|
|
|
1907
1934
|
function gmailPlugin(config = {}) {
|
|
1908
1935
|
const oauth = {
|
|
1909
1936
|
provider: "gmail",
|
|
1910
|
-
clientId: config.clientId ??
|
|
1911
|
-
clientSecret: config.clientSecret ??
|
|
1937
|
+
clientId: config.clientId ?? getEnv("GMAIL_CLIENT_ID"),
|
|
1938
|
+
clientSecret: config.clientSecret ?? getEnv("GMAIL_CLIENT_SECRET"),
|
|
1912
1939
|
scopes: config.scopes || [
|
|
1913
1940
|
"https://www.googleapis.com/auth/gmail.send",
|
|
1914
1941
|
"https://www.googleapis.com/auth/gmail.readonly",
|
|
@@ -1935,8 +1962,8 @@ function genericOAuthPlugin(config) {
|
|
|
1935
1962
|
const providerUpper = config.provider.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
1936
1963
|
const oauth = {
|
|
1937
1964
|
provider: config.provider,
|
|
1938
|
-
clientId: config.clientId ??
|
|
1939
|
-
clientSecret: config.clientSecret ??
|
|
1965
|
+
clientId: config.clientId ?? getEnv(`${providerUpper}_CLIENT_ID`),
|
|
1966
|
+
clientSecret: config.clientSecret ?? getEnv(`${providerUpper}_CLIENT_SECRET`),
|
|
1940
1967
|
scopes: config.scopes,
|
|
1941
1968
|
redirectUri: config.redirectUri,
|
|
1942
1969
|
config
|
|
@@ -1966,11 +1993,13 @@ function getDefaultRedirectUri() {
|
|
|
1966
1993
|
if (typeof window !== "undefined") {
|
|
1967
1994
|
return `${window.location.origin}/api/integrate/oauth/callback`;
|
|
1968
1995
|
}
|
|
1969
|
-
|
|
1970
|
-
|
|
1996
|
+
const integrateUrl = getEnv("INTEGRATE_URL");
|
|
1997
|
+
if (integrateUrl) {
|
|
1998
|
+
return `${integrateUrl}/api/integrate/oauth/callback`;
|
|
1971
1999
|
}
|
|
1972
|
-
|
|
1973
|
-
|
|
2000
|
+
const vercelUrl = getEnv("VERCEL_URL");
|
|
2001
|
+
if (vercelUrl) {
|
|
2002
|
+
return `https://${vercelUrl}/api/integrate/oauth/callback`;
|
|
1974
2003
|
}
|
|
1975
2004
|
return "http://localhost:3000/api/integrate/oauth/callback";
|
|
1976
2005
|
}
|
|
@@ -2027,10 +2056,37 @@ function createMCPServer(config) {
|
|
|
2027
2056
|
serverUrl: config.serverUrl,
|
|
2028
2057
|
apiKey: config.apiKey
|
|
2029
2058
|
});
|
|
2059
|
+
const handler = async (request, context) => {
|
|
2060
|
+
const method = request.method.toUpperCase();
|
|
2061
|
+
let action;
|
|
2062
|
+
if (context?.params?.action) {
|
|
2063
|
+
action = context.params.action;
|
|
2064
|
+
} else if (context?.params?.all) {
|
|
2065
|
+
const all = context.params.all;
|
|
2066
|
+
if (Array.isArray(all)) {
|
|
2067
|
+
action = all[all.length - 1];
|
|
2068
|
+
} else if (typeof all === "string") {
|
|
2069
|
+
action = all.split("/").pop();
|
|
2070
|
+
}
|
|
2071
|
+
} else {
|
|
2072
|
+
const url = new URL(request.url);
|
|
2073
|
+
const pathParts = url.pathname.split("/").filter(Boolean);
|
|
2074
|
+
action = pathParts[pathParts.length - 1] || "callback";
|
|
2075
|
+
}
|
|
2076
|
+
const handlerContext = { params: { action: action || "callback" } };
|
|
2077
|
+
if (method === "POST") {
|
|
2078
|
+
return POST(request, handlerContext);
|
|
2079
|
+
} else if (method === "GET") {
|
|
2080
|
+
return GET(request, handlerContext);
|
|
2081
|
+
} else {
|
|
2082
|
+
return Response.json({ error: `Method ${method} not allowed` }, { status: 405 });
|
|
2083
|
+
}
|
|
2084
|
+
};
|
|
2030
2085
|
return {
|
|
2031
2086
|
client,
|
|
2032
2087
|
POST,
|
|
2033
|
-
GET
|
|
2088
|
+
GET,
|
|
2089
|
+
handler
|
|
2034
2090
|
};
|
|
2035
2091
|
}
|
|
2036
2092
|
function createOAuthRouteHandlers(config) {
|
|
@@ -35,7 +35,7 @@ export declare function fromNodeHeaders(nodeHeaders: IncomingHttpHeaders): Heade
|
|
|
35
35
|
* });
|
|
36
36
|
*
|
|
37
37
|
* createServer(async (req, res) => {
|
|
38
|
-
* if (req.url?.startsWith('/api/
|
|
38
|
+
* if (req.url?.startsWith('/api/integrate/')) {
|
|
39
39
|
* await handler(req, res);
|
|
40
40
|
* } else {
|
|
41
41
|
* res.statusCode = 404;
|
|
@@ -12,7 +12,7 @@ type ResolveFunction = any;
|
|
|
12
12
|
* @param authConfig - Handler function from createMCPServer
|
|
13
13
|
* @param event - SvelteKit RequestEvent
|
|
14
14
|
* @param resolve - SvelteKit resolve function
|
|
15
|
-
* @param basePath - Base path for OAuth routes (default: '/api/
|
|
15
|
+
* @param basePath - Base path for OAuth routes (default: '/api/integrate')
|
|
16
16
|
* @returns Response from OAuth handler or resolved request
|
|
17
17
|
*
|
|
18
18
|
* @example
|
|
@@ -67,7 +67,7 @@ export declare function svelteKitHandler({ authConfig, event, resolve, basePath,
|
|
|
67
67
|
* ],
|
|
68
68
|
* });
|
|
69
69
|
*
|
|
70
|
-
* // routes/api/
|
|
70
|
+
* // routes/api/integrate/[...all]/+server.ts
|
|
71
71
|
* import { toSvelteKitHandler } from 'integrate-sdk/adapters/svelte-kit';
|
|
72
72
|
* import { handler } from '$lib/integrate-server';
|
|
73
73
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"svelte-kit.d.ts","sourceRoot":"","sources":["../../../src/adapters/svelte-kit.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,KAAK,YAAY,GAAG,GAAG,CAAC;AACxB,KAAK,eAAe,GAAG,GAAG,CAAC;AAE3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAsB,gBAAgB,CAAC,EACnC,UAAU,EACV,KAAK,EACL,OAAO,EACP,
|
|
1
|
+
{"version":3,"file":"svelte-kit.d.ts","sourceRoot":"","sources":["../../../src/adapters/svelte-kit.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,KAAK,YAAY,GAAG,GAAG,CAAC;AACxB,KAAK,eAAe,GAAG,GAAG,CAAC;AAE3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAsB,gBAAgB,CAAC,EACnC,UAAU,EACV,KAAK,EACL,OAAO,EACP,QAA2B,GAC9B,EAAE;IACC,UAAU,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IACpD,KAAK,EAAE,YAAY,CAAC;IACpB,OAAO,EAAE,eAAe,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAWpB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,IACrE,OAAO,YAAY,KAAG,OAAO,CAAC,QAAQ,CAAC,CAGxD"}
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
* ],
|
|
26
26
|
* });
|
|
27
27
|
*
|
|
28
|
-
* // app/routes/api/
|
|
28
|
+
* // app/routes/api/integrate/$.ts
|
|
29
29
|
* import { toTanStackStartHandler } from 'integrate-sdk/adapters/tanstack-start';
|
|
30
30
|
* import { handler } from '@/lib/integrate-server';
|
|
31
31
|
*
|
|
32
32
|
* const handlers = toTanStackStartHandler(handler);
|
|
33
33
|
*
|
|
34
|
-
* export const Route = createFileRoute('/api/
|
|
34
|
+
* export const Route = createFileRoute('/api/integrate/$')({
|
|
35
35
|
* server: {
|
|
36
36
|
* handlers: {
|
|
37
37
|
* GET: handlers.GET,
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anthropic Claude Integration
|
|
3
|
+
*
|
|
4
|
+
* Helper functions to convert MCP tools to Anthropic Claude API format
|
|
5
|
+
*/
|
|
6
|
+
import type { MCPClient } from "../client.js";
|
|
7
|
+
import type { MCPTool } from "../protocol/messages.js";
|
|
8
|
+
import { type AIToolsOptions } from "./utils.js";
|
|
9
|
+
/**
|
|
10
|
+
* Anthropic tool definition
|
|
11
|
+
* Compatible with Anthropic's Claude API
|
|
12
|
+
*/
|
|
13
|
+
export interface AnthropicTool {
|
|
14
|
+
name: string;
|
|
15
|
+
description: string;
|
|
16
|
+
input_schema: {
|
|
17
|
+
type: 'object';
|
|
18
|
+
properties?: Record<string, unknown>;
|
|
19
|
+
required?: string[];
|
|
20
|
+
[key: string]: unknown;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Options for converting MCP tools to Anthropic format
|
|
25
|
+
*/
|
|
26
|
+
export interface AnthropicToolsOptions extends AIToolsOptions {
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Anthropic tool use block from message content
|
|
30
|
+
*/
|
|
31
|
+
export interface AnthropicToolUseBlock {
|
|
32
|
+
type: 'tool_use';
|
|
33
|
+
id: string;
|
|
34
|
+
name: string;
|
|
35
|
+
input: Record<string, unknown>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Anthropic tool result block for responses
|
|
39
|
+
*/
|
|
40
|
+
export interface AnthropicToolResultBlock {
|
|
41
|
+
type: 'tool_result';
|
|
42
|
+
tool_use_id: string;
|
|
43
|
+
content: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Convert a single MCP tool to Anthropic Claude API format
|
|
47
|
+
*
|
|
48
|
+
* @param mcpTool - The MCP tool definition
|
|
49
|
+
* @param client - The MCP client instance (used for executing the tool)
|
|
50
|
+
* @param options - Optional configuration including provider tokens
|
|
51
|
+
* @returns Anthropic compatible tool definition
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const anthropicTool = convertMCPToolToAnthropic(mcpTool, client);
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare function convertMCPToolToAnthropic(mcpTool: MCPTool, _client: MCPClient<any>, _options?: AnthropicToolsOptions): AnthropicTool;
|
|
59
|
+
/**
|
|
60
|
+
* Convert all enabled MCP tools to Anthropic Claude API format
|
|
61
|
+
*
|
|
62
|
+
* @param client - The MCP client instance (must be connected)
|
|
63
|
+
* @param options - Optional configuration including provider tokens
|
|
64
|
+
* @returns Array of Anthropic compatible tool definitions
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* // Client-side usage
|
|
69
|
+
* const tools = convertMCPToolsToAnthropic(mcpClient);
|
|
70
|
+
*
|
|
71
|
+
* // Server-side with provider tokens
|
|
72
|
+
* const tools = convertMCPToolsToAnthropic(serverClient, {
|
|
73
|
+
* providerTokens: { github: 'ghp_...', gmail: 'ya29...' }
|
|
74
|
+
* });
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare function convertMCPToolsToAnthropic(client: MCPClient<any>, options?: AnthropicToolsOptions): AnthropicTool[];
|
|
78
|
+
/**
|
|
79
|
+
* Execute a tool call from Anthropic's response
|
|
80
|
+
*
|
|
81
|
+
* @param client - The MCP client instance
|
|
82
|
+
* @param toolUse - The tool use block from Anthropic response
|
|
83
|
+
* @param options - Optional configuration including provider tokens
|
|
84
|
+
* @returns Tool execution result as JSON string
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const result = await executeAnthropicToolCall(client, {
|
|
89
|
+
* type: 'tool_use',
|
|
90
|
+
* id: 'toolu_123',
|
|
91
|
+
* name: 'github_create_issue',
|
|
92
|
+
* input: { owner: 'user', repo: 'repo', title: 'Bug' }
|
|
93
|
+
* }, { providerTokens });
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export declare function executeAnthropicToolCall(client: MCPClient<any>, toolUse: AnthropicToolUseBlock, options?: AnthropicToolsOptions): Promise<string>;
|
|
97
|
+
/**
|
|
98
|
+
* Handle all tool calls from Anthropic's message response
|
|
99
|
+
* Executes all tool use blocks and returns tool result blocks
|
|
100
|
+
*
|
|
101
|
+
* @param client - The MCP client instance
|
|
102
|
+
* @param messageContent - Array of content blocks from Anthropic message
|
|
103
|
+
* @param options - Optional configuration including provider tokens
|
|
104
|
+
* @returns Array of tool result blocks ready to send back to Claude
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const response = await anthropic.messages.create({
|
|
109
|
+
* model: 'claude-3-5-sonnet-20241022',
|
|
110
|
+
* max_tokens: 1024,
|
|
111
|
+
* tools,
|
|
112
|
+
* messages: [{ role: 'user', content: 'Create a GitHub issue' }]
|
|
113
|
+
* });
|
|
114
|
+
*
|
|
115
|
+
* // Handle tool calls
|
|
116
|
+
* const toolResults = await handleAnthropicToolCalls(
|
|
117
|
+
* client,
|
|
118
|
+
* response.content,
|
|
119
|
+
* { providerTokens }
|
|
120
|
+
* );
|
|
121
|
+
*
|
|
122
|
+
* // Continue conversation with tool results
|
|
123
|
+
* const finalResponse = await anthropic.messages.create({
|
|
124
|
+
* model: 'claude-3-5-sonnet-20241022',
|
|
125
|
+
* max_tokens: 1024,
|
|
126
|
+
* tools,
|
|
127
|
+
* messages: [
|
|
128
|
+
* { role: 'user', content: 'Create a GitHub issue' },
|
|
129
|
+
* { role: 'assistant', content: response.content },
|
|
130
|
+
* { role: 'user', content: toolResults }
|
|
131
|
+
* ]
|
|
132
|
+
* });
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
export declare function handleAnthropicToolCalls(client: MCPClient<any>, messageContent: Array<{
|
|
136
|
+
type: string;
|
|
137
|
+
[key: string]: any;
|
|
138
|
+
}>, options?: AnthropicToolsOptions): Promise<AnthropicToolResultBlock[]>;
|
|
139
|
+
/**
|
|
140
|
+
* Get tools in a format compatible with Anthropic Claude API
|
|
141
|
+
*
|
|
142
|
+
* Automatically connects the client if not already connected.
|
|
143
|
+
*
|
|
144
|
+
* @param client - The MCP client instance
|
|
145
|
+
* @param options - Optional configuration including provider tokens for server-side usage
|
|
146
|
+
* @returns Array of tools ready to pass to Claude API
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* // Client-side usage
|
|
151
|
+
* import { createMCPClient, githubPlugin } from 'integrate-sdk';
|
|
152
|
+
* import { getAnthropicTools } from 'integrate-sdk/integrations/anthropic';
|
|
153
|
+
* import Anthropic from '@anthropic-ai/sdk';
|
|
154
|
+
*
|
|
155
|
+
* const client = createMCPClient({
|
|
156
|
+
* plugins: [githubPlugin({ clientId: '...' })],
|
|
157
|
+
* });
|
|
158
|
+
*
|
|
159
|
+
* const tools = await getAnthropicTools(client);
|
|
160
|
+
* const anthropic = new Anthropic({ apiKey: '...' });
|
|
161
|
+
*
|
|
162
|
+
* const message = await anthropic.messages.create({
|
|
163
|
+
* model: 'claude-3-5-sonnet-20241022',
|
|
164
|
+
* max_tokens: 1024,
|
|
165
|
+
* tools,
|
|
166
|
+
* messages: [{ role: 'user', content: 'Create a GitHub issue' }]
|
|
167
|
+
* });
|
|
168
|
+
* ```
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```typescript
|
|
172
|
+
* // Server-side usage with tokens from client
|
|
173
|
+
* import { createMCPServer, githubPlugin } from 'integrate-sdk/server';
|
|
174
|
+
* import { getAnthropicTools, handleAnthropicToolCalls } from 'integrate-sdk/integrations/anthropic';
|
|
175
|
+
*
|
|
176
|
+
* const { client: serverClient } = createMCPServer({
|
|
177
|
+
* plugins: [githubPlugin({
|
|
178
|
+
* clientId: '...',
|
|
179
|
+
* clientSecret: '...'
|
|
180
|
+
* })],
|
|
181
|
+
* });
|
|
182
|
+
*
|
|
183
|
+
* // In your API route
|
|
184
|
+
* export async function POST(req: Request) {
|
|
185
|
+
* const providerTokens = JSON.parse(req.headers.get('x-integrate-tokens') || '{}');
|
|
186
|
+
* const tools = await getAnthropicTools(serverClient, { providerTokens });
|
|
187
|
+
*
|
|
188
|
+
* const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
|
|
189
|
+
* const message = await anthropic.messages.create({
|
|
190
|
+
* model: 'claude-3-5-sonnet-20241022',
|
|
191
|
+
* max_tokens: 1024,
|
|
192
|
+
* tools,
|
|
193
|
+
* messages: [{ role: 'user', content: 'Create a GitHub issue' }]
|
|
194
|
+
* });
|
|
195
|
+
*
|
|
196
|
+
* // Handle any tool calls
|
|
197
|
+
* const toolResults = await handleAnthropicToolCalls(
|
|
198
|
+
* serverClient,
|
|
199
|
+
* message.content,
|
|
200
|
+
* { providerTokens }
|
|
201
|
+
* );
|
|
202
|
+
*
|
|
203
|
+
* return Response.json({ message, toolResults });
|
|
204
|
+
* }
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
export declare function getAnthropicTools(client: MCPClient<any>, options?: AnthropicToolsOptions): Promise<AnthropicTool[]>;
|
|
208
|
+
//# sourceMappingURL=anthropic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../../src/integrations/anthropic.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAA+C,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAE9F;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE;QACZ,IAAI,EAAE,QAAQ,CAAC;QACf,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACrC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;QACpB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,cAAc;CAAI;AAEjE;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,UAAU,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,aAAa,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,SAAS,CAAC,GAAG,CAAC,EACvB,QAAQ,CAAC,EAAE,qBAAqB,GAC/B,aAAa,CAUf;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,aAAa,EAAE,CAGjB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,OAAO,EAAE,qBAAqB,EAC9B,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,MAAM,CAAC,CAGjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,cAAc,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAA,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,CAAC,EAC1D,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,wBAAwB,EAAE,CAAC,CAkCrC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,aAAa,EAAE,CAAC,CAG1B"}
|