@google/genai 1.6.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -275,6 +275,49 @@ async function main() {
275
275
  main();
276
276
  ```
277
277
 
278
+ #### Model Context Protocol (MCP) support (experimental)
279
+
280
+ Built-in [MCP](https://modelcontextprotocol.io/introduction) support is an
281
+ experimental feature. You can pass a local MCP server as a tool directly.
282
+
283
+ ```javascript
284
+ import { GoogleGenAI, FunctionCallingConfigMode , mcpToTool} from '@google/genai';
285
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
286
+ import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
287
+
288
+ // Create server parameters for stdio connection
289
+ const serverParams = new StdioClientTransport({
290
+ command: "npx", // Executable
291
+ args: ["-y", "@philschmid/weather-mcp"] // MCP Server
292
+ });
293
+
294
+ const client = new Client(
295
+ {
296
+ name: "example-client",
297
+ version: "1.0.0"
298
+ }
299
+ );
300
+
301
+ // Configure the client
302
+ const ai = new GoogleGenAI({});
303
+
304
+ // Initialize the connection between client and server
305
+ await client.connect(serverParams);
306
+
307
+ // Send request to the model with MCP tools
308
+ const response = await ai.models.generateContent({
309
+ model: "gemini-2.5-flash",
310
+ contents: `What is the weather in London in ${new Date().toLocaleDateString()}?`,
311
+ config: {
312
+ tools: [mcpToTool(client)], // uses the session, will automatically call the tool using automatic function calling
313
+ },
314
+ });
315
+ console.log(response.text);
316
+
317
+ // Close the connection
318
+ await client.close();
319
+ ```
320
+
278
321
  ### Generate Content
279
322
 
280
323
  #### How to structure `contents` argument for `generateContent`