integrate-sdk 0.7.40 → 0.7.42
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/ai/google.d.ts +63 -45
- package/dist/ai/google.d.ts.map +1 -1
- package/dist/ai/google.js +65 -7
- package/dist/ai/index.js +65 -7
- package/dist/server.js +65 -7
- package/dist/src/ai/google.d.ts +63 -45
- package/dist/src/ai/google.d.ts.map +1 -1
- package/package.json +6 -5
package/dist/ai/google.d.ts
CHANGED
|
@@ -6,28 +6,11 @@
|
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export
|
|
14
|
-
name: string;
|
|
15
|
-
description: string;
|
|
16
|
-
parameters: {
|
|
17
|
-
type: 'object';
|
|
18
|
-
description?: string;
|
|
19
|
-
properties?: Record<string, unknown>;
|
|
20
|
-
required?: string[];
|
|
21
|
-
[key: string]: unknown;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Google GenAI function call
|
|
26
|
-
*/
|
|
27
|
-
export interface GoogleFunctionCall {
|
|
28
|
-
name: string;
|
|
29
|
-
args: Record<string, unknown>;
|
|
30
|
-
}
|
|
9
|
+
import { Type } from "@google/genai";
|
|
10
|
+
import type { Schema, FunctionDeclaration, FunctionCall } from "@google/genai";
|
|
11
|
+
export type GoogleTool = FunctionDeclaration;
|
|
12
|
+
export type GoogleFunctionCall = FunctionCall;
|
|
13
|
+
export type { Schema, Type };
|
|
31
14
|
/**
|
|
32
15
|
* Options for converting MCP tools to Google GenAI format
|
|
33
16
|
*/
|
|
@@ -83,6 +66,39 @@ export declare function convertMCPToolsToGoogle(client: MCPClient<any>, options?
|
|
|
83
66
|
* ```
|
|
84
67
|
*/
|
|
85
68
|
export declare function executeGoogleFunctionCall(client: MCPClient<any>, functionCall: GoogleFunctionCall, options?: GoogleToolsOptions): Promise<string>;
|
|
69
|
+
/**
|
|
70
|
+
* Execute multiple function calls from Google GenAI response
|
|
71
|
+
*
|
|
72
|
+
* This function handles the transformation from Google's function call format
|
|
73
|
+
* to the format expected by the SDK, then executes each call.
|
|
74
|
+
*
|
|
75
|
+
* @param client - The MCP client instance
|
|
76
|
+
* @param functionCalls - Array of function calls from Google GenAI response
|
|
77
|
+
* @param options - Optional configuration including provider tokens
|
|
78
|
+
* @returns Array of execution results
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* // In your API route
|
|
83
|
+
* const response = await ai.models.generateContent({
|
|
84
|
+
* model: 'gemini-2.0-flash-001',
|
|
85
|
+
* contents: messages,
|
|
86
|
+
* config: {
|
|
87
|
+
* tools: [{ functionDeclarations: await getGoogleTools(serverClient) }],
|
|
88
|
+
* },
|
|
89
|
+
* });
|
|
90
|
+
*
|
|
91
|
+
* if (response.functionCalls && response.functionCalls.length > 0) {
|
|
92
|
+
* const results = await executeGoogleFunctionCalls(
|
|
93
|
+
* serverClient,
|
|
94
|
+
* response.functionCalls,
|
|
95
|
+
* { providerTokens }
|
|
96
|
+
* );
|
|
97
|
+
* return Response.json(results);
|
|
98
|
+
* }
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export declare function executeGoogleFunctionCalls(client: MCPClient<any>, functionCalls: GoogleFunctionCall[] | undefined | null, options?: GoogleToolsOptions): Promise<string[]>;
|
|
86
102
|
/**
|
|
87
103
|
* Get tools in a format compatible with Google GenAI
|
|
88
104
|
*
|
|
@@ -97,21 +113,21 @@ export declare function executeGoogleFunctionCall(client: MCPClient<any>, functi
|
|
|
97
113
|
* // Client-side usage
|
|
98
114
|
* import { createMCPClient, githubIntegration } from 'integrate-sdk';
|
|
99
115
|
* import { getGoogleTools } from 'integrate-sdk/ai/google';
|
|
100
|
-
* import {
|
|
116
|
+
* import { genai } from '@google/genai';
|
|
101
117
|
*
|
|
102
118
|
* const client = createMCPClient({
|
|
103
119
|
* integrations: [githubIntegration({ clientId: '...' })],
|
|
104
120
|
* });
|
|
105
121
|
*
|
|
106
122
|
* const tools = await getGoogleTools(client);
|
|
107
|
-
* const
|
|
108
|
-
* const model = genAI.getGenerativeModel({
|
|
109
|
-
* model: 'gemini-pro',
|
|
110
|
-
* tools: [{ functionDeclarations: tools }]
|
|
111
|
-
* });
|
|
123
|
+
* const ai = genai({ apiKey: 'YOUR_API_KEY' });
|
|
112
124
|
*
|
|
113
|
-
* const
|
|
114
|
-
*
|
|
125
|
+
* const response = await ai.models.generateContent({
|
|
126
|
+
* model: 'gemini-2.0-flash-001',
|
|
127
|
+
* contents: messages,
|
|
128
|
+
* config: {
|
|
129
|
+
* tools: [{ functionDeclarations: tools }]
|
|
130
|
+
* }
|
|
115
131
|
* });
|
|
116
132
|
* ```
|
|
117
133
|
*
|
|
@@ -119,7 +135,8 @@ export declare function executeGoogleFunctionCall(client: MCPClient<any>, functi
|
|
|
119
135
|
* ```typescript
|
|
120
136
|
* // Server-side usage with tokens from client
|
|
121
137
|
* import { createMCPServer, githubIntegration } from 'integrate-sdk/server';
|
|
122
|
-
* import { getGoogleTools,
|
|
138
|
+
* import { getGoogleTools, executeGoogleFunctionCalls } from 'integrate-sdk/ai/google';
|
|
139
|
+
* import { genai } from '@google/genai';
|
|
123
140
|
*
|
|
124
141
|
* const { client: serverClient } = createMCPServer({
|
|
125
142
|
* integrations: [githubIntegration({
|
|
@@ -133,25 +150,26 @@ export declare function executeGoogleFunctionCall(client: MCPClient<any>, functi
|
|
|
133
150
|
* const providerTokens = JSON.parse(req.headers.get('x-integrate-tokens') || '{}');
|
|
134
151
|
* const tools = await getGoogleTools(serverClient, { providerTokens });
|
|
135
152
|
*
|
|
136
|
-
* const
|
|
137
|
-
* const
|
|
138
|
-
* model: 'gemini-
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
* contents: [{ role: 'user', parts: [{ text: 'Create a GitHub issue' }] }]
|
|
153
|
+
* const ai = genai({ apiKey: process.env.GOOGLE_API_KEY });
|
|
154
|
+
* const response = await ai.models.generateContent({
|
|
155
|
+
* model: 'gemini-2.0-flash-001',
|
|
156
|
+
* contents: messages,
|
|
157
|
+
* config: {
|
|
158
|
+
* tools: [{ functionDeclarations: tools }]
|
|
159
|
+
* }
|
|
144
160
|
* });
|
|
145
161
|
*
|
|
146
162
|
* // Handle function calls if any
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
163
|
+
* if (response.functionCalls && response.functionCalls.length > 0) {
|
|
164
|
+
* const results = await executeGoogleFunctionCalls(
|
|
165
|
+
* serverClient,
|
|
166
|
+
* response.functionCalls,
|
|
167
|
+
* { providerTokens }
|
|
168
|
+
* );
|
|
169
|
+
* return Response.json(results);
|
|
152
170
|
* }
|
|
153
171
|
*
|
|
154
|
-
* return Response.json(
|
|
172
|
+
* return Response.json(response);
|
|
155
173
|
* }
|
|
156
174
|
* ```
|
|
157
175
|
*/
|
package/dist/ai/google.d.ts.map
CHANGED
|
@@ -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;
|
|
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,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;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,UAAU,EAAE,CAAC,CAevB"}
|
package/dist/ai/google.js
CHANGED
|
@@ -4203,16 +4203,62 @@ async function ensureClientConnected(client) {
|
|
|
4203
4203
|
}
|
|
4204
4204
|
|
|
4205
4205
|
// google.ts
|
|
4206
|
+
import { Type } from "@google/genai";
|
|
4207
|
+
function convertJsonSchemaTypeToGoogleType(type) {
|
|
4208
|
+
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
|
|
4215
|
+
};
|
|
4216
|
+
return typeMap[type.toLowerCase()] || Type.STRING;
|
|
4217
|
+
}
|
|
4218
|
+
function convertPropertiesToSchema(properties) {
|
|
4219
|
+
const result = {};
|
|
4220
|
+
for (const [key, value] of Object.entries(properties)) {
|
|
4221
|
+
if (!value || typeof value !== "object") {
|
|
4222
|
+
result[key] = value;
|
|
4223
|
+
continue;
|
|
4224
|
+
}
|
|
4225
|
+
const schema = {
|
|
4226
|
+
description: value.description,
|
|
4227
|
+
enum: value.enum
|
|
4228
|
+
};
|
|
4229
|
+
if (value.type) {
|
|
4230
|
+
schema.type = convertJsonSchemaTypeToGoogleType(value.type);
|
|
4231
|
+
}
|
|
4232
|
+
if (value.items) {
|
|
4233
|
+
schema.items = convertPropertiesToSchema({ items: value.items }).items;
|
|
4234
|
+
}
|
|
4235
|
+
if (value.properties) {
|
|
4236
|
+
schema.properties = convertPropertiesToSchema(value.properties);
|
|
4237
|
+
}
|
|
4238
|
+
for (const [k, v] of Object.entries(value)) {
|
|
4239
|
+
if (!["type", "description", "enum", "items", "properties"].includes(k)) {
|
|
4240
|
+
schema[k] = v;
|
|
4241
|
+
}
|
|
4242
|
+
}
|
|
4243
|
+
result[key] = schema;
|
|
4244
|
+
}
|
|
4245
|
+
return result;
|
|
4246
|
+
}
|
|
4206
4247
|
function convertMCPToolToGoogle(mcpTool, _client, _options) {
|
|
4248
|
+
const properties = mcpTool.inputSchema?.properties || {};
|
|
4249
|
+
const convertedProperties = convertPropertiesToSchema(properties);
|
|
4250
|
+
const parameters = {
|
|
4251
|
+
type: Type.OBJECT,
|
|
4252
|
+
description: mcpTool.description || "",
|
|
4253
|
+
properties: convertedProperties
|
|
4254
|
+
};
|
|
4255
|
+
if (mcpTool.inputSchema?.required && mcpTool.inputSchema.required.length > 0) {
|
|
4256
|
+
parameters.required = mcpTool.inputSchema.required;
|
|
4257
|
+
}
|
|
4207
4258
|
return {
|
|
4208
4259
|
name: mcpTool.name,
|
|
4209
4260
|
description: mcpTool.description || `Execute ${mcpTool.name}`,
|
|
4210
|
-
parameters
|
|
4211
|
-
type: "object",
|
|
4212
|
-
description: mcpTool.description || "",
|
|
4213
|
-
properties: mcpTool.inputSchema?.properties || {},
|
|
4214
|
-
required: mcpTool.inputSchema?.required || []
|
|
4215
|
-
}
|
|
4261
|
+
parameters
|
|
4216
4262
|
};
|
|
4217
4263
|
}
|
|
4218
4264
|
function convertMCPToolsToGoogle(client, options) {
|
|
@@ -4220,9 +4266,20 @@ function convertMCPToolsToGoogle(client, options) {
|
|
|
4220
4266
|
return mcpTools.map((mcpTool) => convertMCPToolToGoogle(mcpTool, client, options));
|
|
4221
4267
|
}
|
|
4222
4268
|
async function executeGoogleFunctionCall(client, functionCall, options) {
|
|
4223
|
-
|
|
4269
|
+
if (!functionCall?.name) {
|
|
4270
|
+
throw new Error("Function call must have a name");
|
|
4271
|
+
}
|
|
4272
|
+
const args = functionCall.args || {};
|
|
4273
|
+
const result = await executeToolWithToken(client, functionCall.name, args, options);
|
|
4224
4274
|
return JSON.stringify(result);
|
|
4225
4275
|
}
|
|
4276
|
+
async function executeGoogleFunctionCalls(client, functionCalls, options) {
|
|
4277
|
+
if (!functionCalls || functionCalls.length === 0) {
|
|
4278
|
+
return [];
|
|
4279
|
+
}
|
|
4280
|
+
const results = await Promise.all(functionCalls.map((call) => executeGoogleFunctionCall(client, call, options)));
|
|
4281
|
+
return results;
|
|
4282
|
+
}
|
|
4226
4283
|
async function getGoogleTools(client, options) {
|
|
4227
4284
|
await ensureClientConnected(client);
|
|
4228
4285
|
let providerTokens = options?.providerTokens;
|
|
@@ -4236,6 +4293,7 @@ async function getGoogleTools(client, options) {
|
|
|
4236
4293
|
}
|
|
4237
4294
|
export {
|
|
4238
4295
|
getGoogleTools,
|
|
4296
|
+
executeGoogleFunctionCalls,
|
|
4239
4297
|
executeGoogleFunctionCall,
|
|
4240
4298
|
convertMCPToolsToGoogle,
|
|
4241
4299
|
convertMCPToolToGoogle
|
package/dist/ai/index.js
CHANGED
|
@@ -4317,16 +4317,62 @@ async function getCloudflareTools(client, options) {
|
|
|
4317
4317
|
}
|
|
4318
4318
|
|
|
4319
4319
|
// google.ts
|
|
4320
|
+
import { Type } from "@google/genai";
|
|
4321
|
+
function convertJsonSchemaTypeToGoogleType(type) {
|
|
4322
|
+
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
|
|
4329
|
+
};
|
|
4330
|
+
return typeMap[type.toLowerCase()] || Type.STRING;
|
|
4331
|
+
}
|
|
4332
|
+
function convertPropertiesToSchema(properties) {
|
|
4333
|
+
const result = {};
|
|
4334
|
+
for (const [key, value] of Object.entries(properties)) {
|
|
4335
|
+
if (!value || typeof value !== "object") {
|
|
4336
|
+
result[key] = value;
|
|
4337
|
+
continue;
|
|
4338
|
+
}
|
|
4339
|
+
const schema = {
|
|
4340
|
+
description: value.description,
|
|
4341
|
+
enum: value.enum
|
|
4342
|
+
};
|
|
4343
|
+
if (value.type) {
|
|
4344
|
+
schema.type = convertJsonSchemaTypeToGoogleType(value.type);
|
|
4345
|
+
}
|
|
4346
|
+
if (value.items) {
|
|
4347
|
+
schema.items = convertPropertiesToSchema({ items: value.items }).items;
|
|
4348
|
+
}
|
|
4349
|
+
if (value.properties) {
|
|
4350
|
+
schema.properties = convertPropertiesToSchema(value.properties);
|
|
4351
|
+
}
|
|
4352
|
+
for (const [k, v] of Object.entries(value)) {
|
|
4353
|
+
if (!["type", "description", "enum", "items", "properties"].includes(k)) {
|
|
4354
|
+
schema[k] = v;
|
|
4355
|
+
}
|
|
4356
|
+
}
|
|
4357
|
+
result[key] = schema;
|
|
4358
|
+
}
|
|
4359
|
+
return result;
|
|
4360
|
+
}
|
|
4320
4361
|
function convertMCPToolToGoogle(mcpTool, _client, _options) {
|
|
4362
|
+
const properties = mcpTool.inputSchema?.properties || {};
|
|
4363
|
+
const convertedProperties = convertPropertiesToSchema(properties);
|
|
4364
|
+
const parameters = {
|
|
4365
|
+
type: Type.OBJECT,
|
|
4366
|
+
description: mcpTool.description || "",
|
|
4367
|
+
properties: convertedProperties
|
|
4368
|
+
};
|
|
4369
|
+
if (mcpTool.inputSchema?.required && mcpTool.inputSchema.required.length > 0) {
|
|
4370
|
+
parameters.required = mcpTool.inputSchema.required;
|
|
4371
|
+
}
|
|
4321
4372
|
return {
|
|
4322
4373
|
name: mcpTool.name,
|
|
4323
4374
|
description: mcpTool.description || `Execute ${mcpTool.name}`,
|
|
4324
|
-
parameters
|
|
4325
|
-
type: "object",
|
|
4326
|
-
description: mcpTool.description || "",
|
|
4327
|
-
properties: mcpTool.inputSchema?.properties || {},
|
|
4328
|
-
required: mcpTool.inputSchema?.required || []
|
|
4329
|
-
}
|
|
4375
|
+
parameters
|
|
4330
4376
|
};
|
|
4331
4377
|
}
|
|
4332
4378
|
function convertMCPToolsToGoogle(client, options) {
|
|
@@ -4334,9 +4380,20 @@ function convertMCPToolsToGoogle(client, options) {
|
|
|
4334
4380
|
return mcpTools.map((mcpTool) => convertMCPToolToGoogle(mcpTool, client, options));
|
|
4335
4381
|
}
|
|
4336
4382
|
async function executeGoogleFunctionCall(client, functionCall, options) {
|
|
4337
|
-
|
|
4383
|
+
if (!functionCall?.name) {
|
|
4384
|
+
throw new Error("Function call must have a name");
|
|
4385
|
+
}
|
|
4386
|
+
const args = functionCall.args || {};
|
|
4387
|
+
const result = await executeToolWithToken(client, functionCall.name, args, options);
|
|
4338
4388
|
return JSON.stringify(result);
|
|
4339
4389
|
}
|
|
4390
|
+
async function executeGoogleFunctionCalls(client, functionCalls, options) {
|
|
4391
|
+
if (!functionCalls || functionCalls.length === 0) {
|
|
4392
|
+
return [];
|
|
4393
|
+
}
|
|
4394
|
+
const results = await Promise.all(functionCalls.map((call) => executeGoogleFunctionCall(client, call, options)));
|
|
4395
|
+
return results;
|
|
4396
|
+
}
|
|
4340
4397
|
async function getGoogleTools(client, options) {
|
|
4341
4398
|
await ensureClientConnected(client);
|
|
4342
4399
|
let providerTokens = options?.providerTokens;
|
|
@@ -4616,6 +4673,7 @@ export {
|
|
|
4616
4673
|
getAITools,
|
|
4617
4674
|
executeToolWithToken,
|
|
4618
4675
|
executeOpenAIToolCall,
|
|
4676
|
+
executeGoogleFunctionCalls,
|
|
4619
4677
|
executeGoogleFunctionCall,
|
|
4620
4678
|
executeCloudflareToolCall,
|
|
4621
4679
|
executeAnthropicToolCall,
|
package/dist/server.js
CHANGED
|
@@ -6675,16 +6675,62 @@ async function handleAnthropicMessage(client, message, options) {
|
|
|
6675
6675
|
];
|
|
6676
6676
|
}
|
|
6677
6677
|
// src/ai/google.ts
|
|
6678
|
+
import { Type } from "@google/genai";
|
|
6679
|
+
function convertJsonSchemaTypeToGoogleType(type) {
|
|
6680
|
+
const typeMap = {
|
|
6681
|
+
string: Type.STRING,
|
|
6682
|
+
number: Type.NUMBER,
|
|
6683
|
+
integer: Type.INTEGER,
|
|
6684
|
+
boolean: Type.BOOLEAN,
|
|
6685
|
+
array: Type.ARRAY,
|
|
6686
|
+
object: Type.OBJECT
|
|
6687
|
+
};
|
|
6688
|
+
return typeMap[type.toLowerCase()] || Type.STRING;
|
|
6689
|
+
}
|
|
6690
|
+
function convertPropertiesToSchema(properties) {
|
|
6691
|
+
const result = {};
|
|
6692
|
+
for (const [key, value] of Object.entries(properties)) {
|
|
6693
|
+
if (!value || typeof value !== "object") {
|
|
6694
|
+
result[key] = value;
|
|
6695
|
+
continue;
|
|
6696
|
+
}
|
|
6697
|
+
const schema = {
|
|
6698
|
+
description: value.description,
|
|
6699
|
+
enum: value.enum
|
|
6700
|
+
};
|
|
6701
|
+
if (value.type) {
|
|
6702
|
+
schema.type = convertJsonSchemaTypeToGoogleType(value.type);
|
|
6703
|
+
}
|
|
6704
|
+
if (value.items) {
|
|
6705
|
+
schema.items = convertPropertiesToSchema({ items: value.items }).items;
|
|
6706
|
+
}
|
|
6707
|
+
if (value.properties) {
|
|
6708
|
+
schema.properties = convertPropertiesToSchema(value.properties);
|
|
6709
|
+
}
|
|
6710
|
+
for (const [k, v] of Object.entries(value)) {
|
|
6711
|
+
if (!["type", "description", "enum", "items", "properties"].includes(k)) {
|
|
6712
|
+
schema[k] = v;
|
|
6713
|
+
}
|
|
6714
|
+
}
|
|
6715
|
+
result[key] = schema;
|
|
6716
|
+
}
|
|
6717
|
+
return result;
|
|
6718
|
+
}
|
|
6678
6719
|
function convertMCPToolToGoogle(mcpTool, _client, _options) {
|
|
6720
|
+
const properties = mcpTool.inputSchema?.properties || {};
|
|
6721
|
+
const convertedProperties = convertPropertiesToSchema(properties);
|
|
6722
|
+
const parameters = {
|
|
6723
|
+
type: Type.OBJECT,
|
|
6724
|
+
description: mcpTool.description || "",
|
|
6725
|
+
properties: convertedProperties
|
|
6726
|
+
};
|
|
6727
|
+
if (mcpTool.inputSchema?.required && mcpTool.inputSchema.required.length > 0) {
|
|
6728
|
+
parameters.required = mcpTool.inputSchema.required;
|
|
6729
|
+
}
|
|
6679
6730
|
return {
|
|
6680
6731
|
name: mcpTool.name,
|
|
6681
6732
|
description: mcpTool.description || `Execute ${mcpTool.name}`,
|
|
6682
|
-
parameters
|
|
6683
|
-
type: "object",
|
|
6684
|
-
description: mcpTool.description || "",
|
|
6685
|
-
properties: mcpTool.inputSchema?.properties || {},
|
|
6686
|
-
required: mcpTool.inputSchema?.required || []
|
|
6687
|
-
}
|
|
6733
|
+
parameters
|
|
6688
6734
|
};
|
|
6689
6735
|
}
|
|
6690
6736
|
function convertMCPToolsToGoogle(client, options) {
|
|
@@ -6692,9 +6738,20 @@ function convertMCPToolsToGoogle(client, options) {
|
|
|
6692
6738
|
return mcpTools.map((mcpTool) => convertMCPToolToGoogle(mcpTool, client, options));
|
|
6693
6739
|
}
|
|
6694
6740
|
async function executeGoogleFunctionCall(client, functionCall, options) {
|
|
6695
|
-
|
|
6741
|
+
if (!functionCall?.name) {
|
|
6742
|
+
throw new Error("Function call must have a name");
|
|
6743
|
+
}
|
|
6744
|
+
const args = functionCall.args || {};
|
|
6745
|
+
const result = await executeToolWithToken(client, functionCall.name, args, options);
|
|
6696
6746
|
return JSON.stringify(result);
|
|
6697
6747
|
}
|
|
6748
|
+
async function executeGoogleFunctionCalls(client, functionCalls, options) {
|
|
6749
|
+
if (!functionCalls || functionCalls.length === 0) {
|
|
6750
|
+
return [];
|
|
6751
|
+
}
|
|
6752
|
+
const results = await Promise.all(functionCalls.map((call) => executeGoogleFunctionCall(client, call, options)));
|
|
6753
|
+
return results;
|
|
6754
|
+
}
|
|
6698
6755
|
async function getGoogleTools(client, options) {
|
|
6699
6756
|
await ensureClientConnected(client);
|
|
6700
6757
|
let providerTokens = options?.providerTokens;
|
|
@@ -7047,6 +7104,7 @@ export {
|
|
|
7047
7104
|
fromNodeHeaders,
|
|
7048
7105
|
executeToolWithToken,
|
|
7049
7106
|
executeOpenAIToolCall,
|
|
7107
|
+
executeGoogleFunctionCalls,
|
|
7050
7108
|
executeGoogleFunctionCall,
|
|
7051
7109
|
executeCloudflareToolCall,
|
|
7052
7110
|
executeAnthropicToolCall,
|
package/dist/src/ai/google.d.ts
CHANGED
|
@@ -6,28 +6,11 @@
|
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export
|
|
14
|
-
name: string;
|
|
15
|
-
description: string;
|
|
16
|
-
parameters: {
|
|
17
|
-
type: 'object';
|
|
18
|
-
description?: string;
|
|
19
|
-
properties?: Record<string, unknown>;
|
|
20
|
-
required?: string[];
|
|
21
|
-
[key: string]: unknown;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Google GenAI function call
|
|
26
|
-
*/
|
|
27
|
-
export interface GoogleFunctionCall {
|
|
28
|
-
name: string;
|
|
29
|
-
args: Record<string, unknown>;
|
|
30
|
-
}
|
|
9
|
+
import { Type } from "@google/genai";
|
|
10
|
+
import type { Schema, FunctionDeclaration, FunctionCall } from "@google/genai";
|
|
11
|
+
export type GoogleTool = FunctionDeclaration;
|
|
12
|
+
export type GoogleFunctionCall = FunctionCall;
|
|
13
|
+
export type { Schema, Type };
|
|
31
14
|
/**
|
|
32
15
|
* Options for converting MCP tools to Google GenAI format
|
|
33
16
|
*/
|
|
@@ -83,6 +66,39 @@ export declare function convertMCPToolsToGoogle(client: MCPClient<any>, options?
|
|
|
83
66
|
* ```
|
|
84
67
|
*/
|
|
85
68
|
export declare function executeGoogleFunctionCall(client: MCPClient<any>, functionCall: GoogleFunctionCall, options?: GoogleToolsOptions): Promise<string>;
|
|
69
|
+
/**
|
|
70
|
+
* Execute multiple function calls from Google GenAI response
|
|
71
|
+
*
|
|
72
|
+
* This function handles the transformation from Google's function call format
|
|
73
|
+
* to the format expected by the SDK, then executes each call.
|
|
74
|
+
*
|
|
75
|
+
* @param client - The MCP client instance
|
|
76
|
+
* @param functionCalls - Array of function calls from Google GenAI response
|
|
77
|
+
* @param options - Optional configuration including provider tokens
|
|
78
|
+
* @returns Array of execution results
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* // In your API route
|
|
83
|
+
* const response = await ai.models.generateContent({
|
|
84
|
+
* model: 'gemini-2.0-flash-001',
|
|
85
|
+
* contents: messages,
|
|
86
|
+
* config: {
|
|
87
|
+
* tools: [{ functionDeclarations: await getGoogleTools(serverClient) }],
|
|
88
|
+
* },
|
|
89
|
+
* });
|
|
90
|
+
*
|
|
91
|
+
* if (response.functionCalls && response.functionCalls.length > 0) {
|
|
92
|
+
* const results = await executeGoogleFunctionCalls(
|
|
93
|
+
* serverClient,
|
|
94
|
+
* response.functionCalls,
|
|
95
|
+
* { providerTokens }
|
|
96
|
+
* );
|
|
97
|
+
* return Response.json(results);
|
|
98
|
+
* }
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export declare function executeGoogleFunctionCalls(client: MCPClient<any>, functionCalls: GoogleFunctionCall[] | undefined | null, options?: GoogleToolsOptions): Promise<string[]>;
|
|
86
102
|
/**
|
|
87
103
|
* Get tools in a format compatible with Google GenAI
|
|
88
104
|
*
|
|
@@ -97,21 +113,21 @@ export declare function executeGoogleFunctionCall(client: MCPClient<any>, functi
|
|
|
97
113
|
* // Client-side usage
|
|
98
114
|
* import { createMCPClient, githubIntegration } from 'integrate-sdk';
|
|
99
115
|
* import { getGoogleTools } from 'integrate-sdk/ai/google';
|
|
100
|
-
* import {
|
|
116
|
+
* import { genai } from '@google/genai';
|
|
101
117
|
*
|
|
102
118
|
* const client = createMCPClient({
|
|
103
119
|
* integrations: [githubIntegration({ clientId: '...' })],
|
|
104
120
|
* });
|
|
105
121
|
*
|
|
106
122
|
* const tools = await getGoogleTools(client);
|
|
107
|
-
* const
|
|
108
|
-
* const model = genAI.getGenerativeModel({
|
|
109
|
-
* model: 'gemini-pro',
|
|
110
|
-
* tools: [{ functionDeclarations: tools }]
|
|
111
|
-
* });
|
|
123
|
+
* const ai = genai({ apiKey: 'YOUR_API_KEY' });
|
|
112
124
|
*
|
|
113
|
-
* const
|
|
114
|
-
*
|
|
125
|
+
* const response = await ai.models.generateContent({
|
|
126
|
+
* model: 'gemini-2.0-flash-001',
|
|
127
|
+
* contents: messages,
|
|
128
|
+
* config: {
|
|
129
|
+
* tools: [{ functionDeclarations: tools }]
|
|
130
|
+
* }
|
|
115
131
|
* });
|
|
116
132
|
* ```
|
|
117
133
|
*
|
|
@@ -119,7 +135,8 @@ export declare function executeGoogleFunctionCall(client: MCPClient<any>, functi
|
|
|
119
135
|
* ```typescript
|
|
120
136
|
* // Server-side usage with tokens from client
|
|
121
137
|
* import { createMCPServer, githubIntegration } from 'integrate-sdk/server';
|
|
122
|
-
* import { getGoogleTools,
|
|
138
|
+
* import { getGoogleTools, executeGoogleFunctionCalls } from 'integrate-sdk/ai/google';
|
|
139
|
+
* import { genai } from '@google/genai';
|
|
123
140
|
*
|
|
124
141
|
* const { client: serverClient } = createMCPServer({
|
|
125
142
|
* integrations: [githubIntegration({
|
|
@@ -133,25 +150,26 @@ export declare function executeGoogleFunctionCall(client: MCPClient<any>, functi
|
|
|
133
150
|
* const providerTokens = JSON.parse(req.headers.get('x-integrate-tokens') || '{}');
|
|
134
151
|
* const tools = await getGoogleTools(serverClient, { providerTokens });
|
|
135
152
|
*
|
|
136
|
-
* const
|
|
137
|
-
* const
|
|
138
|
-
* model: 'gemini-
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
* contents: [{ role: 'user', parts: [{ text: 'Create a GitHub issue' }] }]
|
|
153
|
+
* const ai = genai({ apiKey: process.env.GOOGLE_API_KEY });
|
|
154
|
+
* const response = await ai.models.generateContent({
|
|
155
|
+
* model: 'gemini-2.0-flash-001',
|
|
156
|
+
* contents: messages,
|
|
157
|
+
* config: {
|
|
158
|
+
* tools: [{ functionDeclarations: tools }]
|
|
159
|
+
* }
|
|
144
160
|
* });
|
|
145
161
|
*
|
|
146
162
|
* // Handle function calls if any
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
163
|
+
* if (response.functionCalls && response.functionCalls.length > 0) {
|
|
164
|
+
* const results = await executeGoogleFunctionCalls(
|
|
165
|
+
* serverClient,
|
|
166
|
+
* response.functionCalls,
|
|
167
|
+
* { providerTokens }
|
|
168
|
+
* );
|
|
169
|
+
* return Response.json(results);
|
|
152
170
|
* }
|
|
153
171
|
*
|
|
154
|
-
* return Response.json(
|
|
172
|
+
* return Response.json(response);
|
|
155
173
|
* }
|
|
156
174
|
* ```
|
|
157
175
|
*/
|
|
@@ -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;
|
|
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,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|
4
4
|
"description": "Type-safe 3rd party integration SDK for the Integrate MCP server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"prep": "bun run type-check && bun run build",
|
|
45
45
|
"build": "bun run build:client && bun run build:server && bun run build:adapters && bun run build:ai && bun run build:types && bun run build:copy-types",
|
|
46
46
|
"build:client": "bun build index.ts react.ts --outdir dist --target browser --format esm --external react",
|
|
47
|
-
"build:server": "bun build server.ts oauth.ts --outdir dist --target node --format esm",
|
|
47
|
+
"build:server": "bun build server.ts oauth.ts --outdir dist --target node --format esm --external @google/genai --external @anthropic-ai/sdk --external openai --external ai --external @langchain/core --external llamaindex --external @mastra/core --external @cloudflare/workers-types --external @openai/agents",
|
|
48
48
|
"build:adapters": "cd src/adapters && bun build *.ts --outdir ../../dist/adapters --target node --format esm && cd ../..",
|
|
49
|
-
"build:ai": "cd src/ai && bun build *.ts --outdir ../../dist/ai --target node --format esm && cd ../..",
|
|
49
|
+
"build:ai": "cd src/ai && bun build *.ts --outdir ../../dist/ai --target node --format esm --external @google/genai --external @anthropic-ai/sdk --external openai --external ai --external @langchain/core --external llamaindex --external @mastra/core --external @cloudflare/workers-types --external @openai/agents && cd ../..",
|
|
50
50
|
"build:types": "tsc --emitDeclarationOnly --declaration --declarationMap",
|
|
51
51
|
"build:copy-types": "cp dist/src/ai/*.d.ts dist/ai/ && cp dist/src/ai/*.d.ts.map dist/ai/ && cp dist/src/adapters/*.d.ts dist/adapters/ && cp dist/src/adapters/*.d.ts.map dist/adapters/",
|
|
52
52
|
"dev": "bun --watch src/index.ts",
|
|
@@ -72,6 +72,7 @@
|
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"@anthropic-ai/sdk": "^0.32.1",
|
|
75
|
+
"@google/genai": "^1.29.0",
|
|
75
76
|
"@types/bun": "latest",
|
|
76
77
|
"@types/react": "^18.3.0",
|
|
77
78
|
"openai": "^4.77.3",
|
|
@@ -86,7 +87,7 @@
|
|
|
86
87
|
"openai": ">=4.0.0",
|
|
87
88
|
"@openai/agents": ">=0.1.0",
|
|
88
89
|
"@anthropic-ai/sdk": ">=0.20.0",
|
|
89
|
-
"@google/
|
|
90
|
+
"@google/genai": "",
|
|
90
91
|
"@cloudflare/workers-types": ">=4.0.0",
|
|
91
92
|
"@langchain/core": ">=0.1.0",
|
|
92
93
|
"llamaindex": ">=0.1.0",
|
|
@@ -108,7 +109,7 @@
|
|
|
108
109
|
"@anthropic-ai/sdk": {
|
|
109
110
|
"optional": true
|
|
110
111
|
},
|
|
111
|
-
"@google/
|
|
112
|
+
"@google/genai": {
|
|
112
113
|
"optional": true
|
|
113
114
|
},
|
|
114
115
|
"@cloudflare/workers-types": {
|