integrate-sdk 0.6.6 → 0.6.7

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/index.js CHANGED
@@ -6152,7 +6152,7 @@ var coerce = {
6152
6152
  date: (arg) => ZodDate.create({ ...arg, coerce: true })
6153
6153
  };
6154
6154
  var NEVER = INVALID;
6155
- // src/integrations/vercel-ai.ts
6155
+ // src/integrations/utils.ts
6156
6156
  function getProviderForTool(client, toolName) {
6157
6157
  return client.getProviderForTool?.(toolName);
6158
6158
  }
@@ -6266,33 +6266,43 @@ function jsonSchemaToZod(schema) {
6266
6266
  }
6267
6267
  return exports_external.object({});
6268
6268
  }
6269
+ async function executeToolWithToken(client, toolName, args, options) {
6270
+ if (options?.providerTokens) {
6271
+ const provider = getProviderForTool(client, toolName);
6272
+ if (provider && options.providerTokens[provider]) {
6273
+ const transport = client.transport;
6274
+ if (transport && typeof transport.setHeader === "function") {
6275
+ const previousAuthHeader = transport.headers?.["Authorization"];
6276
+ try {
6277
+ transport.setHeader("Authorization", `Bearer ${options.providerTokens[provider]}`);
6278
+ const result2 = await client._callToolByName(toolName, args);
6279
+ return result2;
6280
+ } finally {
6281
+ if (previousAuthHeader) {
6282
+ transport.setHeader("Authorization", previousAuthHeader);
6283
+ } else if (transport.removeHeader) {
6284
+ transport.removeHeader("Authorization");
6285
+ }
6286
+ }
6287
+ }
6288
+ }
6289
+ }
6290
+ const result = await client._callToolByName(toolName, args);
6291
+ return result;
6292
+ }
6293
+ async function ensureClientConnected(client) {
6294
+ if (!client.isConnected()) {
6295
+ await client.connect();
6296
+ }
6297
+ }
6298
+
6299
+ // src/integrations/vercel-ai.ts
6269
6300
  function convertMCPToolToVercelAI(mcpTool, client, options) {
6270
6301
  return {
6271
6302
  description: mcpTool.description || `Execute ${mcpTool.name}`,
6272
6303
  inputSchema: jsonSchemaToZod(mcpTool.inputSchema),
6273
6304
  execute: async (args) => {
6274
- if (options?.providerTokens) {
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;
6305
+ return await executeToolWithToken(client, mcpTool.name, args, options);
6296
6306
  }
6297
6307
  };
6298
6308
  }
@@ -6305,9 +6315,7 @@ function convertMCPToolsToVercelAI(client, options) {
6305
6315
  return vercelTools;
6306
6316
  }
6307
6317
  async function getVercelAITools(client, options) {
6308
- if (!client.isConnected()) {
6309
- await client.connect();
6310
- }
6318
+ await ensureClientConnected(client);
6311
6319
  return convertMCPToolsToVercelAI(client, options);
6312
6320
  }
6313
6321
  export {
@@ -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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C,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"}
@@ -0,0 +1,158 @@
1
+ /**
2
+ * Cloudflare Workers AI Integration
3
+ *
4
+ * Helper functions to convert MCP tools to Cloudflare Workers AI 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
+ * Cloudflare AI tool definition
11
+ * Compatible with Cloudflare Workers AI
12
+ */
13
+ export interface CloudflareTool {
14
+ type: 'function';
15
+ function: {
16
+ name: string;
17
+ description: string;
18
+ parameters: {
19
+ type: 'object';
20
+ properties: Record<string, {
21
+ type: string;
22
+ description?: string;
23
+ }>;
24
+ required: string[];
25
+ };
26
+ };
27
+ }
28
+ /**
29
+ * Options for converting MCP tools to Cloudflare format
30
+ */
31
+ export interface CloudflareToolsOptions extends AIToolsOptions {
32
+ }
33
+ /**
34
+ * Convert a single MCP tool to Cloudflare Workers AI format
35
+ *
36
+ * @param mcpTool - The MCP tool definition
37
+ * @param client - The MCP client instance (used for executing the tool)
38
+ * @param options - Optional configuration including provider tokens
39
+ * @returns Cloudflare compatible tool definition
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * const cloudflareTool = convertMCPToolToCloudflare(mcpTool, client);
44
+ * ```
45
+ */
46
+ export declare function convertMCPToolToCloudflare(mcpTool: MCPTool, _client: MCPClient<any>, _options?: CloudflareToolsOptions): CloudflareTool;
47
+ /**
48
+ * Convert all enabled MCP tools to Cloudflare Workers AI format
49
+ * Returns a dictionary keyed by tool name
50
+ *
51
+ * @param client - The MCP client instance (must be connected)
52
+ * @param options - Optional configuration including provider tokens
53
+ * @returns Dictionary of Cloudflare compatible tool definitions
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * // Client-side usage
58
+ * const tools = convertMCPToolsToCloudflare(mcpClient);
59
+ *
60
+ * // Server-side with provider tokens
61
+ * const tools = convertMCPToolsToCloudflare(serverClient, {
62
+ * providerTokens: { github: 'ghp_...', gmail: 'ya29...' }
63
+ * });
64
+ * ```
65
+ */
66
+ export declare function convertMCPToolsToCloudflare(client: MCPClient<any>, options?: CloudflareToolsOptions): Record<string, CloudflareTool>;
67
+ /**
68
+ * Execute a tool call from Cloudflare Workers AI
69
+ *
70
+ * @param client - The MCP client instance
71
+ * @param toolCall - The tool call with name and arguments
72
+ * @param options - Optional configuration including provider tokens
73
+ * @returns Tool execution result as JSON string
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * const result = await executeCloudflareToolCall(client, {
78
+ * name: 'github_create_issue',
79
+ * arguments: { owner: 'user', repo: 'repo', title: 'Bug' }
80
+ * }, { providerTokens });
81
+ * ```
82
+ */
83
+ export declare function executeCloudflareToolCall(client: MCPClient<any>, toolCall: {
84
+ name: string;
85
+ arguments: Record<string, unknown> | string;
86
+ }, options?: CloudflareToolsOptions): Promise<string>;
87
+ /**
88
+ * Get tools in a format compatible with Cloudflare Workers AI
89
+ *
90
+ * Automatically connects the client if not already connected.
91
+ *
92
+ * @param client - The MCP client instance
93
+ * @param options - Optional configuration including provider tokens for server-side usage
94
+ * @returns Dictionary of tools ready to use with Cloudflare Workers AI
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * // Cloudflare Worker usage
99
+ * import { createMCPClient, githubPlugin } from 'integrate-sdk';
100
+ * import { getCloudflareTools, executeCloudflareToolCall } from 'integrate-sdk/integrations/cloudflare';
101
+ *
102
+ * export default {
103
+ * async fetch(request: Request, env: Env): Promise<Response> {
104
+ * const client = createMCPClient({
105
+ * plugins: [githubPlugin({ clientId: env.GITHUB_CLIENT_ID })],
106
+ * });
107
+ *
108
+ * const tools = await getCloudflareTools(client);
109
+ * const ai = new Ai(env.AI);
110
+ *
111
+ * const response = await ai.run('@cf/meta/llama-3-8b-instruct', {
112
+ * messages: [{ role: 'user', content: 'Create a GitHub issue' }],
113
+ * tools: Object.values(tools)
114
+ * });
115
+ *
116
+ * return Response.json(response);
117
+ * }
118
+ * };
119
+ * ```
120
+ *
121
+ * @example
122
+ * ```typescript
123
+ * // Server-side usage with tokens from client
124
+ * import { createMCPServer, githubPlugin } from 'integrate-sdk/server';
125
+ * import { getCloudflareTools, executeCloudflareToolCall } from 'integrate-sdk/integrations/cloudflare';
126
+ *
127
+ * const { client: serverClient } = createMCPServer({
128
+ * plugins: [githubPlugin({
129
+ * clientId: '...',
130
+ * clientSecret: '...'
131
+ * })],
132
+ * });
133
+ *
134
+ * // In your API route
135
+ * export async function POST(req: Request) {
136
+ * const providerTokens = JSON.parse(req.headers.get('x-integrate-tokens') || '{}');
137
+ * const tools = await getCloudflareTools(serverClient, { providerTokens });
138
+ *
139
+ * // Use with Cloudflare AI
140
+ * const ai = new Ai(env.AI);
141
+ * const response = await ai.run('@cf/meta/llama-3-8b-instruct', {
142
+ * messages: [{ role: 'user', content: 'Create a GitHub issue' }],
143
+ * tools: Object.values(tools)
144
+ * });
145
+ *
146
+ * // Handle tool calls
147
+ * if (response.tool_calls) {
148
+ * for (const toolCall of response.tool_calls) {
149
+ * await executeCloudflareToolCall(serverClient, toolCall, { providerTokens });
150
+ * }
151
+ * }
152
+ *
153
+ * return Response.json(response);
154
+ * }
155
+ * ```
156
+ */
157
+ export declare function getCloudflareTools(client: MCPClient<any>, options?: CloudflareToolsOptions): Promise<Record<string, CloudflareTool>>;
158
+ //# sourceMappingURL=cloudflare.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../../../src/integrations/cloudflare.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,cAAc;IAC7B,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,UAAU,EAAE;YACV,IAAI,EAAE,QAAQ,CAAC;YACf,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE;gBACzB,IAAI,EAAE,MAAM,CAAC;gBACb,WAAW,CAAC,EAAE,MAAM,CAAC;aACtB,CAAC,CAAC;YACH,QAAQ,EAAE,MAAM,EAAE,CAAC;SACpB,CAAC;KACH,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ,cAAc;CAAI;AAElE;;;;;;;;;;;;GAYG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,SAAS,CAAC,GAAG,CAAC,EACvB,QAAQ,CAAC,EAAE,sBAAsB,GAChC,cAAc,CAahB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAShC;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,QAAQ,EAAE;IACR,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC;CAC7C,EACD,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,MAAM,CAAC,CAOjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqEG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAGzC"}
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Google GenAI Integration
3
+ *
4
+ * Helper functions to convert MCP tools to Google GenAI 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
+ * Google GenAI function declaration
11
+ * Compatible with @google/genai SDK
12
+ */
13
+ export interface GoogleTool {
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
+ }
31
+ /**
32
+ * Options for converting MCP tools to Google GenAI format
33
+ */
34
+ export interface GoogleToolsOptions extends AIToolsOptions {
35
+ }
36
+ /**
37
+ * Convert a single MCP tool to Google GenAI format
38
+ *
39
+ * @param mcpTool - The MCP tool definition
40
+ * @param client - The MCP client instance (used for executing the tool)
41
+ * @param options - Optional configuration including provider tokens
42
+ * @returns Google GenAI compatible tool definition
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * const googleTool = convertMCPToolToGoogle(mcpTool, client);
47
+ * ```
48
+ */
49
+ export declare function convertMCPToolToGoogle(mcpTool: MCPTool, _client: MCPClient<any>, _options?: GoogleToolsOptions): GoogleTool;
50
+ /**
51
+ * Convert all enabled MCP tools to Google GenAI format
52
+ *
53
+ * @param client - The MCP client instance (must be connected)
54
+ * @param options - Optional configuration including provider tokens
55
+ * @returns Array of Google GenAI compatible tool definitions
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * // Client-side usage
60
+ * const tools = convertMCPToolsToGoogle(mcpClient);
61
+ *
62
+ * // Server-side with provider tokens
63
+ * const tools = convertMCPToolsToGoogle(serverClient, {
64
+ * providerTokens: { github: 'ghp_...', gmail: 'ya29...' }
65
+ * });
66
+ * ```
67
+ */
68
+ export declare function convertMCPToolsToGoogle(client: MCPClient<any>, options?: GoogleToolsOptions): GoogleTool[];
69
+ /**
70
+ * Execute a function call from Google GenAI
71
+ *
72
+ * @param client - The MCP client instance
73
+ * @param functionCall - The function call from Google GenAI response
74
+ * @param options - Optional configuration including provider tokens
75
+ * @returns Tool execution result as JSON string
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * const result = await executeGoogleFunctionCall(client, {
80
+ * name: 'github_create_issue',
81
+ * args: { owner: 'user', repo: 'repo', title: 'Bug' }
82
+ * }, { providerTokens });
83
+ * ```
84
+ */
85
+ export declare function executeGoogleFunctionCall(client: MCPClient<any>, functionCall: GoogleFunctionCall, options?: GoogleToolsOptions): Promise<string>;
86
+ /**
87
+ * Get tools in a format compatible with Google GenAI
88
+ *
89
+ * Automatically connects the client if not already connected.
90
+ *
91
+ * @param client - The MCP client instance
92
+ * @param options - Optional configuration including provider tokens for server-side usage
93
+ * @returns Array of tools ready to use with Google GenAI
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * // Client-side usage
98
+ * import { createMCPClient, githubPlugin } from 'integrate-sdk';
99
+ * import { getGoogleTools } from 'integrate-sdk/integrations/google';
100
+ * import { GoogleGenerativeAI } from '@google/generative-ai';
101
+ *
102
+ * const client = createMCPClient({
103
+ * plugins: [githubPlugin({ clientId: '...' })],
104
+ * });
105
+ *
106
+ * const tools = await getGoogleTools(client);
107
+ * const genAI = new GoogleGenerativeAI('YOUR_API_KEY');
108
+ * const model = genAI.getGenerativeModel({
109
+ * model: 'gemini-pro',
110
+ * tools: [{ functionDeclarations: tools }]
111
+ * });
112
+ *
113
+ * const result = await model.generateContent({
114
+ * contents: [{ role: 'user', parts: [{ text: 'Create a GitHub issue' }] }]
115
+ * });
116
+ * ```
117
+ *
118
+ * @example
119
+ * ```typescript
120
+ * // Server-side usage with tokens from client
121
+ * import { createMCPServer, githubPlugin } from 'integrate-sdk/server';
122
+ * import { getGoogleTools, executeGoogleFunctionCall } from 'integrate-sdk/integrations/google';
123
+ *
124
+ * const { client: serverClient } = createMCPServer({
125
+ * plugins: [githubPlugin({
126
+ * clientId: '...',
127
+ * clientSecret: '...'
128
+ * })],
129
+ * });
130
+ *
131
+ * // In your API route
132
+ * export async function POST(req: Request) {
133
+ * const providerTokens = JSON.parse(req.headers.get('x-integrate-tokens') || '{}');
134
+ * const tools = await getGoogleTools(serverClient, { providerTokens });
135
+ *
136
+ * const genAI = new GoogleGenerativeAI(process.env.GOOGLE_API_KEY);
137
+ * const model = genAI.getGenerativeModel({
138
+ * model: 'gemini-pro',
139
+ * tools: [{ functionDeclarations: tools }]
140
+ * });
141
+ *
142
+ * const result = await model.generateContent({
143
+ * contents: [{ role: 'user', parts: [{ text: 'Create a GitHub issue' }] }]
144
+ * });
145
+ *
146
+ * // Handle function calls if any
147
+ * const functionCalls = result.response.functionCalls();
148
+ * if (functionCalls) {
149
+ * for (const call of functionCalls) {
150
+ * await executeGoogleFunctionCall(serverClient, call, { providerTokens });
151
+ * }
152
+ * }
153
+ *
154
+ * return Response.json(result.response);
155
+ * }
156
+ * ```
157
+ */
158
+ export declare function getGoogleTools(client: MCPClient<any>, options?: GoogleToolsOptions): Promise<GoogleTool[]>;
159
+ //# sourceMappingURL=google.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../../src/integrations/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,EAA+C,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAE9F;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE;QACV,IAAI,EAAE,QAAQ,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,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,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,cAAc;CAAI;AAE9D;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,SAAS,CAAC,GAAG,CAAC,EACvB,QAAQ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