integrate-sdk 0.7.44 → 0.7.46

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.
@@ -1226,10 +1226,10 @@ class OAuthManager {
1226
1226
  this.providerTokens.delete(provider);
1227
1227
  this.clearProviderToken(provider);
1228
1228
  }
1229
- async getProviderToken(provider) {
1229
+ async getProviderToken(provider, context) {
1230
1230
  if (this.getTokenCallback) {
1231
1231
  try {
1232
- const tokenData = await this.getTokenCallback(provider);
1232
+ const tokenData = await this.getTokenCallback(provider, context);
1233
1233
  if (tokenData) {
1234
1234
  this.providerTokens.set(provider, tokenData);
1235
1235
  }
@@ -1244,9 +1244,9 @@ class OAuthManager {
1244
1244
  getAllProviderTokens() {
1245
1245
  return new Map(this.providerTokens);
1246
1246
  }
1247
- async setProviderToken(provider, tokenData) {
1247
+ async setProviderToken(provider, tokenData, context) {
1248
1248
  this.providerTokens.set(provider, tokenData);
1249
- await this.saveProviderToken(provider, tokenData);
1249
+ await this.saveProviderToken(provider, tokenData, context);
1250
1250
  }
1251
1251
  clearProviderToken(provider) {
1252
1252
  this.providerTokens.delete(provider);
@@ -1289,10 +1289,10 @@ class OAuthManager {
1289
1289
  }
1290
1290
  }
1291
1291
  }
1292
- async saveProviderToken(provider, tokenData) {
1292
+ async saveProviderToken(provider, tokenData, context) {
1293
1293
  if (this.setTokenCallback) {
1294
1294
  try {
1295
- await this.setTokenCallback(provider, tokenData);
1295
+ await this.setTokenCallback(provider, tokenData, context);
1296
1296
  } catch (error) {
1297
1297
  console.error(`Failed to save token for ${provider} via callback:`, error);
1298
1298
  throw error;
@@ -1579,9 +1579,9 @@ class MCPClientBase {
1579
1579
  }
1580
1580
  return new Proxy({}, {
1581
1581
  get: (_target, methodName) => {
1582
- return async (args) => {
1582
+ return async (args, options) => {
1583
1583
  const toolName = methodToToolName(methodName, integrationId);
1584
- return await this.callToolWithRetry(toolName, args, 0);
1584
+ return await this.callToolWithRetry(toolName, args, 0, options);
1585
1585
  };
1586
1586
  }
1587
1587
  });
@@ -1589,17 +1589,17 @@ class MCPClientBase {
1589
1589
  createServerProxy() {
1590
1590
  return new Proxy({}, {
1591
1591
  get: (_target, methodName) => {
1592
- return async (args) => {
1592
+ return async (args, options) => {
1593
1593
  const toolName = methodToToolName(methodName, "");
1594
1594
  const finalToolName = toolName.startsWith("_") ? toolName.substring(1) : toolName;
1595
- return await this.callServerToolInternal(finalToolName, args);
1595
+ return await this.callServerToolInternal(finalToolName, args, options);
1596
1596
  };
1597
1597
  }
1598
1598
  });
1599
1599
  }
1600
- async callServerToolInternal(name, args) {
1600
+ async callServerToolInternal(name, args, options) {
1601
1601
  try {
1602
- const response = await this.callToolThroughHandler(name, args);
1602
+ const response = await this.callToolThroughHandler(name, args, undefined, options);
1603
1603
  return response;
1604
1604
  } catch (error) {
1605
1605
  const parsedError = parseServerError(error, { toolName: name });
@@ -1648,8 +1648,8 @@ class MCPClientBase {
1648
1648
  const enabledTools = response.tools.filter((tool) => this.enabledToolNames.has(tool.name));
1649
1649
  console.log(`Discovered ${response.tools.length} tools, ${enabledTools.length} enabled by integrations`);
1650
1650
  }
1651
- async _callToolByName(name, args) {
1652
- return await this.callToolWithRetry(name, args, 0);
1651
+ async _callToolByName(name, args, options) {
1652
+ return await this.callToolWithRetry(name, args, 0, options);
1653
1653
  }
1654
1654
  async callServerTool(name, args) {
1655
1655
  try {
@@ -1660,12 +1660,12 @@ class MCPClientBase {
1660
1660
  throw parsedError;
1661
1661
  }
1662
1662
  }
1663
- async callToolThroughHandler(name, args, provider) {
1663
+ async callToolThroughHandler(name, args, provider, options) {
1664
1664
  const transportHeaders = this.transport.headers || {};
1665
1665
  const hasApiKey = !!transportHeaders["X-API-KEY"];
1666
1666
  if (hasApiKey) {
1667
1667
  if (provider) {
1668
- const tokenData = await this.oauthManager.getProviderToken(provider);
1668
+ const tokenData = await this.oauthManager.getProviderToken(provider, options?.context);
1669
1669
  if (tokenData && this.transport.setHeader) {
1670
1670
  const previousAuthHeader = transportHeaders["Authorization"];
1671
1671
  try {
@@ -1695,7 +1695,7 @@ class MCPClientBase {
1695
1695
  "Content-Type": "application/json"
1696
1696
  };
1697
1697
  if (provider) {
1698
- const tokenData = await this.oauthManager.getProviderToken(provider);
1698
+ const tokenData = await this.oauthManager.getProviderToken(provider, options?.context);
1699
1699
  if (tokenData) {
1700
1700
  headers["Authorization"] = `Bearer ${tokenData.accessToken}`;
1701
1701
  }
@@ -1733,13 +1733,13 @@ class MCPClientBase {
1733
1733
  const result = await response.json();
1734
1734
  return result;
1735
1735
  }
1736
- async callToolWithRetry(name, args, retryCount = 0) {
1736
+ async callToolWithRetry(name, args, retryCount = 0, options) {
1737
1737
  if (!this.enabledToolNames.has(name)) {
1738
1738
  throw new Error(`Tool "${name}" is not enabled. Enable it by adding the appropriate integration.`);
1739
1739
  }
1740
1740
  const provider = this.getProviderForTool(name);
1741
1741
  try {
1742
- const response = await this.callToolThroughHandler(name, args, provider);
1742
+ const response = await this.callToolThroughHandler(name, args, provider, options);
1743
1743
  if (provider) {
1744
1744
  this.authState.set(provider, { authenticated: true });
1745
1745
  }
@@ -1921,11 +1921,11 @@ class MCPClientBase {
1921
1921
  throw error;
1922
1922
  }
1923
1923
  }
1924
- async getProviderToken(provider) {
1925
- return await this.oauthManager.getProviderToken(provider);
1924
+ async getProviderToken(provider, context) {
1925
+ return await this.oauthManager.getProviderToken(provider, context);
1926
1926
  }
1927
- async setProviderToken(provider, tokenData) {
1928
- await this.oauthManager.setProviderToken(provider, tokenData);
1927
+ async setProviderToken(provider, tokenData, context) {
1928
+ await this.oauthManager.setProviderToken(provider, tokenData, context);
1929
1929
  this.authState.set(provider, { authenticated: true });
1930
1930
  }
1931
1931
  getAllProviderTokens() {
@@ -1091,10 +1091,10 @@ class OAuthManager {
1091
1091
  this.providerTokens.delete(provider);
1092
1092
  this.clearProviderToken(provider);
1093
1093
  }
1094
- async getProviderToken(provider) {
1094
+ async getProviderToken(provider, context) {
1095
1095
  if (this.getTokenCallback) {
1096
1096
  try {
1097
- const tokenData = await this.getTokenCallback(provider);
1097
+ const tokenData = await this.getTokenCallback(provider, context);
1098
1098
  if (tokenData) {
1099
1099
  this.providerTokens.set(provider, tokenData);
1100
1100
  }
@@ -1109,9 +1109,9 @@ class OAuthManager {
1109
1109
  getAllProviderTokens() {
1110
1110
  return new Map(this.providerTokens);
1111
1111
  }
1112
- async setProviderToken(provider, tokenData) {
1112
+ async setProviderToken(provider, tokenData, context) {
1113
1113
  this.providerTokens.set(provider, tokenData);
1114
- await this.saveProviderToken(provider, tokenData);
1114
+ await this.saveProviderToken(provider, tokenData, context);
1115
1115
  }
1116
1116
  clearProviderToken(provider) {
1117
1117
  this.providerTokens.delete(provider);
@@ -1154,10 +1154,10 @@ class OAuthManager {
1154
1154
  }
1155
1155
  }
1156
1156
  }
1157
- async saveProviderToken(provider, tokenData) {
1157
+ async saveProviderToken(provider, tokenData, context) {
1158
1158
  if (this.setTokenCallback) {
1159
1159
  try {
1160
- await this.setTokenCallback(provider, tokenData);
1160
+ await this.setTokenCallback(provider, tokenData, context);
1161
1161
  } catch (error) {
1162
1162
  console.error(`Failed to save token for ${provider} via callback:`, error);
1163
1163
  throw error;
@@ -1444,9 +1444,9 @@ class MCPClientBase {
1444
1444
  }
1445
1445
  return new Proxy({}, {
1446
1446
  get: (_target, methodName) => {
1447
- return async (args) => {
1447
+ return async (args, options) => {
1448
1448
  const toolName = methodToToolName(methodName, integrationId);
1449
- return await this.callToolWithRetry(toolName, args, 0);
1449
+ return await this.callToolWithRetry(toolName, args, 0, options);
1450
1450
  };
1451
1451
  }
1452
1452
  });
@@ -1454,17 +1454,17 @@ class MCPClientBase {
1454
1454
  createServerProxy() {
1455
1455
  return new Proxy({}, {
1456
1456
  get: (_target, methodName) => {
1457
- return async (args) => {
1457
+ return async (args, options) => {
1458
1458
  const toolName = methodToToolName(methodName, "");
1459
1459
  const finalToolName = toolName.startsWith("_") ? toolName.substring(1) : toolName;
1460
- return await this.callServerToolInternal(finalToolName, args);
1460
+ return await this.callServerToolInternal(finalToolName, args, options);
1461
1461
  };
1462
1462
  }
1463
1463
  });
1464
1464
  }
1465
- async callServerToolInternal(name, args) {
1465
+ async callServerToolInternal(name, args, options) {
1466
1466
  try {
1467
- const response = await this.callToolThroughHandler(name, args);
1467
+ const response = await this.callToolThroughHandler(name, args, undefined, options);
1468
1468
  return response;
1469
1469
  } catch (error) {
1470
1470
  const parsedError = parseServerError(error, { toolName: name });
@@ -1513,8 +1513,8 @@ class MCPClientBase {
1513
1513
  const enabledTools = response.tools.filter((tool) => this.enabledToolNames.has(tool.name));
1514
1514
  console.log(`Discovered ${response.tools.length} tools, ${enabledTools.length} enabled by integrations`);
1515
1515
  }
1516
- async _callToolByName(name, args) {
1517
- return await this.callToolWithRetry(name, args, 0);
1516
+ async _callToolByName(name, args, options) {
1517
+ return await this.callToolWithRetry(name, args, 0, options);
1518
1518
  }
1519
1519
  async callServerTool(name, args) {
1520
1520
  try {
@@ -1525,12 +1525,12 @@ class MCPClientBase {
1525
1525
  throw parsedError;
1526
1526
  }
1527
1527
  }
1528
- async callToolThroughHandler(name, args, provider) {
1528
+ async callToolThroughHandler(name, args, provider, options) {
1529
1529
  const transportHeaders = this.transport.headers || {};
1530
1530
  const hasApiKey = !!transportHeaders["X-API-KEY"];
1531
1531
  if (hasApiKey) {
1532
1532
  if (provider) {
1533
- const tokenData = await this.oauthManager.getProviderToken(provider);
1533
+ const tokenData = await this.oauthManager.getProviderToken(provider, options?.context);
1534
1534
  if (tokenData && this.transport.setHeader) {
1535
1535
  const previousAuthHeader = transportHeaders["Authorization"];
1536
1536
  try {
@@ -1560,7 +1560,7 @@ class MCPClientBase {
1560
1560
  "Content-Type": "application/json"
1561
1561
  };
1562
1562
  if (provider) {
1563
- const tokenData = await this.oauthManager.getProviderToken(provider);
1563
+ const tokenData = await this.oauthManager.getProviderToken(provider, options?.context);
1564
1564
  if (tokenData) {
1565
1565
  headers["Authorization"] = `Bearer ${tokenData.accessToken}`;
1566
1566
  }
@@ -1598,13 +1598,13 @@ class MCPClientBase {
1598
1598
  const result = await response.json();
1599
1599
  return result;
1600
1600
  }
1601
- async callToolWithRetry(name, args, retryCount = 0) {
1601
+ async callToolWithRetry(name, args, retryCount = 0, options) {
1602
1602
  if (!this.enabledToolNames.has(name)) {
1603
1603
  throw new Error(`Tool "${name}" is not enabled. Enable it by adding the appropriate integration.`);
1604
1604
  }
1605
1605
  const provider = this.getProviderForTool(name);
1606
1606
  try {
1607
- const response = await this.callToolThroughHandler(name, args, provider);
1607
+ const response = await this.callToolThroughHandler(name, args, provider, options);
1608
1608
  if (provider) {
1609
1609
  this.authState.set(provider, { authenticated: true });
1610
1610
  }
@@ -1786,11 +1786,11 @@ class MCPClientBase {
1786
1786
  throw error;
1787
1787
  }
1788
1788
  }
1789
- async getProviderToken(provider) {
1790
- return await this.oauthManager.getProviderToken(provider);
1789
+ async getProviderToken(provider, context) {
1790
+ return await this.oauthManager.getProviderToken(provider, context);
1791
1791
  }
1792
- async setProviderToken(provider, tokenData) {
1793
- await this.oauthManager.setProviderToken(provider, tokenData);
1792
+ async setProviderToken(provider, tokenData, context) {
1793
+ await this.oauthManager.setProviderToken(provider, tokenData, context);
1794
1794
  this.authState.set(provider, { authenticated: true });
1795
1795
  }
1796
1796
  getAllProviderTokens() {
@@ -1091,10 +1091,10 @@ class OAuthManager {
1091
1091
  this.providerTokens.delete(provider);
1092
1092
  this.clearProviderToken(provider);
1093
1093
  }
1094
- async getProviderToken(provider) {
1094
+ async getProviderToken(provider, context) {
1095
1095
  if (this.getTokenCallback) {
1096
1096
  try {
1097
- const tokenData = await this.getTokenCallback(provider);
1097
+ const tokenData = await this.getTokenCallback(provider, context);
1098
1098
  if (tokenData) {
1099
1099
  this.providerTokens.set(provider, tokenData);
1100
1100
  }
@@ -1109,9 +1109,9 @@ class OAuthManager {
1109
1109
  getAllProviderTokens() {
1110
1110
  return new Map(this.providerTokens);
1111
1111
  }
1112
- async setProviderToken(provider, tokenData) {
1112
+ async setProviderToken(provider, tokenData, context) {
1113
1113
  this.providerTokens.set(provider, tokenData);
1114
- await this.saveProviderToken(provider, tokenData);
1114
+ await this.saveProviderToken(provider, tokenData, context);
1115
1115
  }
1116
1116
  clearProviderToken(provider) {
1117
1117
  this.providerTokens.delete(provider);
@@ -1154,10 +1154,10 @@ class OAuthManager {
1154
1154
  }
1155
1155
  }
1156
1156
  }
1157
- async saveProviderToken(provider, tokenData) {
1157
+ async saveProviderToken(provider, tokenData, context) {
1158
1158
  if (this.setTokenCallback) {
1159
1159
  try {
1160
- await this.setTokenCallback(provider, tokenData);
1160
+ await this.setTokenCallback(provider, tokenData, context);
1161
1161
  } catch (error) {
1162
1162
  console.error(`Failed to save token for ${provider} via callback:`, error);
1163
1163
  throw error;
@@ -1444,9 +1444,9 @@ class MCPClientBase {
1444
1444
  }
1445
1445
  return new Proxy({}, {
1446
1446
  get: (_target, methodName) => {
1447
- return async (args) => {
1447
+ return async (args, options) => {
1448
1448
  const toolName = methodToToolName(methodName, integrationId);
1449
- return await this.callToolWithRetry(toolName, args, 0);
1449
+ return await this.callToolWithRetry(toolName, args, 0, options);
1450
1450
  };
1451
1451
  }
1452
1452
  });
@@ -1454,17 +1454,17 @@ class MCPClientBase {
1454
1454
  createServerProxy() {
1455
1455
  return new Proxy({}, {
1456
1456
  get: (_target, methodName) => {
1457
- return async (args) => {
1457
+ return async (args, options) => {
1458
1458
  const toolName = methodToToolName(methodName, "");
1459
1459
  const finalToolName = toolName.startsWith("_") ? toolName.substring(1) : toolName;
1460
- return await this.callServerToolInternal(finalToolName, args);
1460
+ return await this.callServerToolInternal(finalToolName, args, options);
1461
1461
  };
1462
1462
  }
1463
1463
  });
1464
1464
  }
1465
- async callServerToolInternal(name, args) {
1465
+ async callServerToolInternal(name, args, options) {
1466
1466
  try {
1467
- const response = await this.callToolThroughHandler(name, args);
1467
+ const response = await this.callToolThroughHandler(name, args, undefined, options);
1468
1468
  return response;
1469
1469
  } catch (error) {
1470
1470
  const parsedError = parseServerError(error, { toolName: name });
@@ -1513,8 +1513,8 @@ class MCPClientBase {
1513
1513
  const enabledTools = response.tools.filter((tool) => this.enabledToolNames.has(tool.name));
1514
1514
  console.log(`Discovered ${response.tools.length} tools, ${enabledTools.length} enabled by integrations`);
1515
1515
  }
1516
- async _callToolByName(name, args) {
1517
- return await this.callToolWithRetry(name, args, 0);
1516
+ async _callToolByName(name, args, options) {
1517
+ return await this.callToolWithRetry(name, args, 0, options);
1518
1518
  }
1519
1519
  async callServerTool(name, args) {
1520
1520
  try {
@@ -1525,12 +1525,12 @@ class MCPClientBase {
1525
1525
  throw parsedError;
1526
1526
  }
1527
1527
  }
1528
- async callToolThroughHandler(name, args, provider) {
1528
+ async callToolThroughHandler(name, args, provider, options) {
1529
1529
  const transportHeaders = this.transport.headers || {};
1530
1530
  const hasApiKey = !!transportHeaders["X-API-KEY"];
1531
1531
  if (hasApiKey) {
1532
1532
  if (provider) {
1533
- const tokenData = await this.oauthManager.getProviderToken(provider);
1533
+ const tokenData = await this.oauthManager.getProviderToken(provider, options?.context);
1534
1534
  if (tokenData && this.transport.setHeader) {
1535
1535
  const previousAuthHeader = transportHeaders["Authorization"];
1536
1536
  try {
@@ -1560,7 +1560,7 @@ class MCPClientBase {
1560
1560
  "Content-Type": "application/json"
1561
1561
  };
1562
1562
  if (provider) {
1563
- const tokenData = await this.oauthManager.getProviderToken(provider);
1563
+ const tokenData = await this.oauthManager.getProviderToken(provider, options?.context);
1564
1564
  if (tokenData) {
1565
1565
  headers["Authorization"] = `Bearer ${tokenData.accessToken}`;
1566
1566
  }
@@ -1598,13 +1598,13 @@ class MCPClientBase {
1598
1598
  const result = await response.json();
1599
1599
  return result;
1600
1600
  }
1601
- async callToolWithRetry(name, args, retryCount = 0) {
1601
+ async callToolWithRetry(name, args, retryCount = 0, options) {
1602
1602
  if (!this.enabledToolNames.has(name)) {
1603
1603
  throw new Error(`Tool "${name}" is not enabled. Enable it by adding the appropriate integration.`);
1604
1604
  }
1605
1605
  const provider = this.getProviderForTool(name);
1606
1606
  try {
1607
- const response = await this.callToolThroughHandler(name, args, provider);
1607
+ const response = await this.callToolThroughHandler(name, args, provider, options);
1608
1608
  if (provider) {
1609
1609
  this.authState.set(provider, { authenticated: true });
1610
1610
  }
@@ -1786,11 +1786,11 @@ class MCPClientBase {
1786
1786
  throw error;
1787
1787
  }
1788
1788
  }
1789
- async getProviderToken(provider) {
1790
- return await this.oauthManager.getProviderToken(provider);
1789
+ async getProviderToken(provider, context) {
1790
+ return await this.oauthManager.getProviderToken(provider, context);
1791
1791
  }
1792
- async setProviderToken(provider, tokenData) {
1793
- await this.oauthManager.setProviderToken(provider, tokenData);
1792
+ async setProviderToken(provider, tokenData, context) {
1793
+ await this.oauthManager.setProviderToken(provider, tokenData, context);
1794
1794
  this.authState.set(provider, { authenticated: true });
1795
1795
  }
1796
1796
  getAllProviderTokens() {
@@ -6,8 +6,7 @@
6
6
  import type { MCPClient } from "../client.js";
7
7
  import type { MCPTool } from "../protocol/messages.js";
8
8
  import { type AIToolsOptions } from "./utils.js";
9
- import { Type } from "@google/genai";
10
- import type { Schema, FunctionDeclaration, FunctionCall } from "@google/genai";
9
+ import type { Schema, FunctionDeclaration, FunctionCall, Type } from "@google/genai";
11
10
  export type GoogleTool = FunctionDeclaration;
12
11
  export type GoogleFunctionCall = FunctionCall;
13
12
  export type { Schema, Type };
@@ -26,10 +25,10 @@ export interface GoogleToolsOptions extends AIToolsOptions {
26
25
  *
27
26
  * @example
28
27
  * ```typescript
29
- * const googleTool = convertMCPToolToGoogle(mcpTool, client);
28
+ * const googleTool = await convertMCPToolToGoogle(mcpTool, client);
30
29
  * ```
31
30
  */
32
- export declare function convertMCPToolToGoogle(mcpTool: MCPTool, _client: MCPClient<any>, _options?: GoogleToolsOptions): GoogleTool;
31
+ export declare function convertMCPToolToGoogle(mcpTool: MCPTool, _client: MCPClient<any>, _options?: GoogleToolsOptions): Promise<GoogleTool>;
33
32
  /**
34
33
  * Convert all enabled MCP tools to Google GenAI format
35
34
  *
@@ -40,15 +39,15 @@ export declare function convertMCPToolToGoogle(mcpTool: MCPTool, _client: MCPCli
40
39
  * @example
41
40
  * ```typescript
42
41
  * // Client-side usage
43
- * const tools = convertMCPToolsToGoogle(mcpClient);
42
+ * const tools = await convertMCPToolsToGoogle(mcpClient);
44
43
  *
45
44
  * // Server-side with provider tokens
46
- * const tools = convertMCPToolsToGoogle(serverClient, {
45
+ * const tools = await convertMCPToolsToGoogle(serverClient, {
47
46
  * providerTokens: { github: 'ghp_...', gmail: 'ya29...' }
48
47
  * });
49
48
  * ```
50
49
  */
51
- export declare function convertMCPToolsToGoogle(client: MCPClient<any>, options?: GoogleToolsOptions): GoogleTool[];
50
+ export declare function convertMCPToolsToGoogle(client: MCPClient<any>, options?: GoogleToolsOptions): Promise<GoogleTool[]>;
52
51
  /**
53
52
  * Execute a function call from Google GenAI
54
53
  *
@@ -1 +1 @@
1
- {"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../../src/ai/google.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,EAAkE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAIjH,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,KAAK,EACV,MAAM,EACN,mBAAmB,EACnB,YAAY,EACb,MAAM,eAAe,CAAC;AAGvB,MAAM,MAAM,UAAU,GAAG,mBAAmB,CAAC;AAC7C,MAAM,MAAM,kBAAkB,GAAG,YAAY,CAAC;AAC9C,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AAE7B;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,cAAc;CAAI;AA4D9D;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE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AAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,UAAU,EAAE,CAAC,CAevB"}
package/dist/ai/google.js CHANGED
@@ -4203,19 +4203,22 @@ async function ensureClientConnected(client) {
4203
4203
  }
4204
4204
 
4205
4205
  // google.ts
4206
- import { Type } from "@google/genai";
4207
- function convertJsonSchemaTypeToGoogleType(type) {
4206
+ async function getGoogleType() {
4207
+ const { Type } = await import("@google/genai");
4208
+ return Type;
4209
+ }
4210
+ function convertJsonSchemaTypeToGoogleType(type, TypeEnum) {
4208
4211
  const typeMap = {
4209
- string: Type.STRING,
4210
- number: Type.NUMBER,
4211
- integer: Type.INTEGER,
4212
- boolean: Type.BOOLEAN,
4213
- array: Type.ARRAY,
4214
- object: Type.OBJECT
4212
+ string: TypeEnum.STRING,
4213
+ number: TypeEnum.NUMBER,
4214
+ integer: TypeEnum.INTEGER,
4215
+ boolean: TypeEnum.BOOLEAN,
4216
+ array: TypeEnum.ARRAY,
4217
+ object: TypeEnum.OBJECT
4215
4218
  };
4216
- return typeMap[type.toLowerCase()] || Type.STRING;
4219
+ return typeMap[type.toLowerCase()] || TypeEnum.STRING;
4217
4220
  }
4218
- function convertPropertiesToSchema(properties) {
4221
+ function convertPropertiesToSchema(properties, TypeEnum) {
4219
4222
  const result = {};
4220
4223
  for (const [key, value] of Object.entries(properties)) {
4221
4224
  if (!value || typeof value !== "object") {
@@ -4227,13 +4230,13 @@ function convertPropertiesToSchema(properties) {
4227
4230
  enum: value.enum
4228
4231
  };
4229
4232
  if (value.type) {
4230
- schema.type = convertJsonSchemaTypeToGoogleType(value.type);
4233
+ schema.type = convertJsonSchemaTypeToGoogleType(value.type, TypeEnum);
4231
4234
  }
4232
4235
  if (value.items) {
4233
- schema.items = convertPropertiesToSchema({ items: value.items }).items;
4236
+ schema.items = convertPropertiesToSchema({ items: value.items }, TypeEnum).items;
4234
4237
  }
4235
4238
  if (value.properties) {
4236
- schema.properties = convertPropertiesToSchema(value.properties);
4239
+ schema.properties = convertPropertiesToSchema(value.properties, TypeEnum);
4237
4240
  }
4238
4241
  for (const [k, v] of Object.entries(value)) {
4239
4242
  if (!["type", "description", "enum", "items", "properties"].includes(k)) {
@@ -4244,11 +4247,12 @@ function convertPropertiesToSchema(properties) {
4244
4247
  }
4245
4248
  return result;
4246
4249
  }
4247
- function convertMCPToolToGoogle(mcpTool, _client, _options) {
4250
+ async function convertMCPToolToGoogle(mcpTool, _client, _options) {
4251
+ const TypeEnum = await getGoogleType();
4248
4252
  const properties = mcpTool.inputSchema?.properties || {};
4249
- const convertedProperties = convertPropertiesToSchema(properties);
4253
+ const convertedProperties = convertPropertiesToSchema(properties, TypeEnum);
4250
4254
  const parameters = {
4251
- type: Type.OBJECT,
4255
+ type: TypeEnum.OBJECT,
4252
4256
  description: mcpTool.description || "",
4253
4257
  properties: convertedProperties
4254
4258
  };
@@ -4261,9 +4265,9 @@ function convertMCPToolToGoogle(mcpTool, _client, _options) {
4261
4265
  parameters
4262
4266
  };
4263
4267
  }
4264
- function convertMCPToolsToGoogle(client, options) {
4268
+ async function convertMCPToolsToGoogle(client, options) {
4265
4269
  const mcpTools = client.getEnabledTools();
4266
- return mcpTools.map((mcpTool) => convertMCPToolToGoogle(mcpTool, client, options));
4270
+ return await Promise.all(mcpTools.map((mcpTool) => convertMCPToolToGoogle(mcpTool, client, options)));
4267
4271
  }
4268
4272
  async function executeGoogleFunctionCall(client, functionCall, options) {
4269
4273
  if (!functionCall?.name) {
package/dist/ai/index.js CHANGED
@@ -4317,19 +4317,22 @@ async function getCloudflareTools(client, options) {
4317
4317
  }
4318
4318
 
4319
4319
  // google.ts
4320
- import { Type } from "@google/genai";
4321
- function convertJsonSchemaTypeToGoogleType(type) {
4320
+ async function getGoogleType() {
4321
+ const { Type } = await import("@google/genai");
4322
+ return Type;
4323
+ }
4324
+ function convertJsonSchemaTypeToGoogleType(type, TypeEnum) {
4322
4325
  const typeMap = {
4323
- string: Type.STRING,
4324
- number: Type.NUMBER,
4325
- integer: Type.INTEGER,
4326
- boolean: Type.BOOLEAN,
4327
- array: Type.ARRAY,
4328
- object: Type.OBJECT
4326
+ string: TypeEnum.STRING,
4327
+ number: TypeEnum.NUMBER,
4328
+ integer: TypeEnum.INTEGER,
4329
+ boolean: TypeEnum.BOOLEAN,
4330
+ array: TypeEnum.ARRAY,
4331
+ object: TypeEnum.OBJECT
4329
4332
  };
4330
- return typeMap[type.toLowerCase()] || Type.STRING;
4333
+ return typeMap[type.toLowerCase()] || TypeEnum.STRING;
4331
4334
  }
4332
- function convertPropertiesToSchema(properties) {
4335
+ function convertPropertiesToSchema(properties, TypeEnum) {
4333
4336
  const result = {};
4334
4337
  for (const [key, value] of Object.entries(properties)) {
4335
4338
  if (!value || typeof value !== "object") {
@@ -4341,13 +4344,13 @@ function convertPropertiesToSchema(properties) {
4341
4344
  enum: value.enum
4342
4345
  };
4343
4346
  if (value.type) {
4344
- schema.type = convertJsonSchemaTypeToGoogleType(value.type);
4347
+ schema.type = convertJsonSchemaTypeToGoogleType(value.type, TypeEnum);
4345
4348
  }
4346
4349
  if (value.items) {
4347
- schema.items = convertPropertiesToSchema({ items: value.items }).items;
4350
+ schema.items = convertPropertiesToSchema({ items: value.items }, TypeEnum).items;
4348
4351
  }
4349
4352
  if (value.properties) {
4350
- schema.properties = convertPropertiesToSchema(value.properties);
4353
+ schema.properties = convertPropertiesToSchema(value.properties, TypeEnum);
4351
4354
  }
4352
4355
  for (const [k, v] of Object.entries(value)) {
4353
4356
  if (!["type", "description", "enum", "items", "properties"].includes(k)) {
@@ -4358,11 +4361,12 @@ function convertPropertiesToSchema(properties) {
4358
4361
  }
4359
4362
  return result;
4360
4363
  }
4361
- function convertMCPToolToGoogle(mcpTool, _client, _options) {
4364
+ async function convertMCPToolToGoogle(mcpTool, _client, _options) {
4365
+ const TypeEnum = await getGoogleType();
4362
4366
  const properties = mcpTool.inputSchema?.properties || {};
4363
- const convertedProperties = convertPropertiesToSchema(properties);
4367
+ const convertedProperties = convertPropertiesToSchema(properties, TypeEnum);
4364
4368
  const parameters = {
4365
- type: Type.OBJECT,
4369
+ type: TypeEnum.OBJECT,
4366
4370
  description: mcpTool.description || "",
4367
4371
  properties: convertedProperties
4368
4372
  };
@@ -4375,9 +4379,9 @@ function convertMCPToolToGoogle(mcpTool, _client, _options) {
4375
4379
  parameters
4376
4380
  };
4377
4381
  }
4378
- function convertMCPToolsToGoogle(client, options) {
4382
+ async function convertMCPToolsToGoogle(client, options) {
4379
4383
  const mcpTools = client.getEnabledTools();
4380
- return mcpTools.map((mcpTool) => convertMCPToolToGoogle(mcpTool, client, options));
4384
+ return await Promise.all(mcpTools.map((mcpTool) => convertMCPToolToGoogle(mcpTool, client, options)));
4381
4385
  }
4382
4386
  async function executeGoogleFunctionCall(client, functionCall, options) {
4383
4387
  if (!functionCall?.name) {
@@ -4426,7 +4430,10 @@ function convertMCPToolToVercelAI(mcpTool, client, options) {
4426
4430
  description: mcpTool.description || `Execute ${mcpTool.name}`,
4427
4431
  inputSchema: jsonSchemaToZod(mcpTool.inputSchema),
4428
4432
  execute: async (args) => {
4429
- return await executeToolWithToken(client, mcpTool.name, args, options);
4433
+ if (options?.providerTokens) {
4434
+ return await executeToolWithToken(client, mcpTool.name, args, options);
4435
+ }
4436
+ return await client._callToolByName(mcpTool.name, args, options?.context ? { context: options.context } : undefined);
4430
4437
  }
4431
4438
  };
4432
4439
  }
@@ -6,6 +6,7 @@
6
6
  import { z } from "zod";
7
7
  import type { MCPClient } from "../client.js";
8
8
  import type { MCPTool } from "../protocol/messages.js";
9
+ import type { MCPContext } from "../config/types.js";
9
10
  import { type AIToolsOptions } from "./utils.js";
10
11
  /**
11
12
  * Tool definition compatible with Vercel AI SDK v5
@@ -20,13 +21,15 @@ export interface VercelAITool {
20
21
  * Options for converting MCP tools to Vercel AI SDK format
21
22
  */
22
23
  export interface VercelAIToolsOptions extends AIToolsOptions {
24
+ /** User context for multi-tenant token storage */
25
+ context?: MCPContext;
23
26
  }
24
27
  /**
25
28
  * Convert a single MCP tool to Vercel AI SDK format
26
29
  *
27
30
  * @param mcpTool - The MCP tool definition
28
31
  * @param client - The MCP client instance (used for executing the tool)
29
- * @param options - Optional configuration including provider tokens
32
+ * @param options - Optional configuration including provider tokens and context
30
33
  * @returns Vercel AI SDK compatible tool definition
31
34
  */
32
35
  export declare function convertMCPToolToVercelAI(mcpTool: MCPTool, client: MCPClient<any>, options?: VercelAIToolsOptions): VercelAITool;
@@ -109,11 +112,12 @@ export declare function convertMCPToolsToVercelAI(client: MCPClient<any>, option
109
112
  *
110
113
  * export async function POST(req: Request) {
111
114
  * const { messages } = await req.json();
115
+ * const userId = await getUserIdFromSession(req);
112
116
  *
113
117
  * const result = streamText({
114
118
  * model: "openai/gpt-4",
115
119
  * messages,
116
- * tools: await getVercelAITools(serverClient), // Tokens auto-extracted
120
+ * tools: await getVercelAITools(serverClient, { context: { userId } }), // Pass user context
117
121
  * });
118
122
  *
119
123
  * return result.toUIMessageStreamResponse();